Skip to content

Commit

Permalink
Add "clangd.restart" command. (clangd#35)
Browse files Browse the repository at this point in the history
* Add "clangd.restart" command.

* Don't leak resources after restart.
  • Loading branch information
hokein authored Jun 8, 2020
1 parent 562d00b commit 6f2cef1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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();
}));
}

0 comments on commit 6f2cef1

Please sign in to comment.