Skip to content

Commit

Permalink
fix extension still downloading server from CI
Browse files Browse the repository at this point in the history
  • Loading branch information
rtk0c committed Nov 14, 2024
1 parent 7d651f2 commit f4181d5
Showing 1 changed file with 7 additions and 56 deletions.
63 changes: 7 additions & 56 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { ExtensionContext, ExtensionMode, workspace } from "vscode";

import { createWriteStream, existsSync, mkdirSync } from "fs";
import { chmod } from "fs/promises";
import * as net from "net";
import { sep } from "path";
import { Readable } from "stream";
import { finished } from "stream/promises";
import * as path from "path";
import {
LanguageClient,
LanguageClientOptions,
Expand All @@ -15,55 +11,6 @@ import {

let client: LanguageClient;

async function downloadToBin(
ctx: ExtensionContext,
url: string,
filename: string
) {
const res = await fetch(url);
if (!existsSync(ctx.asAbsolutePath("bin"))) {
mkdirSync(ctx.asAbsolutePath("bin"), { recursive: true });
}
const actualFileName = ctx.asAbsolutePath(`bin${sep}${filename}`);
const fileStream = createWriteStream(actualFileName, { flags: "wx" });
await finished(Readable.fromWeb(res.body).pipe(fileStream));
}

async function resolveServerExecutable(ctx: ExtensionContext): Promise<string> {
const version = "1.0.3";
const platformDetails = {
win32: {
url: `https://github.com/chrehall68/vls/releases/download/${version}/vls-windows-amd64.exe`,
filename: "vls.exe",
doChmod: false,
},
darwin: {
url: `https://github.com/chrehall68/vls/releases/download/${version}/vls-macos-amd64`,
filename: "vls",
doChmod: true,
},
linux: {
url: `https://github.com/chrehall68/vls/releases/download/${version}/vls-linux-amd64`,
filename: "vls",
doChmod: true,
},
};

const platform = process.platform;
if (!platformDetails[platform]) {
throw new Error(`Unsupported platform: ${platform}`);
}
const { url, filename, doChmod } = platformDetails[platform];
if (!existsSync(ctx.asAbsolutePath(`bin${sep}${filename}`))) {
await downloadToBin(ctx, url, filename);
if (doChmod) {
// make it executable; rx-rx-rx
await chmod(ctx.asAbsolutePath(`bin${sep}${filename}`), 0o555);
}
}
return ctx.asAbsolutePath(`bin${sep}${filename}`);
}

async function getServerOptions(ctx: ExtensionContext): Promise<ServerOptions> {
if (ctx.extensionMode == ExtensionMode.Development) {
// In debug mode, the server is launched by VSCode (on this project) with Go debugger
Expand All @@ -81,9 +28,13 @@ async function getServerOptions(ctx: ExtensionContext): Promise<ServerOptions> {
};
}

const executable = await resolveServerExecutable(ctx);
let filename = "verilog_language_server";
if (process.platform == "win32") {
filename += ".exe";
}

return {
command: executable,
command: ctx.asAbsolutePath(path.join("bin", filename)),
args: [],
};
}
Expand Down

0 comments on commit f4181d5

Please sign in to comment.