Skip to content

Improve LSP configuration change notification #878

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

Merged
Merged
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
51 changes: 40 additions & 11 deletions src/sourcekit-lsp/LanguageClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ export class LanguageClientManager {
// used by single server support to keep a record of the project folders
// that are not at the root of their workspace
public subFolderWorkspaces: vscode.Uri[];
/** Get the current state of the underlying LanguageClient */
public get state(): langclient.State {
if (!this.languageClient) {
return langclient.State.Stopped;
}
return this.languageClient.state;
}

constructor(public workspaceContext: WorkspaceContext) {
this.singleServerSupport = workspaceContext.swiftVersion.isGreaterThanOrEqual(
Expand Down Expand Up @@ -161,18 +168,40 @@ export class LanguageClientManager {
}
// on change config restart server
const onChangeConfig = vscode.workspace.onDidChangeConfiguration(event => {
if (event.affectsConfiguration("swift.sourcekit-lsp")) {
vscode.window
.showInformationMessage(
"Changing LSP settings requires the language server be restarted.",
"Ok"
)
.then(selected => {
if (selected === "Ok") {
this.restart();
}
});
if (!event.affectsConfiguration("swift.sourcekit-lsp")) {
return;
}
let message =
"Changing SourceKit-LSP settings requires the language server be restarted. Would you like to restart it now?";
let restartLSPButton = "Restart Language Server";
// Enabling/Disabling sourcekit-lsp shows a special notification
if (event.affectsConfiguration("swift.sourcekit-lsp.disable")) {
if (configuration.lsp.disable) {
if (this.state === langclient.State.Stopped) {
// Language client is already stopped
return;
}
message =
"You have disabled the Swift language server, but it is still running. Would you like to stop it now?";
restartLSPButton = "Stop Language Server";
} else {
if (this.state !== langclient.State.Stopped) {
// Langauge client is already running
return;
}
message =
"You have enabled the Swift language server. Would you like to start it now?";
restartLSPButton = "Start Language Server";
}
} else if (configuration.lsp.disable && this.state === langclient.State.Stopped) {
// Ignore configuration changes if SourceKit-LSP is disabled
return;
}
vscode.window.showInformationMessage(message, restartLSPButton).then(selected => {
if (selected === restartLSPButton) {
this.restart();
}
});
});

this.subscriptions.push(onChangeConfig);
Expand Down