Skip to content

Commit

Permalink
code: Update extension to specify binary
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Jul 27, 2024
1 parent d0e4748 commit 7b440dd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
6 changes: 6 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions editors/code/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,18 @@ export class Config {
return this.cfg.get<T>(path)!;
}

get serverPath() {
get serverPath(): null | string {
return this.get<null | string>("server.path");
}

get serverCargoPackage() {
get serverCargoPackage(): string {
return this.get<string>("server.cargoPackage");
}

get serverCargoBinary(): string {
return this.get<string>("server.cargoBinary");
}

get serverExtraEnv(): Env {
const extraEnv =
this.get<{ [key: string]: string | number } | null>("server.extraEnv") ?? {};
Expand Down
31 changes: 12 additions & 19 deletions editors/code/src/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { PersistentState } from "./persistent_state";
const RUNE_PROJECT_CONTEXT_NAME = "inRuneProject";

interface FoundBinary {
kind: "languageserver" | "cli",
path: string
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<string | null> {
async buildCargoPackage(name: string, binary: string): Promise<string | null> {
interface Target {
kind: [string],
name: string,
Expand Down Expand Up @@ -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;
}
}
}
});
Expand Down Expand Up @@ -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();
Expand All @@ -297,7 +290,7 @@ export class Ctx {
return null;
}

return { kind: "cli", path };
return { path };
}

async downloadServer(): Promise<string | null> {
Expand Down

0 comments on commit 7b440dd

Please sign in to comment.