From 7b440dd9045fe98108da9e94c7a91679664717d6 Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Sat, 27 Jul 2024 05:47:47 +0200 Subject: [PATCH] code: Update extension to specify binary --- editors/code/package.json | 6 ++++++ editors/code/src/config.ts | 8 ++++++-- editors/code/src/ctx.ts | 31 ++++++++++++------------------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/editors/code/package.json b/editors/code/package.json index c78d2e323..95c596b09 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -115,6 +115,12 @@ "type": "string", "default": "" }, + "rune.server.cargoBinary": { + "title": "Cargo Binary", + "markdownDescription": "Set the extension to use the given cargo binary to run the language server. If left empty, the last binary built is used.", + "type": "string", + "default": "" + }, "rune.server.path": { "markdownDescription": "Path to rune-languageserver executable (will be downloaded by default). If this is set, then `#rune.updates.channel#` setting is not used", "type": "string", diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index acb02e1a8..8549ee536 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -152,14 +152,18 @@ export class Config { return this.cfg.get(path)!; } - get serverPath() { + get serverPath(): null | string { return this.get("server.path"); } - get serverCargoPackage() { + get serverCargoPackage(): string { return this.get("server.cargoPackage"); } + get serverCargoBinary(): string { + return this.get("server.cargoBinary"); + } + get serverExtraEnv(): Env { const extraEnv = this.get<{ [key: string]: string | number } | null>("server.extraEnv") ?? {}; diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index b4d36a130..858dd772c 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -13,7 +13,6 @@ import { PersistentState } from "./persistent_state"; const RUNE_PROJECT_CONTEXT_NAME = "inRuneProject"; interface FoundBinary { - kind: "languageserver" | "cli", path: string } @@ -88,16 +87,7 @@ export class Ctx { try { const binary = await this.bootstrap(); - - switch (binary.kind) { - case "languageserver": - this.client = createClient(binary.path, this.config.serverExtraEnv); - break; - case "cli": - this.client = createClient(binary.path, this.config.serverExtraEnv, ["language-server"]); - break; - } - + this.client = createClient(binary.path, this.config.serverExtraEnv, ["language-server"]); await this.client.start(); await setContextValue(RUNE_PROJECT_CONTEXT_NAME, true); } catch (err: any) { @@ -181,7 +171,7 @@ export class Ctx { * @param name package to build. * @returns a string to the path of the built binary. */ - async buildCargoPackage(name: string): Promise { + async buildCargoPackage(name: string, binary: string): Promise { interface Target { kind: [string], name: string, @@ -232,10 +222,13 @@ export class Ctx { if (output.reason === "compiler-artifact") { let artifact = output as CompilerArtifact; + this.statusBar.text = `rune: cargo (${artifact.target.name})`; - if (artifact.target.name === name && artifact.target.kind.includes("bin")) { - executable = artifact.executable; + if (artifact.target.kind.includes("bin")) { + if (binary == "" || artifact.target.name === binary) { + executable = artifact.executable; + } } } }); @@ -273,22 +266,22 @@ export class Ctx { if (explicitPath) { if (explicitPath.startsWith("~/")) { - return { kind: "cli", path: os.homedir() + explicitPath.slice("~".length) }; + return { path: os.homedir() + explicitPath.slice("~".length) }; } - return { kind: "cli", path: explicitPath }; + return { path: explicitPath }; } const cargoPackage = this.config.serverCargoPackage; if (cargoPackage) { - let path = await this.buildCargoPackage(cargoPackage); + let path = await this.buildCargoPackage(cargoPackage, this.config.serverCargoBinary); if (!path) { return null; } - return { kind: "cli", path }; + return { path }; } let path = await this.downloadServer(); @@ -297,7 +290,7 @@ export class Ctx { return null; } - return { kind: "cli", path }; + return { path }; } async downloadServer(): Promise {