Skip to content

Commit

Permalink
Send configuration for mesonbuild.$SERVER to the server
Browse files Browse the repository at this point in the history
  • Loading branch information
JCWasmx86 committed Oct 23, 2023
1 parent 7e9981d commit 1213b31
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## next

- Add configuration options specific for Swift-MesonLSP.

## 1.13.0

- Add support for CodeLLDB extension
Expand Down
10 changes: 10 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,16 @@ export async function activate(ctx: vscode.ExtensionContext) {

let client = await createLanguageServerClient(server, await shouldDownload(downloadLanguageServer), ctx);
if (client !== null && server == "Swift-MesonLSP") {
ctx.subscriptions.push(
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration(`mesonbuild.${server}`)) {
client?.reloadConfig();
}
}),
);
ctx.subscriptions.push(client);
client.start();
await client.reloadConfig();

getOutputChannel().appendLine("Not enabling the muon linter/formatter because Swift-MesonLSP is active.");
} else {
Expand All @@ -262,10 +270,12 @@ export async function activate(ctx: vscode.ExtensionContext) {
if (client !== null) {
ctx.subscriptions.push(client);
client.start();
await client.reloadConfig();
// TODO: The output line from above about not enabling muon would be good to have here.
}
} else {
client.restart();
await client.reloadConfig();
}
}),
);
Expand Down
14 changes: 13 additions & 1 deletion src/lsp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import * as os from "os";
import * as path from "path";
import * as vscode from "vscode";
import {
DidChangeConfigurationNotification,
DidChangeConfigurationParams,
Executable,
LanguageClient,
LanguageClientOptions,
Expand All @@ -15,6 +17,7 @@ import {
} from "vscode-languageclient/node";
import * as storage from "../storage";
import { LanguageServer } from "../types";
import { getOutputChannel } from "../utils";

export abstract class LanguageServerClient {
private static readonly clientOptions: LanguageClientOptions = {
Expand Down Expand Up @@ -183,7 +186,8 @@ export abstract class LanguageServerClient {
debug: this.debugExe,
transport: TransportKind.stdio,
};

const options = LanguageServerClient.clientOptions;
options.initializationOptions = vscode.workspace.getConfiguration(`mesonbuild.${this.server}`);
this.ls = new LanguageClient(
this.server!,
`Meson Language Server (${this.server})`,
Expand All @@ -193,4 +197,12 @@ export abstract class LanguageServerClient {
);
this.ls.start();
}

async reloadConfig(): Promise<void> {
const config = vscode.workspace.getConfiguration(`mesonbuild.${this.server}`);
const params: DidChangeConfigurationParams = {
settings: config,
};
await this.ls!.sendNotification(DidChangeConfigurationNotification.type, params);
}
}

0 comments on commit 1213b31

Please sign in to comment.