Skip to content

Commit

Permalink
Fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Tillmanns committed Aug 7, 2020
1 parent 3cf5cb4 commit 0a1b72a
Showing 1 changed file with 68 additions and 37 deletions.
105 changes: 68 additions & 37 deletions client/vueMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,43 +52,42 @@ export async function activate(context: vscode.ExtensionContext) {
)
);

context.subscriptions.push(
vscode.commands.registerCommand('vetur.chooseTypeScriptRefactoring', (args: any) => {
client.sendRequest<WorkspaceEdit | undefined>('requestCodeActionEdits', args).then(edits => {
if (edits) {
vscode.workspace.applyEdit(client.protocol2CodeConverter.asWorkspaceEdit(edits)!);
}
});
})
);

registerLanguageConfigurations();

/**
* Vue Language Server Initialization
*/

const serverModule = context.asAbsolutePath(join('server', 'dist', 'vueServerMain.js'));
const client = initializeLanguageClient(serverModule, globalSnippetDir);
context.subscriptions.push(client.start());

const promise = client
.onReady()
.then(() => {
registerCustomClientNotificationHandlers(client);
registerCustomLSPCommands(context, client);
})
.catch(e => {
console.log('Client initialization failed');
});

return vscode.window.withProgress(
{
title: 'Vetur initialization',
location: vscode.ProgressLocation.Window
},
() => promise
);
function onDidOpenTextDocument(document: vscode.TextDocument) {
const client = initializeClientForTextDocument(context, serverModule, globalSnippetDir, document);
// TODO handle commands properly
if (!client || clients.size > 1) {
return;
}
context.subscriptions.push(
vscode.commands.registerCommand('vetur.applyWorkspaceEdits', (args: WorkspaceEdit) => {
const edit = client.protocol2CodeConverter.asWorkspaceEdit(args)!;
vscode.workspace.applyEdit(edit);
})
);

context.subscriptions.push(
vscode.commands.registerCommand('vetur.chooseTypeScriptRefactoring', (args: any) => {
client.sendRequest<WorkspaceEdit | undefined>('requestCodeActionEdits', args).then(edits => {
if (edits) {
vscode.workspace.applyEdit(client.protocol2CodeConverter.asWorkspaceEdit(edits)!);
}
});
})
);
}

vscode.workspace.onDidOpenTextDocument(onDidOpenTextDocument);
vscode.workspace.textDocuments.forEach(onDidOpenTextDocument);

vscode.workspace.onDidChangeWorkspaceFolders(event => {
for (const folder of event.removed) {
const client = clients.get(folder.uri.toString());
if (client) {
clients.delete(folder.uri.toString());
client.stop();
}
}
});
}

function registerCustomClientNotificationHandlers(client: LanguageClient) {
Expand All @@ -111,3 +110,35 @@ function registerCustomLSPCommands(context: vscode.ExtensionContext, client: Lan
vscode.commands.registerCommand('vetur.showCorrespondingVirtualFile', generateShowVirtualFileCommand(client))
);
}

function initializeClientForTextDocument(
context: vscode.ExtensionContext,
serverModule: string,
globalSnippetDir: string,
document: vscode.TextDocument
): LanguageClient | undefined {
const folder = vscode.workspace.getWorkspaceFolder(document.uri);

if (!folder || document.languageId !== 'vue') {
return;
}

if (!clients.has(folder.uri.toString())) {
const client = initializeLanguageClient(serverModule, globalSnippetDir, folder);

client
.onReady()
.then(() => {
registerCustomClientNotificationHandlers(client);
registerCustomLSPCommands(context, client);
})
.catch(e => {
console.log(`Client initialization failed for workspace: ${folder.uri.toString()}`);
});

context.subscriptions.push(client.start());
clients.set(folder.uri.toString(), client);

return client;
}
}

0 comments on commit 0a1b72a

Please sign in to comment.