vscode: Request interesting buffers only

Ask VSCode to only send files stored on disc to the LSP,
not random other kinds of buffers. The LS can not make
sense of anything else anyway as it can nto get to
the resources stored next to buffer it works on.

For WASm we can load more kinds of buffers. Whitelist a range
of possibnle buffer schemes, incl. `vscode-vfs` which is used
on `github.dev`.

This does stop VSCode from asking the LS to process random
other buffers like those containing a git diff of a slint file.

Fixes: #6375
This commit is contained in:
Tobias Hunger 2024-09-30 16:05:26 +00:00 committed by Tobias Hunger
parent 40cd2cc8fe
commit 35cfed3a10
3 changed files with 28 additions and 3 deletions

View file

@ -24,7 +24,25 @@ function startClient(
//let args = vscode.workspace.getConfiguration('slint').get<[string]>('lsp-args'); //let args = vscode.workspace.getConfiguration('slint').get<[string]>('lsp-args');
// Options to control the language client // Options to control the language client
const clientOptions = common.languageClientOptions(telemetryLogger); // Note: This works with way more schemes than the native LSP as it goes
// through VSCode to open files by necessity.
// https://github.com/microsoft/vscode/blob/main/src/vs/base/common/network.ts
// lists all the known schemes in VSCode (without extensions). I err on the
// side of allowing too much here I think...
const clientOptions = common.languageClientOptions(
[
"file",
"http",
"https",
"inmemory",
"vscode-file",
"vscode-remote",
"vscode-remote-resource",
"vscode-vfs", // github.dev uses this
"vsls",
],
telemetryLogger,
);
clientOptions.synchronize = {}; clientOptions.synchronize = {};
clientOptions.initializationOptions = {}; clientOptions.initializationOptions = {};

View file

@ -100,10 +100,17 @@ export function setServerStatus(
// as needed and makes the triggering side so much simpler! // as needed and makes the triggering side so much simpler!
export function languageClientOptions( export function languageClientOptions(
schemes: string[],
telemetryLogger: vscode.TelemetryLogger, telemetryLogger: vscode.TelemetryLogger,
): LanguageClientOptions { ): LanguageClientOptions {
var document_selector = [];
for (var scheme of schemes) {
document_selector.push({ scheme: scheme, language: "slint" });
document_selector.push({ scheme: scheme, language: "rust" });
}
return { return {
documentSelector: [{ language: "slint" }, { language: "rust" }], documentSelector: document_selector,
middleware: { middleware: {
async provideCodeActions( async provideCodeActions(
document: vscode.TextDocument, document: vscode.TextDocument,

View file

@ -195,7 +195,7 @@ function startClient(
"slint-lsp", "slint-lsp",
"Slint", "Slint",
serverOptions, serverOptions,
common.languageClientOptions(telemetryLogger), common.languageClientOptions(["file"], telemetryLogger),
); );
common.prepare_client(cl); common.prepare_client(cl);