@agenthead/graph 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +376 -2
- package/THIRD_PARTY_NOTICES.md +474 -0
- package/dist/graph-signals.d.ts +4 -0
- package/dist/graph-signals.js +101 -0
- package/dist/graph-signals.js.map +1 -0
- package/dist/graph-store.d.ts +38 -0
- package/dist/graph-store.js +273 -0
- package/dist/graph-store.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/load-signals.d.ts +7 -0
- package/dist/load-signals.js +35 -0
- package/dist/load-signals.js.map +1 -0
- package/dist/lsp-bridge.d.ts +91 -0
- package/dist/lsp-bridge.js +454 -0
- package/dist/lsp-bridge.js.map +1 -0
- package/dist/lsp-client.d.ts +42 -0
- package/dist/lsp-client.js +233 -0
- package/dist/lsp-client.js.map +1 -0
- package/dist/migrations.d.ts +3 -0
- package/dist/migrations.js +32 -0
- package/dist/migrations.js.map +1 -0
- package/dist/parser.d.ts +3 -0
- package/dist/parser.js +404 -0
- package/dist/parser.js.map +1 -0
- package/dist/resolve-import.d.ts +3 -0
- package/dist/resolve-import.js +71 -0
- package/dist/resolve-import.js.map +1 -0
- package/dist/types.d.ts +68 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +53 -4
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import { isUtf8 } from "node:buffer";
|
|
2
|
+
import { accessSync, constants, existsSync, mkdtempSync, realpathSync, rmSync, statSync, } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { basename, delimiter, extname, isAbsolute, join, sep } from "node:path";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import { LspClient, LspError, } from "./lsp-client.js";
|
|
7
|
+
const defaults = {
|
|
8
|
+
typescript: { command: "typescript-language-server", args: ["--stdio"] },
|
|
9
|
+
python: { command: "pyright-langserver", args: ["--stdio"] },
|
|
10
|
+
};
|
|
11
|
+
// typescript-language-server options: no automatic type acquisition, which
|
|
12
|
+
// downloads @types packages, and no syntax server, which answers while the
|
|
13
|
+
// project loads but knows only the open files.
|
|
14
|
+
const initializationOptions = {
|
|
15
|
+
typescript: {
|
|
16
|
+
disableAutomaticTypingAcquisition: true,
|
|
17
|
+
tsserver: { useSyntaxServer: "never" },
|
|
18
|
+
},
|
|
19
|
+
python: undefined,
|
|
20
|
+
};
|
|
21
|
+
const languageIds = {
|
|
22
|
+
".ts": "typescript",
|
|
23
|
+
".mts": "typescript",
|
|
24
|
+
".cts": "typescript",
|
|
25
|
+
".tsx": "typescriptreact",
|
|
26
|
+
".js": "javascript",
|
|
27
|
+
".mjs": "javascript",
|
|
28
|
+
".cjs": "javascript",
|
|
29
|
+
".jsx": "javascriptreact",
|
|
30
|
+
".py": "python",
|
|
31
|
+
};
|
|
32
|
+
function familyOf(file) {
|
|
33
|
+
const languageId = languageIds[extname(file).toLowerCase()];
|
|
34
|
+
if (!languageId)
|
|
35
|
+
return undefined;
|
|
36
|
+
return languageId === "python" ? "python" : "typescript";
|
|
37
|
+
}
|
|
38
|
+
function isRecord(value) {
|
|
39
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
40
|
+
}
|
|
41
|
+
function isIndex(value) {
|
|
42
|
+
return (Number.isInteger(value) &&
|
|
43
|
+
value >= 0 &&
|
|
44
|
+
value < 2 ** 31);
|
|
45
|
+
}
|
|
46
|
+
function isRange(value) {
|
|
47
|
+
if (!isRecord(value) || !isRecord(value.start) || !isRecord(value.end))
|
|
48
|
+
return false;
|
|
49
|
+
const { start, end } = value;
|
|
50
|
+
return (isIndex(start.line) &&
|
|
51
|
+
isIndex(start.character) &&
|
|
52
|
+
isIndex(end.line) &&
|
|
53
|
+
isIndex(end.character) &&
|
|
54
|
+
(end.line > start.line ||
|
|
55
|
+
(end.line === start.line && end.character >= start.character)));
|
|
56
|
+
}
|
|
57
|
+
function plain({ file, line, column, endLine, endColumn }) {
|
|
58
|
+
return { file, line, column, endLine, endColumn };
|
|
59
|
+
}
|
|
60
|
+
function compare(a, b) {
|
|
61
|
+
return ((a.file < b.file ? -1 : a.file > b.file ? 1 : 0) ||
|
|
62
|
+
a.line - b.line ||
|
|
63
|
+
a.column - b.column ||
|
|
64
|
+
a.endLine - b.endLine ||
|
|
65
|
+
a.endColumn - b.endColumn);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Look a bare command up on PATH. Relative entries are skipped, as are
|
|
69
|
+
* directories and executables that resolve inside the project, so the
|
|
70
|
+
* executable is never one the project provides.
|
|
71
|
+
*/
|
|
72
|
+
function findOnPath(name, root) {
|
|
73
|
+
const folded = root.toLowerCase();
|
|
74
|
+
const inside = (path) => path.toLowerCase() === folded ||
|
|
75
|
+
path.toLowerCase().startsWith(folded.endsWith(sep) ? folded : folded + sep);
|
|
76
|
+
for (const entry of (process.env.PATH ?? "").split(delimiter)) {
|
|
77
|
+
if (!isAbsolute(entry))
|
|
78
|
+
continue;
|
|
79
|
+
try {
|
|
80
|
+
const directory = realpathSync(entry);
|
|
81
|
+
const path = realpathSync(join(directory, name));
|
|
82
|
+
if (inside(directory) || inside(path) || !statSync(path).isFile())
|
|
83
|
+
continue;
|
|
84
|
+
accessSync(path, constants.X_OK);
|
|
85
|
+
return path;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// Not in this entry.
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The caller's environment without relative PATH entries, which would resolve
|
|
95
|
+
* inside the project: the server runs in the project root. Its temporary
|
|
96
|
+
* directory is `temporary`, under the names Node, Python and Windows read.
|
|
97
|
+
*/
|
|
98
|
+
function serverEnvironment(temporary) {
|
|
99
|
+
const env = { ...process.env };
|
|
100
|
+
const path = process.env.PATH ?? "";
|
|
101
|
+
const replaced = ["PATH", "TMPDIR", "TMP", "TEMP"];
|
|
102
|
+
for (const key of Object.keys(env))
|
|
103
|
+
if (replaced.includes(key.toUpperCase()))
|
|
104
|
+
delete env[key];
|
|
105
|
+
env.PATH = path
|
|
106
|
+
.split(delimiter)
|
|
107
|
+
.filter((entry) => isAbsolute(entry))
|
|
108
|
+
.join(delimiter);
|
|
109
|
+
env.TMPDIR = env.TMP = env.TEMP = temporary;
|
|
110
|
+
return env;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Bridge options from `AGENTHEAD_LSP`, the switch the CLI and the MCP server read.
|
|
114
|
+
* Language servers can run code from the project, so they are off unless it is
|
|
115
|
+
* `on`. Unset, empty or `off` turns both off; any other value throws, so a
|
|
116
|
+
* misspelt setting is noticed rather than read either way.
|
|
117
|
+
*/
|
|
118
|
+
export function lspOptionsFromEnv(env = process.env) {
|
|
119
|
+
const setting = env.AGENTHEAD_LSP ?? "";
|
|
120
|
+
if (setting === "on")
|
|
121
|
+
return {};
|
|
122
|
+
if (setting === "" || setting === "off")
|
|
123
|
+
return { typescript: false, python: false };
|
|
124
|
+
throw new Error(`AGENTHEAD_LSP must be on or off, got ${JSON.stringify(setting)}`);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Definitions and references from a language server when one is available and
|
|
128
|
+
* healthy, otherwise from the graph's name matches. Every location a server
|
|
129
|
+
* returns is checked against the graph's workspace boundary.
|
|
130
|
+
*/
|
|
131
|
+
export class LspBridge {
|
|
132
|
+
graph;
|
|
133
|
+
boundary;
|
|
134
|
+
configs;
|
|
135
|
+
startupTimeoutMs;
|
|
136
|
+
timeoutMs;
|
|
137
|
+
servers = new Map();
|
|
138
|
+
/** The servers' temporary directory: made for the first, removed by close(). */
|
|
139
|
+
temporary;
|
|
140
|
+
closed = false;
|
|
141
|
+
constructor(graph, options = {}) {
|
|
142
|
+
this.graph = graph;
|
|
143
|
+
this.boundary = graph.boundary;
|
|
144
|
+
this.startupTimeoutMs = options.startupTimeoutMs ?? 30_000;
|
|
145
|
+
this.timeoutMs = options.timeoutMs ?? 30_000;
|
|
146
|
+
// setTimeout fires at once for delays above 2^31 - 1.
|
|
147
|
+
for (const [name, value] of Object.entries({
|
|
148
|
+
startupTimeoutMs: this.startupTimeoutMs,
|
|
149
|
+
timeoutMs: this.timeoutMs,
|
|
150
|
+
}))
|
|
151
|
+
if (!isIndex(value) || value === 0)
|
|
152
|
+
throw new RangeError(`${name} must be an integer from 1 to 2^31 - 1`);
|
|
153
|
+
this.configs = {
|
|
154
|
+
typescript: options.typescript ?? defaults.typescript,
|
|
155
|
+
python: options.python ?? defaults.python,
|
|
156
|
+
};
|
|
157
|
+
for (const config of Object.values(this.configs)) {
|
|
158
|
+
if (config &&
|
|
159
|
+
(!config.command ||
|
|
160
|
+
(!isAbsolute(config.command) && /[\\/]/.test(config.command)) ||
|
|
161
|
+
[config.command, ...(config.args ?? [])].some((part) => part.includes("\0"))))
|
|
162
|
+
throw new TypeError("A language server command must be an absolute path or a bare name, without NUL");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/** Where the symbol at a position is declared. */
|
|
166
|
+
definitions(at) {
|
|
167
|
+
return this.query(at, "textDocument/definition", "definitionProvider", {}, (name) => this.graph.definitions(name), false);
|
|
168
|
+
}
|
|
169
|
+
/** Uses of the symbol at a position, without its declaration. */
|
|
170
|
+
references(at) {
|
|
171
|
+
return this.query(at, "textDocument/references", "referencesProvider", { context: { includeDeclaration: false } }, (name) => this.graph.references(name), true);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Tell the running servers which files an index run added, changed or
|
|
175
|
+
* removed, with `workspace/didChangeWatchedFiles`, so that they read those
|
|
176
|
+
* files again. Pass it the report of every `graph.index()` while the bridge
|
|
177
|
+
* is open. A server that has not started yet reads the files when it does.
|
|
178
|
+
*/
|
|
179
|
+
filesChanged({ changes }) {
|
|
180
|
+
if (this.closed)
|
|
181
|
+
return;
|
|
182
|
+
// FileChangeType: 1 created, 2 changed, 3 deleted.
|
|
183
|
+
const events = [
|
|
184
|
+
...changes.added.map((file) => ({ file, type: 1 })),
|
|
185
|
+
...changes.changed.map((file) => ({ file, type: 2 })),
|
|
186
|
+
...changes.removed.map((file) => ({ file, type: 3 })),
|
|
187
|
+
];
|
|
188
|
+
for (const [family, pending] of this.servers) {
|
|
189
|
+
const found = events.flatMap(({ file, type }) => {
|
|
190
|
+
if (familyOf(file) !== family)
|
|
191
|
+
return [];
|
|
192
|
+
let path;
|
|
193
|
+
try {
|
|
194
|
+
path = this.boundary.resolveSource(file).absolutePath;
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
// Now outside the project or excluded: nothing to tell.
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
// The graph also drops a file that is still there, such as one that
|
|
201
|
+
// is no longer UTF-8.
|
|
202
|
+
const kind = type === 3 && existsSync(path) ? 2 : type;
|
|
203
|
+
return [{ uri: pathToFileURL(path).href, type: kind }];
|
|
204
|
+
});
|
|
205
|
+
if (found.length)
|
|
206
|
+
void pending.then((server) => {
|
|
207
|
+
if (typeof server !== "string")
|
|
208
|
+
server.client.notify("workspace/didChangeWatchedFiles", {
|
|
209
|
+
changes: found,
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Shut down every server this bridge started and remove their temporary
|
|
216
|
+
* directory. Later queries throw.
|
|
217
|
+
*/
|
|
218
|
+
async close() {
|
|
219
|
+
this.closed = true;
|
|
220
|
+
await Promise.all([...this.servers.values()].map(async (pending) => {
|
|
221
|
+
const server = await pending;
|
|
222
|
+
if (typeof server !== "string")
|
|
223
|
+
await server.client.stop(this.timeoutMs);
|
|
224
|
+
}));
|
|
225
|
+
if (this.temporary)
|
|
226
|
+
rmSync(this.temporary, { recursive: true, force: true });
|
|
227
|
+
}
|
|
228
|
+
async query(at, method, capability, params, fallback, seed) {
|
|
229
|
+
if (this.closed)
|
|
230
|
+
throw new Error("The LSP bridge is closed");
|
|
231
|
+
if (!isIndex(at.line) || !isIndex(at.column) || !at.line || !at.column)
|
|
232
|
+
throw new RangeError("A position needs a one-based line and column");
|
|
233
|
+
// Throws for paths outside the project or excluded, as graph queries do.
|
|
234
|
+
const { absolutePath, relativePath } = this.boundary.resolveSource(at.file);
|
|
235
|
+
const file = relativePath.split(sep).join("/");
|
|
236
|
+
const family = familyOf(file);
|
|
237
|
+
const name = this.graph.nameAt(file, at.line, at.column);
|
|
238
|
+
let reason = "unavailable";
|
|
239
|
+
if (family) {
|
|
240
|
+
const server = await this.server(family);
|
|
241
|
+
// A server searches only the files it knows: those it has listed so far
|
|
242
|
+
// (pyright lists them in the background) or, without a tsconfig, the
|
|
243
|
+
// open ones. So references first open every file that can refer to the
|
|
244
|
+
// name.
|
|
245
|
+
const files = [file];
|
|
246
|
+
if (seed && name !== undefined && typeof server !== "string")
|
|
247
|
+
files.push(...this.seeds(name, family).filter((other) => other !== file));
|
|
248
|
+
if (typeof server === "string")
|
|
249
|
+
reason = server;
|
|
250
|
+
else if (server.capabilities[capability] && this.sync(server, files)) {
|
|
251
|
+
try {
|
|
252
|
+
const result = await server.client.request(method, {
|
|
253
|
+
textDocument: { uri: pathToFileURL(absolutePath).href },
|
|
254
|
+
position: { line: at.line - 1, character: at.column - 1 },
|
|
255
|
+
...params,
|
|
256
|
+
}, this.timeoutMs);
|
|
257
|
+
return { source: "lsp", locations: this.locations(result) };
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
reason = error instanceof LspError ? error.reason : "crashed";
|
|
261
|
+
// A late request was cancelled and an error answer was an answer:
|
|
262
|
+
// the server stays. The client stopped one that hung or exited, and
|
|
263
|
+
// fails every later request; forget it and the files it had open.
|
|
264
|
+
if (server.client.stopped)
|
|
265
|
+
this.servers.set(family, Promise.resolve(reason));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// A Python name never refers to a TypeScript or JavaScript symbol.
|
|
270
|
+
return {
|
|
271
|
+
source: "graph",
|
|
272
|
+
reason,
|
|
273
|
+
locations: name === undefined
|
|
274
|
+
? []
|
|
275
|
+
: fallback(name)
|
|
276
|
+
.filter((entry) => familyOf(entry.file) === family)
|
|
277
|
+
.map(plain),
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/** Files where the graph records `name`, and importers of those defining it. */
|
|
281
|
+
seeds(name, family) {
|
|
282
|
+
const files = new Set(this.graph.references(name).map((entry) => entry.file));
|
|
283
|
+
for (const file of new Set(this.graph.definitions(name).map((entry) => entry.file))) {
|
|
284
|
+
files.add(file);
|
|
285
|
+
for (const importer of this.graph.importers(file))
|
|
286
|
+
files.add(importer);
|
|
287
|
+
}
|
|
288
|
+
return [...files].filter((file) => familyOf(file) === family).sort();
|
|
289
|
+
}
|
|
290
|
+
server(family) {
|
|
291
|
+
let server = this.servers.get(family);
|
|
292
|
+
if (!server) {
|
|
293
|
+
server = this.start(family);
|
|
294
|
+
this.servers.set(family, server);
|
|
295
|
+
}
|
|
296
|
+
return server;
|
|
297
|
+
}
|
|
298
|
+
async start(family) {
|
|
299
|
+
const config = this.configs[family];
|
|
300
|
+
if (!config)
|
|
301
|
+
return "disabled";
|
|
302
|
+
const root = this.boundary.root;
|
|
303
|
+
const command = isAbsolute(config.command)
|
|
304
|
+
? config.command
|
|
305
|
+
: findOnPath(config.command, root);
|
|
306
|
+
if (!command)
|
|
307
|
+
return "unavailable";
|
|
308
|
+
let client;
|
|
309
|
+
try {
|
|
310
|
+
// Private to the user, outside the project, and gone after close(),
|
|
311
|
+
// with whatever a killed server left in it.
|
|
312
|
+
this.temporary ??= mkdtempSync(join(tmpdir(), "agenthead-lsp-servers-"));
|
|
313
|
+
client = new LspClient(command, config.args ?? [], root, serverEnvironment(this.temporary));
|
|
314
|
+
const rootUri = pathToFileURL(root).href;
|
|
315
|
+
const result = await client.request("initialize", {
|
|
316
|
+
processId: process.pid,
|
|
317
|
+
clientInfo: { name: "agenthead" },
|
|
318
|
+
rootUri,
|
|
319
|
+
// pyright reads its workspace from these, not from rootUri.
|
|
320
|
+
workspaceFolders: [{ uri: rootUri, name: basename(root) }],
|
|
321
|
+
capabilities: {
|
|
322
|
+
general: { positionEncodings: ["utf-16"] },
|
|
323
|
+
// Sent by filesChanged; servers cannot register their own watchers.
|
|
324
|
+
workspace: {
|
|
325
|
+
didChangeWatchedFiles: { dynamicRegistration: false },
|
|
326
|
+
},
|
|
327
|
+
textDocument: {
|
|
328
|
+
synchronization: { dynamicRegistration: false },
|
|
329
|
+
definition: { dynamicRegistration: false, linkSupport: true },
|
|
330
|
+
references: { dynamicRegistration: false },
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
initializationOptions: initializationOptions[family],
|
|
334
|
+
}, this.startupTimeoutMs);
|
|
335
|
+
const capabilities = isRecord(result) && isRecord(result.capabilities)
|
|
336
|
+
? result.capabilities
|
|
337
|
+
: {};
|
|
338
|
+
// Columns are UTF-16 code units, the only encoding the client offers.
|
|
339
|
+
if ((capabilities.positionEncoding ?? "utf-16") !== "utf-16") {
|
|
340
|
+
client.kill();
|
|
341
|
+
return "unavailable";
|
|
342
|
+
}
|
|
343
|
+
client.notify("initialized", {});
|
|
344
|
+
return { client, capabilities, documents: new Map() };
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
client?.kill();
|
|
348
|
+
// spawn can throw at once. That, like an error answer to initialize,
|
|
349
|
+
// means the server did not start.
|
|
350
|
+
if (!(error instanceof LspError) || error.reason === "error")
|
|
351
|
+
return "unavailable";
|
|
352
|
+
return error.reason;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Bring the server's copy of every file it was given up to date, then open
|
|
357
|
+
* those of `files` it has not seen. A server reads an open file from the
|
|
358
|
+
* client, never from disk, so an unsynced copy would answer from old text.
|
|
359
|
+
* False if `files[0]`, the queried file, cannot be read as UTF-8; other
|
|
360
|
+
* files that cannot be read are left out.
|
|
361
|
+
*/
|
|
362
|
+
sync(server, files) {
|
|
363
|
+
for (const [open, document] of server.documents) {
|
|
364
|
+
const text = this.read(open);
|
|
365
|
+
if (text === undefined) {
|
|
366
|
+
server.documents.delete(open);
|
|
367
|
+
server.client.notify("textDocument/didClose", {
|
|
368
|
+
textDocument: { uri: document.uri },
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
else if (text !== document.text) {
|
|
372
|
+
document.version++;
|
|
373
|
+
document.text = text;
|
|
374
|
+
server.client.notify("textDocument/didChange", {
|
|
375
|
+
textDocument: { uri: document.uri, version: document.version },
|
|
376
|
+
contentChanges: [{ text }],
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
for (const [index, file] of files.entries()) {
|
|
381
|
+
if (server.documents.has(file))
|
|
382
|
+
continue;
|
|
383
|
+
const text = this.read(file);
|
|
384
|
+
if (text === undefined) {
|
|
385
|
+
if (index === 0)
|
|
386
|
+
return false;
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
const uri = pathToFileURL(this.boundary.resolveSource(file).absolutePath).href;
|
|
390
|
+
server.documents.set(file, { uri, version: 1, text });
|
|
391
|
+
server.client.notify("textDocument/didOpen", {
|
|
392
|
+
textDocument: {
|
|
393
|
+
uri,
|
|
394
|
+
languageId: languageIds[extname(file).toLowerCase()],
|
|
395
|
+
version: 1,
|
|
396
|
+
text,
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
/** A file's text, read through the boundary; undefined if gone or not UTF-8. */
|
|
403
|
+
read(file) {
|
|
404
|
+
try {
|
|
405
|
+
const bytes = this.boundary.readSource(file);
|
|
406
|
+
return isUtf8(bytes) ? bytes.toString("utf8") : undefined;
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
return undefined;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/** File locations inside the boundary, canonical, deduplicated and sorted. */
|
|
413
|
+
locations(result) {
|
|
414
|
+
const found = new Map();
|
|
415
|
+
// Many locations share a file; check each URI once.
|
|
416
|
+
const files = new Map();
|
|
417
|
+
const items = Array.isArray(result) ? result : result ? [result] : [];
|
|
418
|
+
for (const item of items) {
|
|
419
|
+
if (!isRecord(item))
|
|
420
|
+
continue;
|
|
421
|
+
// A LocationLink's selection range is the declared name.
|
|
422
|
+
const [uri, range] = item.targetUri === undefined
|
|
423
|
+
? [item.uri, item.range]
|
|
424
|
+
: [item.targetUri, item.targetSelectionRange ?? item.targetRange];
|
|
425
|
+
if (typeof uri !== "string" || !isRange(range))
|
|
426
|
+
continue;
|
|
427
|
+
if (!files.has(uri)) {
|
|
428
|
+
try {
|
|
429
|
+
files.set(uri, this.boundary
|
|
430
|
+
.resolveSource(fileURLToPath(uri))
|
|
431
|
+
.relativePath.split(sep)
|
|
432
|
+
.join("/"));
|
|
433
|
+
}
|
|
434
|
+
catch {
|
|
435
|
+
// Not a file URL, outside the project, excluded or unresolvable.
|
|
436
|
+
files.set(uri, undefined);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
const file = files.get(uri);
|
|
440
|
+
if (file === undefined)
|
|
441
|
+
continue;
|
|
442
|
+
const location = {
|
|
443
|
+
file,
|
|
444
|
+
line: range.start.line + 1,
|
|
445
|
+
column: range.start.character + 1,
|
|
446
|
+
endLine: range.end.line + 1,
|
|
447
|
+
endColumn: range.end.character + 1,
|
|
448
|
+
};
|
|
449
|
+
found.set(JSON.stringify(location), location);
|
|
450
|
+
}
|
|
451
|
+
return [...found.values()].sort(compare);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
//# sourceMappingURL=lsp-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lsp-bridge.js","sourceRoot":"","sources":["../src/lsp-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC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I,CAAC,GAAG,CAAC,CACb,CAAC;gBACJ,CAAC;gBAAC,MAAM,CAAC;oBACP,iEAAiE;oBACjE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;YACD,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,IAAI,KAAK,SAAS;gBAAE,SAAS;YACjC,MAAM,QAAQ,GAAG;gBACf,IAAI;gBACJ,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC;gBAC1B,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC;gBACjC,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;gBAC3B,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC;aACnC,CAAC;YACF,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Why a language server gave no answer. */
|
|
2
|
+
export type LspFailure = "unavailable" | "timeout" | "crashed" | "error";
|
|
3
|
+
export declare class LspError extends Error {
|
|
4
|
+
readonly reason: LspFailure;
|
|
5
|
+
readonly name = "LspError";
|
|
6
|
+
constructor(reason: LspFailure, message: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* One language server process, spoken to with JSON-RPC 2.0 and Content-Length
|
|
10
|
+
* framing over stdio. A request that misses its deadline fails with "timeout"
|
|
11
|
+
* and is cancelled with `$/cancelRequest`; the server stays. A server must
|
|
12
|
+
* still answer a cancelled request, so one that has not within another
|
|
13
|
+
* deadline has hung. That, an exit or a broken frame stops the server's whole
|
|
14
|
+
* process group and fails every pending and later request. The client answers
|
|
15
|
+
* requests from the server with MethodNotFound and ignores its notifications.
|
|
16
|
+
*/
|
|
17
|
+
export declare class LspClient {
|
|
18
|
+
private readonly child;
|
|
19
|
+
private readonly pending;
|
|
20
|
+
private nextId;
|
|
21
|
+
private chunks;
|
|
22
|
+
private size;
|
|
23
|
+
private needed;
|
|
24
|
+
private failure;
|
|
25
|
+
/** Settles when the process exits or fails to start. */
|
|
26
|
+
readonly exited: Promise<void>;
|
|
27
|
+
constructor(command: string, args: readonly string[], cwd: string, env: NodeJS.ProcessEnv);
|
|
28
|
+
request(method: string, params: unknown, timeoutMs: number): Promise<unknown>;
|
|
29
|
+
/** True once the process is stopped: every request fails at once. */
|
|
30
|
+
get stopped(): boolean;
|
|
31
|
+
notify(method: string, params?: unknown): void;
|
|
32
|
+
/** Stop the process group now and fail every pending request. */
|
|
33
|
+
kill(): void;
|
|
34
|
+
/** Ask for a clean shutdown, then stop the process group regardless. */
|
|
35
|
+
stop(timeoutMs: number): Promise<void>;
|
|
36
|
+
/** Fail a late request now, then stop the server if it never answers. */
|
|
37
|
+
private cancel;
|
|
38
|
+
private send;
|
|
39
|
+
private fail;
|
|
40
|
+
private receive;
|
|
41
|
+
private handle;
|
|
42
|
+
}
|