Skip to content

Commit

Permalink
Support debug build
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-cho committed Sep 15, 2024
1 parent b2105ea commit 221c58a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"<node_internals>/**/*.js"
],
"env": {
"SERVER_PATH": "${workspaceFolder}/target/debug/fluent-bit-language-server"
"__FLB_LSP_SERVER_DEBUG": "${workspaceFolder}/target/debug/fluent-bit-language-server"
}
}
]
Expand Down
67 changes: 67 additions & 0 deletions clients/vscode/src/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import * as vscode from "vscode";
import * as os from "os";

export async function bootstrap(
context: vscode.ExtensionContext
): Promise<string> {
const path = await getServers(context);
if (!path) {
throw new Error("fluent-bit-language-server is not available.");
}

console.log("Using server binary at", path);

// TODO: check validity

return path;
}

async function getServers(
context: vscode.ExtensionContext
): Promise<string | undefined> {
// check if the server path is configured explicitly
const explicitPath = process.env["__FLB_LSP_SERVER_DEBUG"];
if (explicitPath) {
if (explicitPath.startsWith("~/")) {
return os.homedir() + explicitPath.slice("~".length);
}
return explicitPath;
}

const ext = process.platform === "win32" ? ".exe" : "";
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `fluent-bit-language-server${ext}`);
const bundledExists = await fileExists(bundled);

if (!bundledExists) {
await vscode.window.showErrorMessage(
"Unfortunately we don't ship binaries for your platform yet. " +
"Please build and run the server manually from the source code. " +
"Or, please create an issue on repository."
);
return;
}
}

async function fileExists(uri: vscode.Uri) {
return await vscode.workspace.fs.stat(uri).then(
() => true,
() => false,
);
}

// TODO
// export function isValidExecutable(path: string, extraEnv: Env): boolean {
// log.debug("Checking availability of a binary at", path);

// const res = spawnSync(path, ["--version"], {
// encoding: "utf8",
// env: { ...process.env, ...extraEnv },
// });

// if (res.error) {
// log.warn(path, "--version:", res);
// } else {
// log.info(path, "--version:", res);
// }
// return res.status === 0;
// }
29 changes: 3 additions & 26 deletions clients/vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,15 @@ import {
LanguageClientOptions,
ServerOptions,
} from "vscode-languageclient/node";
import * as vscode from "vscode";
import { bootstrap } from "./bootstrap";

let client: LanguageClient;

export async function activate(context: ExtensionContext) {
// TODO: bootstrap debug, release
// const traceOutputChannel = window.createOutputChannel("fluent-bit language server trace");
// const command = process.env.SERVER_PATH || "fluent-bit-language-server";

// Use bundled server only for now
const ext = process.platform === "win32" ? ".exe" : "";
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `fluent-bit-language-server${ext}`);
const bundledExists = await fileExists(bundled);

if (!bundledExists) {
await vscode.window.showErrorMessage(
"Unfortunately we don't ship binaries for your platform yet." +
"Please build and run the server manually from the source code." +
"Or, please create an issue on repository."
);
return;
}
const path = await bootstrap(context);

const run: Executable = {
command: bundled.fsPath,
command: path,
options: {
env: {
...process.env
Expand Down Expand Up @@ -70,13 +54,6 @@ export async function activate(context: ExtensionContext) {
await client.start();
}

async function fileExists(uri: vscode.Uri) {
return await vscode.workspace.fs.stat(uri).then(
() => true,
() => false,
);
}

export function deactivate(): Thenable<void> | undefined {
if (!client) {
return undefined;
Expand Down
2 changes: 2 additions & 0 deletions fluent-bit-language-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ async fn main() {
})
.finish();

// TODO: support other commands (e.g. `--version`)

Server::new(stdin, stdout, socket).serve(service).await;
}

0 comments on commit 221c58a

Please sign in to comment.