-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathextension.js
More file actions
94 lines (83 loc) · 2.56 KB
/
Copy pathextension.js
File metadata and controls
94 lines (83 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const vscode = require("vscode");
const fs = require("node:fs");
const path = require("node:path");
const { LanguageClient, TransportKind } = require("vscode-languageclient/node");
const { ensureServerBinary, CONFIG_SECTION } = require("./installer");
let client;
// Resolve the server binary on PATH, preferring the new `lsp` name and
// falling back to the legacy `iii-lsp` name for older installs.
function resolvePathBinary() {
const candidates = ["lsp", "iii-lsp"];
const pathEntries = (process.env.PATH || "").split(path.delimiter).filter(Boolean);
const exts = process.platform === "win32"
? (process.env.PATHEXT || ".EXE;.CMD;.BAT").split(";")
: [""];
for (const candidate of candidates) {
for (const dir of pathEntries) {
for (const ext of exts) {
const full = path.join(dir, candidate + ext);
try {
const stat = fs.statSync(full);
if (!stat.isFile()) {
continue;
}
if (process.platform !== "win32") {
fs.accessSync(full, fs.constants.X_OK);
}
return full;
} catch {
// not here, keep looking
}
}
}
}
// Nothing on PATH; default to the new name and let the OS resolve it.
return candidates[0];
}
async function activate(context) {
const config = vscode.workspace.getConfiguration(CONFIG_SECTION);
const engineUrl = config.get("engineUrl") || "ws://127.0.0.1:49134";
let serverPath;
try {
serverPath = await ensureServerBinary(context, vscode);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
vscode.window.showWarningMessage(
`Failed to install lsp binary. Falling back to configured path or PATH lookup. ${message}`
);
serverPath = config.get("serverPath") || resolvePathBinary();
}
const serverOptions = {
run: {
command: serverPath,
args: ["--url", engineUrl],
transport: TransportKind.stdio,
},
debug: {
command: serverPath,
args: ["--url", engineUrl],
transport: TransportKind.stdio,
},
};
const clientOptions = {
documentSelector: [
{ scheme: "file", language: "typescript" },
{ scheme: "file", language: "typescriptreact" },
{ scheme: "file", language: "python" },
{ scheme: "file", language: "rust" },
],
};
client = new LanguageClient(
"iii-lsp",
"iii Language Server",
serverOptions,
clientOptions
);
client.start();
}
function deactivate() {
if (client) {
return client.stop();
}
}
module.exports = { activate, deactivate };