@floydous/pi-agent-kernel 0.4.2 → 0.5.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/AGENT_KERNEL_SYS_PROMPT.md +1 -7
- package/CHANGELOG.md +48 -0
- package/README.md +6 -53
- package/config.example.toml +0 -8
- package/docs/README.md +1 -2
- package/docs/architecture.md +2 -3
- package/docs/configuration.md +10 -9
- package/docs/editing-and-verification.md +1 -3
- package/docs/retrieval.md +6 -11
- package/docs/testing.md +3 -3
- package/package.json +4 -2
- package/src/config/agent_kernel_command.ts +8 -39
- package/src/config/kernel_config.ts +30 -68
- package/src/config/toml.ts +6 -1
- package/src/editing/auto_heal.ts +1 -1
- package/src/editing/patch.ts +27 -16
- package/src/editing/post_edit_verification.ts +12 -10
- package/src/editing/smart_anchor.ts +7 -5
- package/src/editing/syntax-verify.ts +117 -15
- package/src/index.ts +15 -257
- package/src/retrieval/search_bm25.ts +4 -2
- package/src/retrieval/search_chunker.ts +1 -1
- package/src/retrieval/search_config.ts +4 -6
- package/src/retrieval/search_embedder.ts +3 -2
- package/src/retrieval/search_index.ts +82 -35
- package/src/retrieval/search_modal.ts +7 -8
- package/src/retrieval/{repomap.ts → tag_extractor.ts} +5 -292
- package/src/retrieval/tree_sitter_engine.ts +70 -34
- package/src/retrieval/workspace_walker.ts +6 -2
- package/src/safety/atomic_write.ts +1 -1
- package/src/safety/epistemic_guard.ts +122 -32
- package/src/safety/output_clamper.ts +57 -35
- package/src/tools/code_search_output.ts +2 -1
- package/src/tools/code_search_tool.ts +2 -5
- package/src/tools/context.ts +0 -14
- package/src/tools/edit_tool.ts +82 -115
- package/src/tools/read_tool.ts +42 -178
- package/src/ui/footer.ts +7 -7
- package/docs/lsp.md +0 -31
- package/src/lsp/adapters/base.ts +0 -42
- package/src/lsp/adapters/index.ts +0 -21
- package/src/lsp/adapters/python.ts +0 -37
- package/src/lsp/adapters/rust.ts +0 -35
- package/src/lsp/adapters/typescript.ts +0 -40
- package/src/lsp/index.ts +0 -13
- package/src/lsp/lsp_client.ts +0 -765
- package/src/lsp/lsp_detector.ts +0 -52
- package/src/lsp/lsp_formatter.ts +0 -323
- package/src/lsp/lsp_installer.ts +0 -320
- package/src/lsp/lsp_manager.ts +0 -202
- package/src/lsp/lsp_modal.ts +0 -675
- package/src/lsp/lsp_registry.ts +0 -600
- package/src/lsp/lsp_types.ts +0 -143
- package/src/retrieval/ast_search.ts +0 -999
- package/src/retrieval/symbol_reader.ts +0 -228
- package/src/tools/ast_search_formatter.ts +0 -161
- package/src/tools/ast_search_tool.ts +0 -146
- package/src/tools/lsp_tool.ts +0 -794
- package/src/tools/repo_map_tool.ts +0 -56
package/src/tools/read_tool.ts
CHANGED
|
@@ -3,18 +3,12 @@ import { Type } from "typebox";
|
|
|
3
3
|
import { Text, makeOutputText } from "../ui/tui_utils";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import * as fs from "node:fs";
|
|
6
|
-
import {
|
|
7
|
-
import { findSymbolSuggestions } from "../retrieval/ast_search";
|
|
8
|
-
import { computeLineHash, formatSmartAnchorLines } from "../editing/smart_anchor";
|
|
6
|
+
import { computeLineHash } from "../editing/smart_anchor";
|
|
9
7
|
import {
|
|
10
8
|
globalEpistemicGuard,
|
|
11
9
|
resolveUserPath,
|
|
12
10
|
} from "../safety/epistemic_guard";
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
function countFileLines(filePath: string): number {
|
|
16
|
-
return fs.readFileSync(filePath, "utf8").split("\n").length;
|
|
17
|
-
}
|
|
11
|
+
import type { SessionDeps } from "./context";
|
|
18
12
|
|
|
19
13
|
const MAX_READ_LINES = 2_000;
|
|
20
14
|
const MAX_READ_BYTES = 50 * 1024;
|
|
@@ -58,7 +52,7 @@ function formatReadLine(
|
|
|
58
52
|
numberWidth: number,
|
|
59
53
|
benchmarkMethod: string | undefined,
|
|
60
54
|
): string {
|
|
61
|
-
const line = lines[index]
|
|
55
|
+
const line = lines[index] ?? "";
|
|
62
56
|
if (useAnchors) {
|
|
63
57
|
return `${String(index + 1).padStart(numberWidth, " ")}#${computeLineHash(lines, index)}│${line}`;
|
|
64
58
|
}
|
|
@@ -69,7 +63,7 @@ function formatReadLine(
|
|
|
69
63
|
}
|
|
70
64
|
|
|
71
65
|
function selectReadLineIndexes(
|
|
72
|
-
|
|
66
|
+
_lines: readonly string[],
|
|
73
67
|
startIdx: number,
|
|
74
68
|
endIdx: number,
|
|
75
69
|
formatLine: (index: number) => string,
|
|
@@ -99,52 +93,50 @@ function lineRanges(indexes: readonly number[]): Array<{ startLine: number; endL
|
|
|
99
93
|
|
|
100
94
|
/** Extracted from index.ts — registers the `read` tool. */
|
|
101
95
|
export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
102
|
-
// 6. Tool: `read` (
|
|
96
|
+
// 6. Tool: `read` (Bounded File Reader with Line-Windowing - Replaces stock read tool)
|
|
103
97
|
const editMethod = process.env.PI_EDIT_METHOD?.toLowerCase();
|
|
104
98
|
const benchmarkMethod = ["line-range", "search-replace", "hash-anchor", "adaptive"].includes(editMethod || "") ? editMethod : undefined;
|
|
105
99
|
const readMode = process.env.PI_READ_MODE?.toLowerCase();
|
|
100
|
+
let readToolDescription =
|
|
101
|
+
"Read file contents with 50KB / 2,000-line caps. Supports bounded line-range inspection via 'offset' and 'limit', or batch inspection across multiple files via 'paths'.";
|
|
102
|
+
switch (benchmarkMethod) {
|
|
103
|
+
case "line-range":
|
|
104
|
+
readToolDescription = "Read source with line numbers for numeric line-range edits.";
|
|
105
|
+
break;
|
|
106
|
+
case "search-replace":
|
|
107
|
+
readToolDescription = "Read source text for exact search/replace edits.";
|
|
108
|
+
break;
|
|
109
|
+
case "adaptive":
|
|
110
|
+
readToolDescription = "Read source with line numbers. Prefer unique search/replace; use line ranges when needed.";
|
|
111
|
+
break;
|
|
112
|
+
default:
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
106
115
|
const readToolDefinition: any = {
|
|
107
116
|
name: "read",
|
|
108
|
-
label: "Read File
|
|
109
|
-
description:
|
|
110
|
-
|
|
111
|
-
? "Read source with line numbers for numeric line-range edits."
|
|
112
|
-
: benchmarkMethod === "search-replace"
|
|
113
|
-
? "Read source text for exact search/replace edits."
|
|
114
|
-
: benchmarkMethod === "adaptive"
|
|
115
|
-
? "Read source with line numbers. Prefer unique search/replace; use line ranges when needed."
|
|
116
|
-
: "Read file contents (plain text), extract a symbol via 'symbol', or read multiple files via 'paths'. Bounded at 2,000 lines or 50KB. Use 'offset'/'limit' for ranges.",
|
|
117
|
-
promptSnippet: "Read file contents, inspect line ranges, extract symbols, or read multiple files via 'paths'",
|
|
117
|
+
label: "Read File",
|
|
118
|
+
description: readToolDescription,
|
|
119
|
+
promptSnippet: "Read file contents, inspect line ranges, or read multiple files via 'paths'",
|
|
118
120
|
renderShell: "default",
|
|
119
121
|
parameters: Type.Object({
|
|
120
122
|
path: Type.Optional(
|
|
121
123
|
Type.String({
|
|
122
|
-
description: "
|
|
124
|
+
description: "Workspace-relative or absolute file path to inspect. For multiple files, use 'paths'",
|
|
123
125
|
}),
|
|
124
126
|
),
|
|
125
127
|
paths: Type.Optional(
|
|
126
128
|
Type.Array(Type.String(), {
|
|
127
|
-
description: "
|
|
128
|
-
}),
|
|
129
|
-
),
|
|
130
|
-
symbol: Type.Optional(
|
|
131
|
-
Type.String({
|
|
132
|
-
description: "Function, class, or type to extract",
|
|
129
|
+
description: "Array of file paths to read in a single batch (plain text only, bounded per file)",
|
|
133
130
|
}),
|
|
134
131
|
),
|
|
135
132
|
offset: Type.Optional(
|
|
136
133
|
Type.Number({
|
|
137
|
-
description: "
|
|
134
|
+
description: "1-based starting line number for windowed reads (best when examining code around an exact line coordinate from grep or test failures)",
|
|
138
135
|
}),
|
|
139
136
|
),
|
|
140
137
|
limit: Type.Optional(
|
|
141
138
|
Type.Number({
|
|
142
|
-
description: "Maximum lines to read",
|
|
143
|
-
}),
|
|
144
|
-
),
|
|
145
|
-
surrounding_lines: Type.Optional(
|
|
146
|
-
Type.Number({
|
|
147
|
-
description: "Extra surrounding context lines for symbol",
|
|
139
|
+
description: "Maximum number of lines to read starting from 'offset' (default: 250 for unconstrained reads; keep <= 60 for narrow inspection)",
|
|
148
140
|
}),
|
|
149
141
|
),
|
|
150
142
|
anchors: Type.Optional(
|
|
@@ -162,9 +154,9 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
162
154
|
_toolCallId: string,
|
|
163
155
|
params: any,
|
|
164
156
|
_signal: any,
|
|
165
|
-
|
|
157
|
+
_onUpdate: any,
|
|
166
158
|
ctx: any,
|
|
167
|
-
)
|
|
159
|
+
) {
|
|
168
160
|
let targetPaths: string[] = [];
|
|
169
161
|
if (params && typeof params === "object") {
|
|
170
162
|
if (Array.isArray(params.paths)) {
|
|
@@ -285,136 +277,7 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
285
277
|
};
|
|
286
278
|
}
|
|
287
279
|
|
|
288
|
-
|
|
289
|
-
if (readLimitError) {
|
|
290
|
-
return {
|
|
291
|
-
content: [{ type: "text", text: `[READ ERROR] ${readLimitError}: ${params.path}` }],
|
|
292
|
-
details: { error: "read_limit", maxBytes: MAX_READ_FILE_BYTES },
|
|
293
|
-
isError: true,
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// Mode 1: Targeted AST symbol extraction
|
|
298
|
-
if (params.symbol && params.symbol.trim()) {
|
|
299
|
-
const sym = params.symbol.trim();
|
|
300
|
-
onUpdate?.({
|
|
301
|
-
content: [
|
|
302
|
-
{
|
|
303
|
-
type: "text",
|
|
304
|
-
text: `Extracting symbol '${sym}' from ${params.path}...`,
|
|
305
|
-
},
|
|
306
|
-
],
|
|
307
|
-
});
|
|
308
|
-
let symbolSnapshot: string;
|
|
309
|
-
try {
|
|
310
|
-
symbolSnapshot = fs.readFileSync(resolvedPath, "utf8");
|
|
311
|
-
} catch (error: any) {
|
|
312
|
-
return {
|
|
313
|
-
content: [
|
|
314
|
-
{ type: "text", text: `[READ ERROR] Unable to read ${params.path}: ${error.message}` },
|
|
315
|
-
],
|
|
316
|
-
isError: true,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
const res = extractSymbolContent(
|
|
320
|
-
resolvedPath,
|
|
321
|
-
sym,
|
|
322
|
-
{ surroundingLines: params.surrounding_lines },
|
|
323
|
-
symbolSnapshot,
|
|
324
|
-
);
|
|
325
|
-
|
|
326
|
-
if (!res.found) {
|
|
327
|
-
const suggestions = findSymbolSuggestions(
|
|
328
|
-
ctx.cwd,
|
|
329
|
-
resolvedPath,
|
|
330
|
-
sym,
|
|
331
|
-
);
|
|
332
|
-
let errorText: string;
|
|
333
|
-
if (res.error) {
|
|
334
|
-
errorText = res.error;
|
|
335
|
-
} else if (suggestions.length > 0) {
|
|
336
|
-
const formattedSuggestions = suggestions
|
|
337
|
-
.map(
|
|
338
|
-
(s) =>
|
|
339
|
-
`- ${s.name} (${s.filePath}:${s.line}) [${s.kind}] ${s.signature}`,
|
|
340
|
-
)
|
|
341
|
-
.join("\n");
|
|
342
|
-
errorText = `Symbol '${sym}' not found in ${params.path}.\nDid you mean:\n${formattedSuggestions}`;
|
|
343
|
-
} else {
|
|
344
|
-
errorText = `Symbol '${sym}' not found in ${params.path}. ` +
|
|
345
|
-
(speculativeToolsEnabled(deps.getConfig, ctx.cwd)
|
|
346
|
-
? `Use 'ast_search' to locate symbols or 'rg' in bash to search text.`
|
|
347
|
-
: `Use 'code_search' to locate code or 'rg' in bash to search text.`);
|
|
348
|
-
}
|
|
349
|
-
return {
|
|
350
|
-
content: [{ type: "text", text: errorText }],
|
|
351
|
-
details: {
|
|
352
|
-
error: "symbol_not_found",
|
|
353
|
-
query: sym,
|
|
354
|
-
candidates: suggestions.map((s) => ({
|
|
355
|
-
name: s.name,
|
|
356
|
-
filePath: s.filePath,
|
|
357
|
-
line: s.line,
|
|
358
|
-
kind: s.kind,
|
|
359
|
-
})),
|
|
360
|
-
},
|
|
361
|
-
isError: true,
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// Record the exact snapshot used for extraction only after a successful
|
|
366
|
-
// symbol result; failed extraction must not authorize a mutation.
|
|
367
|
-
globalEpistemicGuard.recordFileRead(
|
|
368
|
-
resolvedPath,
|
|
369
|
-
deps.getSessionId(ctx),
|
|
370
|
-
ctx.cwd,
|
|
371
|
-
symbolSnapshot,
|
|
372
|
-
{
|
|
373
|
-
coverage: {
|
|
374
|
-
complete: false,
|
|
375
|
-
ranges: res.symbols.map((symbol) => ({
|
|
376
|
-
startLine: symbol.startLine,
|
|
377
|
-
endLine: symbol.endLine,
|
|
378
|
-
})),
|
|
379
|
-
totalLines: countFileLines(resolvedPath),
|
|
380
|
-
},
|
|
381
|
-
provenance: "symbol",
|
|
382
|
-
query: sym,
|
|
383
|
-
},
|
|
384
|
-
);
|
|
385
|
-
|
|
386
|
-
const config = deps.getConfig?.(ctx.cwd);
|
|
387
|
-
const defaultAnchors = config?.editing?.default_anchors ?? true;
|
|
388
|
-
const configuredReadMode = readMode ?? config?.editing?.read_mode ?? "auto";
|
|
389
|
-
const useAnchors = shouldUseAnchors(params, benchmarkMethod, configuredReadMode, defaultAnchors, true);
|
|
390
|
-
|
|
391
|
-
const allFileLines = symbolSnapshot.split("\n");
|
|
392
|
-
const formatted = res.symbols
|
|
393
|
-
.map((s) => {
|
|
394
|
-
const header = `// ${(path.relative(ctx.cwd, s.filePath) || s.filePath).replace(/\\/g, "/")}:${s.startLine}-${s.endLine} [${s.kind}] ${s.name}`;
|
|
395
|
-
const body = useAnchors
|
|
396
|
-
? formatSmartAnchorLines(allFileLines, s.startLine, s.endLine)
|
|
397
|
-
: benchmarkMethod === "line-range"
|
|
398
|
-
? allFileLines.slice(s.startLine - 1, s.endLine).map((line, index) => `${String(s.startLine + index).padStart(String(s.endLine).length, " ")}│${line}`).join("\n")
|
|
399
|
-
: s.content;
|
|
400
|
-
return `${header}\n${body}`;
|
|
401
|
-
})
|
|
402
|
-
.join("\n\n");
|
|
403
|
-
|
|
404
|
-
return {
|
|
405
|
-
content: [{ type: "text", text: formatted }],
|
|
406
|
-
details: {
|
|
407
|
-
count: res.symbols.length,
|
|
408
|
-
symbols: res.symbols.map((s) => ({
|
|
409
|
-
name: s.name,
|
|
410
|
-
kind: s.kind,
|
|
411
|
-
lines: `${s.startLine}-${s.endLine}`,
|
|
412
|
-
})),
|
|
413
|
-
},
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// Mode 2: Standard file reading
|
|
280
|
+
// Single file read
|
|
418
281
|
try {
|
|
419
282
|
const readLimitError = validateReadableFile(resolvedPath);
|
|
420
283
|
if (readLimitError) {
|
|
@@ -568,8 +431,11 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
568
431
|
}
|
|
569
432
|
const isTruncated = oversizedFirstLine || hasMore || startIdx > 0;
|
|
570
433
|
if (isTruncated && hasMore && !oversizedFirstLine && hiddenLines === 0) {
|
|
571
|
-
const
|
|
572
|
-
|
|
434
|
+
const lastIdx = visibleIndexes[visibleIndexes.length - 1];
|
|
435
|
+
if (lastIdx !== undefined) {
|
|
436
|
+
const lastShown = lastIdx + 1;
|
|
437
|
+
outputLines.push(`\n[Showing ${visibleIndexes.length} of ${totalLines} lines. Use offset=${lastShown + 1} to continue.]`);
|
|
438
|
+
}
|
|
573
439
|
}
|
|
574
440
|
const coverageRanges = lineRanges(visibleIndexes);
|
|
575
441
|
|
|
@@ -609,19 +475,17 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
609
475
|
`${theme.fg("toolTitle", theme.bold("read"))} [${theme.fg("accent", pathsSummary)}]`,
|
|
610
476
|
);
|
|
611
477
|
}
|
|
612
|
-
const
|
|
478
|
+
const path0 = Array.isArray(args?.paths) ? args.paths[0] : "";
|
|
479
|
+
const rawPath = args?.path || path0 || "";
|
|
613
480
|
const relPath = rawPath
|
|
614
481
|
? (path.relative(context.cwd, rawPath) || rawPath).replace(/\\/g, "/")
|
|
615
482
|
: "";
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
483
|
+
let range = "";
|
|
484
|
+
if (args?.offset || args?.limit) {
|
|
485
|
+
const off = args.offset ?? 1;
|
|
486
|
+
const lim = args.limit ? `-${off + args.limit - 1}` : "";
|
|
487
|
+
range = `:${off}${lim}`;
|
|
620
488
|
}
|
|
621
|
-
const range =
|
|
622
|
-
args?.offset || args?.limit
|
|
623
|
-
? `:${args.offset ?? 1}${args.limit ? `-${(args.offset ?? 1) + args.limit - 1}` : ""}`
|
|
624
|
-
: "";
|
|
625
489
|
return makeOutputText(
|
|
626
490
|
`${theme.fg("toolTitle", theme.bold("read"))} ${theme.fg("accent", relPath)}${theme.fg("warning", range)}`,
|
|
627
491
|
);
|
package/src/ui/footer.ts
CHANGED
|
@@ -63,7 +63,7 @@ export const Pastel = {
|
|
|
63
63
|
* Format numbers into compact token strings (e.g. 1.2k, 45k, 1.2M)
|
|
64
64
|
*/
|
|
65
65
|
export function formatTokens(count: number): string {
|
|
66
|
-
if (
|
|
66
|
+
if (!Number.isFinite(count) || count < 0) return "0";
|
|
67
67
|
if (count < 1000) return count.toString();
|
|
68
68
|
if (count < 10000) return `${(count / 1000).toFixed(1)}k`;
|
|
69
69
|
if (count < 1000000) return `${Math.round(count / 1000)}k`;
|
|
@@ -280,12 +280,12 @@ export function renderFooter(
|
|
|
280
280
|
|
|
281
281
|
// If retrieval is not yet recorded in extension statuses but searchIndex is provided, include it
|
|
282
282
|
if (searchIndex && !extEntries.some(([key]) => key === "retrieval")) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
283
|
+
let eff = "lean";
|
|
284
|
+
if (typeof searchIndex.getEffectiveProfile === "function") {
|
|
285
|
+
eff = searchIndex.getEffectiveProfile();
|
|
286
|
+
} else if (typeof searchIndex === "string") {
|
|
287
|
+
eff = searchIndex;
|
|
288
|
+
}
|
|
289
289
|
if (eff !== "off") {
|
|
290
290
|
const tag = formatSearchEngineTag(searchIndex, true);
|
|
291
291
|
extEntries.push(["retrieval", tag]);
|
package/docs/lsp.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# Language Server Protocol
|
|
2
|
-
|
|
3
|
-
LSP support lives under `src/lsp/`. It provides language-server discovery,
|
|
4
|
-
client lifecycle management, formatting, diagnostics, and interactive controls.
|
|
5
|
-
|
|
6
|
-
## Components
|
|
7
|
-
|
|
8
|
-
- `lsp_registry.ts` describes supported language servers.
|
|
9
|
-
- `lsp_detector.ts` detects a file language and workspace root.
|
|
10
|
-
- `lsp_client.ts` manages JSON-RPC communication with a server process.
|
|
11
|
-
- `lsp_manager.ts` owns client reuse, lifecycle, and status reporting.
|
|
12
|
-
- `lsp_formatter.ts` renders diagnostics and navigation results for agents.
|
|
13
|
-
- `lsp_installer.ts` handles optional server installation.
|
|
14
|
-
- `lsp_modal.ts` provides the interactive server-control UI.
|
|
15
|
-
|
|
16
|
-
## Edit verification
|
|
17
|
-
|
|
18
|
-
Post-edit verification only reuses a client that is already ready for the
|
|
19
|
-
edited file. It does not start a new server solely to verify an edit. If a
|
|
20
|
-
client is unavailable, the result remains explicitly `not run`, `unavailable`,
|
|
21
|
-
or otherwise uncertain; it is never presented as `clean`.
|
|
22
|
-
|
|
23
|
-
The LSP tool can request diagnostics, definitions, references, hover details,
|
|
24
|
-
and document symbols. AST-based fallback behavior is kept in
|
|
25
|
-
`src/retrieval/ast_search.ts` for cases where no ready language server can
|
|
26
|
-
answer the request.
|
|
27
|
-
|
|
28
|
-
## Output formatting
|
|
29
|
-
|
|
30
|
-
- Diagnostics render in token-minimal format (`- [line:col] [SEV] [code] message (source)`) with no redundant `<path>` preamble. Clean files return strictly `<path> clean`.
|
|
31
|
-
- References support `exclude_tests` and `exclude_declaration` filters with bounded code window snippets (`windowAround`).
|
package/src/lsp/adapters/base.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { LspDiagnostic } from "../lsp_types";
|
|
2
|
-
|
|
3
|
-
export interface LspAdapter {
|
|
4
|
-
readonly languageKey: string;
|
|
5
|
-
getInitializationOptions?(rootDir: string): Record<string, any>;
|
|
6
|
-
getClientCapabilities?(): Record<string, any>;
|
|
7
|
-
handleServerRequest?(method: string, params: any, rootDir: string): any;
|
|
8
|
-
transformDiagnostics?(uri: string, diagnostics: LspDiagnostic[]): LspDiagnostic[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class BaseLspAdapter implements LspAdapter {
|
|
12
|
-
public readonly languageKey: string;
|
|
13
|
-
|
|
14
|
-
constructor(languageKey = "generic") {
|
|
15
|
-
this.languageKey = languageKey;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public getInitializationOptions(_rootDir: string): Record<string, any> {
|
|
19
|
-
return {};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public getClientCapabilities(): Record<string, any> {
|
|
23
|
-
return {};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public handleServerRequest(method: string, params: any, rootDir: string): any {
|
|
27
|
-
switch (method) {
|
|
28
|
-
case "workspace/configuration":
|
|
29
|
-
return Array.isArray(params?.items) ? params.items.map(() => null) : [];
|
|
30
|
-
case "workspace/workspaceFolders":
|
|
31
|
-
return [{ uri: rootDir, name: "workspace" }];
|
|
32
|
-
case "workspace/applyEdit":
|
|
33
|
-
return { applied: false };
|
|
34
|
-
default:
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public transformDiagnostics(_uri: string, diagnostics: LspDiagnostic[]): LspDiagnostic[] {
|
|
40
|
-
return diagnostics;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { LspAdapter } from "./base";
|
|
2
|
-
import { BaseLspAdapter } from "./base";
|
|
3
|
-
import { TypeScriptLspAdapter } from "./typescript";
|
|
4
|
-
import { PythonLspAdapter } from "./python";
|
|
5
|
-
import { RustLspAdapter } from "./rust";
|
|
6
|
-
|
|
7
|
-
export * from "./base";
|
|
8
|
-
export * from "./typescript";
|
|
9
|
-
export * from "./python";
|
|
10
|
-
export * from "./rust";
|
|
11
|
-
|
|
12
|
-
const adapters = new Map<string, LspAdapter>([
|
|
13
|
-
["typescript", new TypeScriptLspAdapter()],
|
|
14
|
-
["python", new PythonLspAdapter()],
|
|
15
|
-
["rust", new RustLspAdapter()],
|
|
16
|
-
]);
|
|
17
|
-
|
|
18
|
-
export function getLspAdapter(languageKey: string): LspAdapter {
|
|
19
|
-
const norm = languageKey.toLowerCase();
|
|
20
|
-
return adapters.get(norm) || new BaseLspAdapter(norm);
|
|
21
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { BaseLspAdapter } from "./base";
|
|
2
|
-
|
|
3
|
-
export class PythonLspAdapter extends BaseLspAdapter {
|
|
4
|
-
constructor() {
|
|
5
|
-
super("python");
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
public override getInitializationOptions(_rootDir: string): Record<string, any> {
|
|
9
|
-
return {
|
|
10
|
-
analysis: {
|
|
11
|
-
autoSearchPaths: true,
|
|
12
|
-
useLibraryCodeForTypes: true,
|
|
13
|
-
diagnosticMode: "openFilesOnly",
|
|
14
|
-
typeCheckingMode: "basic",
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public override handleServerRequest(method: string, params: any, rootDir: string): any {
|
|
20
|
-
if (method === "workspace/configuration") {
|
|
21
|
-
const items = params?.items || [];
|
|
22
|
-
return items.map((item: any) => {
|
|
23
|
-
const section = item?.section || "";
|
|
24
|
-
if (section.startsWith("python") || section.startsWith("pyright") || section.startsWith("basedpyright")) {
|
|
25
|
-
return {
|
|
26
|
-
analysis: {
|
|
27
|
-
diagnosticMode: "openFilesOnly",
|
|
28
|
-
typeCheckingMode: "basic",
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return null;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return super.handleServerRequest(method, params, rootDir);
|
|
36
|
-
}
|
|
37
|
-
}
|
package/src/lsp/adapters/rust.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { BaseLspAdapter } from "./base";
|
|
2
|
-
|
|
3
|
-
export class RustLspAdapter extends BaseLspAdapter {
|
|
4
|
-
constructor() {
|
|
5
|
-
super("rust");
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
public override getInitializationOptions(_rootDir: string): Record<string, any> {
|
|
9
|
-
return {
|
|
10
|
-
checkOnSave: true,
|
|
11
|
-
diagnostics: {
|
|
12
|
-
enable: true,
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public override handleServerRequest(method: string, params: any, rootDir: string): any {
|
|
18
|
-
if (method === "workspace/configuration") {
|
|
19
|
-
const items = params?.items || [];
|
|
20
|
-
return items.map((item: any) => {
|
|
21
|
-
const section = item?.section || "";
|
|
22
|
-
if (section.startsWith("rust-analyzer") || section === "") {
|
|
23
|
-
return {
|
|
24
|
-
check: { command: "check" },
|
|
25
|
-
checkOnSave: true,
|
|
26
|
-
cargo: { buildScripts: { enable: true } },
|
|
27
|
-
diagnostics: { enable: true, experimental: { enable: true } },
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return {};
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return super.handleServerRequest(method, params, rootDir);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { BaseLspAdapter } from "./base";
|
|
2
|
-
import type { LspDiagnostic } from "../lsp_types";
|
|
3
|
-
|
|
4
|
-
export class TypeScriptLspAdapter extends BaseLspAdapter {
|
|
5
|
-
constructor() {
|
|
6
|
-
super("typescript");
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
public override getInitializationOptions(_rootDir: string): Record<string, any> {
|
|
10
|
-
return {
|
|
11
|
-
preferences: {
|
|
12
|
-
includeInlayParameterNameHints: "none",
|
|
13
|
-
includeInlayVariableTypeHints: false,
|
|
14
|
-
includeInlayFunctionParameterTypeHints: false,
|
|
15
|
-
},
|
|
16
|
-
tsserver: {
|
|
17
|
-
log: "off",
|
|
18
|
-
maxTsServerMemory: 4096,
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public override handleServerRequest(method: string, params: any, rootDir: string): any {
|
|
24
|
-
if (method === "workspace/configuration") {
|
|
25
|
-
const items = params?.items || [];
|
|
26
|
-
return items.map((item: any) => {
|
|
27
|
-
const section = item?.section || "";
|
|
28
|
-
if (section.startsWith("typescript") || section.startsWith("javascript") || section.startsWith("vtsls")) {
|
|
29
|
-
return {};
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return super.handleServerRequest(method, params, rootDir);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public override transformDiagnostics(_uri: string, diagnostics: LspDiagnostic[]): LspDiagnostic[] {
|
|
38
|
-
return diagnostics;
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/lsp/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public LSP Module Exports
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export * from "./lsp_types";
|
|
6
|
-
export * from "./adapters";
|
|
7
|
-
export * from "./lsp_registry";
|
|
8
|
-
export * from "./lsp_detector";
|
|
9
|
-
export * from "./lsp_formatter";
|
|
10
|
-
export * from "./lsp_client";
|
|
11
|
-
export * from "./lsp_manager";
|
|
12
|
-
export * from "./lsp_installer";
|
|
13
|
-
export * from "./lsp_modal";
|