Skip to content

Add shutdown command#866

Merged
HighCommander4 merged 6 commits intoclangd:masterfrom
xamelllion:master
Sep 20, 2025
Merged

Add shutdown command#866
HighCommander4 merged 6 commits intoclangd:masterfrom
xamelllion:master

Conversation

@xamelllion
Copy link
Contributor

Resolves #512

Copy link
Contributor

@HighCommander4 HighCommander4 left a comment

Choose a reason for hiding this comment

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

Two observations:

  1. The patch has the counter-intuitive behaviour that if the clangd extension has never been activated yet, then running the clangd.shutdown command will actually start the clangd server (because vscode will call activate() on the extension that declared the command if it hasn't been activated yet). This can probably be avoided with some more work, but it's a bit of an edge case, so I'm not sure if it's worth bothering.

  2. After a shutdown, running clangd.activate does not have the effect of starting clangd again (but clangd.restart does). Should we change it such that it does?

cc @JVApen for any thoughts

@JVApen
Copy link
Contributor

JVApen commented Sep 8, 2025

Before diving into the details, I can say that I've missed this feature and regularly killed clangd on Windows such that I could recompile it. (A problem that doesn't exist on Linux)

Regarding 1., although it looks strange to activate the extension due to the abort, I don't think we have much of an option here. I think this is such an edge case that we'll simply have to live with it.

Regarding 2., this has me more worried, arguments can be made that 'activate' is about the extension, not the server, though the average user won't see it that way. Personally, I also would expect it to launch the server if not running. The difference I see between activate and restart is that restart does shutdown when a server is active while activate will do nothing.

@xamelllion
Copy link
Contributor Author

Added the functionality described by @JVApen of activating the language server via the clangd.activate command.

Copy link
Contributor

@HighCommander4 HighCommander4 left a comment

Choose a reason for hiding this comment

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

LGTM with my comment addressed, and the CI failure fixed (a newly added method needs to be defined in a mock class as well)

src/extension.ts Outdated
vscode.commands.registerCommand('clangd.activate', async () => {}));
vscode.commands.registerCommand('clangd.activate', async () => {
// If clangd server is already running, do nothing.
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

Copy link
Contributor

@HighCommander4 HighCommander4 left a comment

Choose a reason for hiding this comment

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

Thanks for the update. LGTM.

src/extension.ts Outdated
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

@HighCommander4 HighCommander4 merged commit 7ddc363 into clangd:master Sep 20, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a command to disable clangd, when it is hogging CPU or RAM

3 participants