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

Automatically restart clangd language server after it is installed #749

Merged

Conversation

k0zmo
Copy link
Contributor

@k0zmo k0zmo commented Dec 9, 2024

No description provided.

@k0zmo k0zmo force-pushed the restart-clangd-after-installation branch from bb1d370 to 9f2f7ff Compare December 12, 2024 19:21
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 patch. The general approach looks reasonable to me. A few comments on the specifics:

src/install.ts Outdated
@@ -129,6 +132,11 @@ class UI {
return p;
}
set clangdPath(p: string) {
config.update('path', p, vscode.ConfigurationTarget.Global);
this._pathUpdated =
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe a more conventional way to write this is:

this._pathUpdated = new Promise(resolve => {
  config.update('path', ...).then(resolve);
});

or alternatively:

this._pathUpdated = new Promise(async resolve => {
  await config.update('path', ...);
  resolve();
});

This avoids the extra variable _resolvePathUpdated, and also ensures that if the setter is called multiple times, awaiting _pathUpdated will correctly wait until the most recent promise is resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with first option as config.update is not awaitable.

src/install.ts Outdated
async promptReload(message: string) {
if (await vscode.window.showInformationMessage(message, 'Reload window'))
vscode.commands.executeCommand('workbench.action.reloadWindow');
await this._pathUpdated
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 null out _pathUpdated after having awaited it, to avoid any objects being unnecessarily kept alive

@@ -81,9 +81,12 @@ class UI {
}
}

private _pathUpdated: Promise<void>|undefined;
private _resolvePathUpdated: (() => void)|undefined;

async promptReload(message: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should ignore message entirely. Can we still show it in an info dialog, without waiting for the user to interact with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can do this:

  async promptReload(message: string) {
    vscode.window.showInformationMessage(message)
    await this._pathUpdated;
    this._pathUpdated = null;
    vscode.commands.executeCommand('clangd.restart');
  }

Without await, this won't wait for user prompt and it would serve as a status message 'clangd ${version} is installed'. Is this what you had in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, exactly

@k0zmo k0zmo force-pushed the restart-clangd-after-installation branch 2 times, most recently from e377555 to ff43647 Compare December 17, 2024 08:22
@k0zmo k0zmo force-pushed the restart-clangd-after-installation branch from ff43647 to add1a70 Compare December 17, 2024 23:52
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

@HighCommander4 HighCommander4 merged commit 4a6319a into clangd:master Dec 18, 2024
1 check passed
@k0zmo k0zmo deleted the restart-clangd-after-installation branch December 18, 2024 08:27
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.

2 participants