Skip to content

Commit

Permalink
Add middleware for configuration requests
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Jan 14, 2025
1 parent ada8074 commit 02b17a5
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion editors/code/src/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from "vscode";
import * as lc from "vscode-languageclient/node";
import { default as PQueue } from "p-queue";
import { getInitializationOptions } from "./settings";
import { Middleware, ResponseError } from "vscode-languageclient/node";

// All session management operations are put on a queue. They can't run
// concurrently and either result in a started or stopped state. Starting when
Expand Down Expand Up @@ -60,6 +61,44 @@ export class Lsp {
args: ["language-server"],
};

// We need a middleware for `configuration` requests from the server
// because the LSP client does not query language-specific configuration.
// See https://github.com/microsoft/vscode-languageserver-node/issues/1043 and
// https://github.com/microsoft/vscode-languageserver-node/issues/1056.
let middleware: Middleware = {
workspace: {
configuration: async (params, token, next) => {
const items = await next(params, token);

if (items instanceof ResponseError) {
return items;
}

for (let i = 0; i < params.items.length; ++i) {
const item = params.items[i];

if (!item.section || !item.scopeUri) {
continue;
}

const uri = vscode.Uri.parse(item.scopeUri);

const document =
await vscode.workspace.openTextDocument(uri);
const languageId = document.languageId;

const config = vscode.workspace.getConfiguration(
undefined,
{ uri, languageId },
);
items[i] = config.get(item.section);
}

return items;
},
},
};

let clientOptions: lc.LanguageClientOptions = {
// Look for unnamed scheme
documentSelector: [
Expand All @@ -70,13 +109,14 @@ export class Lsp {
],
outputChannel: this.channel,
initializationOptions: initializationOptions,
middleware,
};

const client = new lc.LanguageClient(
"airLanguageServer",
"Air Language Server",
serverOptions,
clientOptions
clientOptions,
);
await client.start();

Expand Down

0 comments on commit 02b17a5

Please sign in to comment.