Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@
"category": "clangd",
"title": "Restart language server"
},
{
"command": "clangd.shutdown",
"category": "clangd",
"title": "Shutdown language server"
},
{
"command": "clangd.typeHierarchy",
"category": "clangd",
Expand Down
4 changes: 4 additions & 0 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ export class ClangdContext implements vscode.Disposable {
return this.client && this.client.state == vscodelc.State.Starting;
}

clientIsRunning() {
return this.client && this.client.state == vscodelc.State.Running;
}

dispose() {
this.subscriptions.forEach((d) => { d.dispose(); });
if (this.client)
Expand Down
20 changes: 17 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ export async function activate(context: vscode.ExtensionContext):

let clangdContext: ClangdContext|null = null;

// 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 () => {}));
vscode.commands.registerCommand('clangd.activate', async () => {
if (clangdContext && clangdContext.clientIsStarting()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: combine these conditions (clangdContext.clientIsStarting() || clangdContext.clientisRunning())?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return;
}
if (clangdContext && clangdContext.clientIsRunning()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this if the client is in the Starting state as well. (I know clangd.restart checks that and early-returns, but by the time it's called the client may be in the Running state and then we'd stop/start it again for no reason.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this check

return;
}
vscode.commands.executeCommand('clangd.restart');
}));
context.subscriptions.push(
vscode.commands.registerCommand('clangd.restart', async () => {
if (!get<boolean>('enable')) {
Expand Down Expand Up @@ -58,6 +64,14 @@ export async function activate(context: vscode.ExtensionContext):
apiInstance.client = clangdContext?.client;
}
}));
context.subscriptions.push(
vscode.commands.registerCommand('clangd.shutdown', async () => {
if (clangdContext && clangdContext.clientIsStarting()) {
return;
}
if (clangdContext)
clangdContext.dispose();
}));

let shouldCheck = false;

Expand Down
2 changes: 2 additions & 0 deletions test/inactive-regions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class MockClangdContext implements ClangdContext {

clientIsStarting() { return false; }

clientIsRunning() { return true; }

dispose() { throw new Error('Method not implemented.'); }
}

Expand Down