Skip to content

Commit 89c0bd0

Browse files
committed
fix(vscode-lsp): get latest config settings
When the LSP server asks the VS Code extension for configuration, the extension responds with stale config. This is fine in the current use case (where config is only fetched on initialization), but will become confusing when we handle config updates. Make the extension reply with the latest configs.
1 parent 79a9568 commit 89c0bd0

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

plugin/vscode-lsp/extension.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ let toDispose = [];
1414
async function startOrRestartServerAsync() {
1515
await stopServerIfStartedAsync();
1616

17-
let config = vscode.workspace.getConfiguration(clientID);
1817
client = new LanguageClient(
1918
clientID,
2019
"quick-lint-js-lsp",
@@ -31,7 +30,10 @@ async function startOrRestartServerAsync() {
3130
middleware: {
3231
workspace: {
3332
async configuration(params, _token, _next) {
34-
return params.items.map((item) => getLSPWorkspaceConfig(item));
33+
let vscodeConfig = getLatestWorkspaceConfig();
34+
return params.items.map((item) =>
35+
getLSPWorkspaceConfig(vscodeConfig, item)
36+
);
3537
},
3638
},
3739
},
@@ -40,15 +42,16 @@ async function startOrRestartServerAsync() {
4042
client.start();
4143

4244
function getQuickLintJSExecutablePath() {
45+
let config = getLatestWorkspaceConfig();
4346
let path = config["executablePath"];
4447
let pathIsEmpty = /^\s*$/.test(path);
4548
return pathIsEmpty ? "quick-lint-js" : path;
4649
}
4750

48-
function getLSPWorkspaceConfig(lspConfigItem) {
51+
function getLSPWorkspaceConfig(vscodeConfig, lspConfigItem) {
4952
switch (lspConfigItem.section) {
5053
case "quick-lint-js.tracing-directory":
51-
return config.get("tracing-directory");
54+
return vscodeConfig.get("tracing-directory");
5255

5356
default:
5457
return null;
@@ -94,6 +97,10 @@ async function deactivateAsync() {
9497
}
9598
exports.deactivate = deactivateAsync;
9699

100+
function getLatestWorkspaceConfig() {
101+
return vscode.workspace.getConfiguration(clientID);
102+
}
103+
97104
function logAsyncErrors(promise) {
98105
if (typeof promise === "function") {
99106
promise = promise();

0 commit comments

Comments
 (0)