init
This commit is contained in:
commit
8f4f858d86
30 changed files with 9765 additions and 0 deletions
86
tools/vscode-gotlin/src/extension.ts
Normal file
86
tools/vscode-gotlin/src/extension.ts
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import * as vscode from "vscode";
|
||||
import {
|
||||
LanguageClient,
|
||||
LanguageClientOptions,
|
||||
ServerOptions
|
||||
} from "vscode-languageclient/node";
|
||||
|
||||
let client: LanguageClient | undefined;
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext): Promise<void> {
|
||||
const serverPath = resolveServerPath();
|
||||
if (!serverPath) {
|
||||
void vscode.window.showErrorMessage(
|
||||
"Gotlin LSP binary was not found. Build ./bin/gotlin-lsp or set gotlin.serverPath."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const serverOptions: ServerOptions = {
|
||||
command: serverPath,
|
||||
args: [],
|
||||
options: {
|
||||
env: {
|
||||
...process.env,
|
||||
GOTLIN_GOPLS_PATH: resolveGoplsPath()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [{ scheme: "file", language: "gotlin" }],
|
||||
outputChannelName: "Gotlin Language Server"
|
||||
};
|
||||
|
||||
client = new LanguageClient(
|
||||
"gotlin-lsp",
|
||||
"Gotlin Language Server",
|
||||
serverOptions,
|
||||
clientOptions
|
||||
);
|
||||
|
||||
await client.start();
|
||||
}
|
||||
|
||||
export async function deactivate(): Promise<void> {
|
||||
if (client) {
|
||||
await client.stop();
|
||||
client = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function resolveServerPath(): string | undefined {
|
||||
const configured = vscode.workspace
|
||||
.getConfiguration("gotlin")
|
||||
.get<string>("serverPath", "")
|
||||
.trim();
|
||||
|
||||
if (configured) {
|
||||
return configured;
|
||||
}
|
||||
|
||||
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
|
||||
if (workspaceFolder) {
|
||||
const candidate = path.join(workspaceFolder.uri.fsPath, "bin", platformBinaryName("gotlin-lsp"));
|
||||
if (fs.existsSync(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
return "gotlin-lsp";
|
||||
}
|
||||
|
||||
function platformBinaryName(base: string): string {
|
||||
return process.platform === "win32" ? `${base}.exe` : base;
|
||||
}
|
||||
|
||||
function resolveGoplsPath(): string {
|
||||
const configured = vscode.workspace
|
||||
.getConfiguration("gotlin")
|
||||
.get<string>("goplsPath", "")
|
||||
.trim();
|
||||
|
||||
return configured;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue