Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "clangd.restart" command. #35

Merged
merged 2 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@
{
"command": "clangd.activate",
"title": "Manually activate clangd extension"
},
{
"command": "clangd.restart",
"title": "Restart the clangd language server"
}
],
"keybindings": [
Expand Down
19 changes: 18 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ class ClangdLanguageClient extends vscodelc.LanguageClient {
// Call default implementation.
super.logFailedRequest(rpcReply, error);
}

activate() {
this.dispose();
this.startDisposable = this.start();
}

dispose() {
if (this.startDisposable)
this.startDisposable.dispose();
}
private startDisposable: vscodelc.Disposable;
}

class EnableEditsNearCursorFeature implements vscodelc.StaticFeature {
Expand Down Expand Up @@ -102,15 +113,21 @@ export async function activate(context: vscode.ExtensionContext) {

const client = new ClangdLanguageClient('Clang Language Server',
serverOptions, clientOptions);
context.subscriptions.push(vscode.Disposable.from(client));
if (config.get<boolean>('semanticHighlighting'))
semanticHighlighting.activate(client, context);
client.registerFeature(new EnableEditsNearCursorFeature);
context.subscriptions.push(client.start());
client.activate();
console.log('Clang Language Server is now active!');
fileStatus.activate(client, context);
switchSourceHeader.activate(client, context);
// An empty place holder for the activate command, otherwise we'll get an
// "command is not registered" error.
context.subscriptions.push(
vscode.commands.registerCommand('clangd.activate', async () => {}));
context.subscriptions.push(
vscode.commands.registerCommand('clangd.restart', async () => {
await client.stop();
client.activate();
}));
}