Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@
"configuration": {
"title": "Meson build configuration",
"properties": {
"mesonbuild.trace.server": {
"type": "string",
"default": "off",
"scope": "window",
"enum": [
"off",
"messages",
"verbose"
],
"description": "Traces the communication between VS Code and the current Meson language server."
},
"mesonbuild.selectRootDir": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -255,6 +266,7 @@
"enum": [
"Swift-MesonLSP",
"mesonlsp",
"muon",
null
],
"description": "Select which language server to use. Swift-MesonLSP is a legacy alias for mesonlsp."
Expand Down
15 changes: 5 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,11 @@ export async function activate(ctx: vscode.ExtensionContext) {
await regenerateTests(controller);
}

const server = extensionConfiguration(SettingsKey.languageServer);
let client = await createLanguageServerClient(server, await askShouldDownloadLanguageServer(), ctx);
// Basically every server supports formatting...
const serverSupportsFormatting = server == "mesonlsp" || server == "Swift-MesonLSP";
if (client !== null && serverSupportsFormatting) {
let client = await createLanguageServerClient(await askShouldDownloadLanguageServer(), ctx);
if (client !== null) {
ctx.subscriptions.push(
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration(`mesonbuild.${server}`)) {
if (e.affectsConfiguration(`mesonbuild.${client!.server}`)) {
client?.reloadConfig();
}
}),
Expand All @@ -257,9 +254,7 @@ export async function activate(ctx: vscode.ExtensionContext) {
client.start();
await client.reloadConfig();

getOutputChannel().appendLine(
"Not enabling the muon linter/formatter because a language server supporting formatting is active.",
);
getOutputChannel().appendLine("Linters and formatters disabled because a language server is active.");
} else {
activateLinters(sourceDir, ctx);
activateFormatters(sourceDir, ctx);
Expand All @@ -268,7 +263,7 @@ export async function activate(ctx: vscode.ExtensionContext) {
ctx.subscriptions.push(
vscode.commands.registerCommand("mesonbuild.restartLanguageServer", async () => {
if (client === null) {
client = await createLanguageServerClient(server, await askShouldDownloadLanguageServer(), ctx);
client = await createLanguageServerClient(await askShouldDownloadLanguageServer(), ctx);
if (client !== null) {
ctx.subscriptions.push(client);
client.start();
Expand Down
9 changes: 7 additions & 2 deletions src/lsp/common.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import * as vscode from "vscode";
import { LanguageServerClient } from ".";
import { LanguageServer } from "../types";
import { LanguageServer, SettingsKey } from "../types";
import { MesonLSPLanguageClient } from "./mesonlsp";
import { MuonLanguageClient } from "./muon";
import { Uri } from "vscode";
import { extensionConfiguration } from "../utils";

export function serverToClass(server: LanguageServer): any {
switch (server) {
case "Swift-MesonLSP":
case "mesonlsp":
return MesonLSPLanguageClient;
case "muon":
return MuonLanguageClient;
default:
return null;
}
}

export async function createLanguageServerClient(
server: LanguageServer,
download: boolean,
context: vscode.ExtensionContext,
): Promise<LanguageServerClient | null> {
const server = extensionConfiguration(SettingsKey.languageServer);

const klass = serverToClass(server);
if (klass == null) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export abstract class LanguageServerClient {
const options = LanguageServerClient.clientOptions;
options.initializationOptions = vscode.workspace.getConfiguration(`mesonbuild.${this.server}`);
this.ls = new LanguageClient(
this.server!,
"mesonbuild",
`Meson Language Server (${this.server})`,
serverOptions,
LanguageServerClient.clientOptions,
Expand Down
24 changes: 24 additions & 0 deletions src/lsp/muon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as vscode from "vscode";

import type { Executable } from "vscode-languageclient/node";
import { LanguageServerClient } from "../lsp";

export class MuonLanguageClient extends LanguageServerClient {
get runExe(): Executable {
return {
command: this.languageServerPath!.fsPath,
args: ["analyze", "lsp"],
};
}

get debugExe(): Executable {
return {
command: this.languageServerPath!.fsPath,
args: ["analyze", "lsp"],
};
}

constructor(languageServerPath: vscode.Uri, context: vscode.ExtensionContext, referenceVersion: string) {
super("muon", languageServerPath, context, referenceVersion);
}
}
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export type LinterConfiguration = {
enabled: boolean;
};

export type LanguageServer = "Swift-MesonLSP" | "mesonlsp" | null;
export type LanguageServer = "Swift-MesonLSP" | "mesonlsp" | "muon" | null;
export type ModifiableExtension = "ms-vscode.cpptools" | "rust-lang.rust-analyzer";

export type FormattingProvider = "muon" | "meson";
Expand Down
Loading