@mrclrchtr/supi-code-intelligence 11.3.0 → 12.0.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/CHANGELOG.md +33 -0
- package/README.md +15 -9
- package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
- package/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
- package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/README.md +22 -17
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/range.js +2 -2
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/constants.js +30 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +2 -2
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-capabilities.ts +13 -3
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +25 -9
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +7 -5
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-edit-capture.ts +258 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +64 -11
- package/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +8 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/config/operation-support.ts +48 -79
- package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +10 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-typescript-coverage.ts +118 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +67 -3
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/typescript-file-local.ts +87 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-refactor-provider.ts +21 -35
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-command-capture.ts +139 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +202 -47
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +22 -17
- package/node_modules/@mrclrchtr/supi-lsp/src/session/route-boundary.ts +26 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +106 -16
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-rename.ts +3 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +22 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +3 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +64 -28
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm +0 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +5 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm +0 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +5 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/coordinates.ts +16 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client.ts +3 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/syntax-errors.ts +2 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-range.ts +94 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +26 -6
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +6 -3
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/exports.ts +13 -4
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime.ts +1 -9
- package/package.json +5 -5
- package/src/analysis/health/server-status.ts +41 -12
- package/src/analysis/helpers.ts +0 -7
- package/src/analysis/relations/implementations.ts +5 -0
- package/src/analysis/relations/references.ts +5 -0
- package/src/analysis/target/anchored-structural.ts +4 -1
- package/src/analysis/target/file-merge.ts +162 -0
- package/src/analysis/target/file-outline-omissions.ts +146 -0
- package/src/analysis/target/file-refinement.ts +7 -7
- package/src/analysis/target/file.ts +44 -156
- package/src/analysis/target/symbol.ts +5 -1
- package/src/analysis/target/types.ts +32 -6
- package/src/api.ts +1 -1
- package/src/app/app.ts +9 -3
- package/src/session/find-types.ts +8 -4
- package/src/session/find-workflow.ts +11 -16
- package/src/session/graph/collect.ts +2 -0
- package/src/session/graph-types.ts +3 -1
- package/src/session/graph-workflow.ts +5 -4
- package/src/session/input/health-refactor.ts +48 -34
- package/src/session/input/workflows.ts +45 -46
- package/src/session/inspect/file-point.ts +2 -2
- package/src/session/inspect-types.ts +1 -1
- package/src/session/inspect-workflow.ts +3 -3
- package/src/session/orientation/workspace-context.ts +3 -0
- package/src/session/orientation-workflow.ts +6 -3
- package/src/session/refactor-file-actions.ts +122 -0
- package/src/session/refactor-plan-pipeline.ts +152 -0
- package/src/session/refactor-plans.ts +18 -15
- package/src/session/refactor-types.ts +24 -12
- package/src/session/refactor-workflow.ts +70 -244
- package/src/session/session.ts +87 -12
- package/src/session/target-workflow.ts +23 -21
- package/src/tool/code_find/execute.ts +6 -7
- package/src/tool/code_find/spec.ts +9 -16
- package/src/tool/code_find/tui.ts +12 -6
- package/src/tool/code_graph/section.ts +4 -0
- package/src/tool/code_graph/spec.ts +6 -0
- package/src/tool/code_health/spec.ts +6 -0
- package/src/tool/code_health/structured-schema.ts +4 -4
- package/src/tool/code_health/structured.ts +15 -17
- package/src/tool/code_inspect/execute.ts +1 -1
- package/src/tool/code_inspect/markdown.ts +33 -6
- package/src/tool/code_inspect/result.ts +1 -1
- package/src/tool/code_inspect/spec.ts +14 -6
- package/src/tool/code_inspect/structured.ts +2 -2
- package/src/tool/code_inspect/tui.ts +2 -2
- package/src/tool/code_orientation/directory-navigation.ts +20 -31
- package/src/tool/code_orientation/spec.ts +8 -0
- package/src/tool/code_orientation/workspace-output.ts +40 -13
- package/src/tool/code_orientation/workspace-sections.ts +45 -2
- package/src/tool/code_refactor_apply/result.ts +2 -1
- package/src/tool/code_refactor_apply/spec.ts +7 -0
- package/src/tool/code_refactor_plan/execute.ts +0 -2
- package/src/tool/code_refactor_plan/result.ts +23 -13
- package/src/tool/code_refactor_plan/spec.ts +8 -2
- package/src/tool/code_refactor_plan/structured.ts +59 -12
- package/src/tool/code_refactor_plan/tui.ts +14 -17
- package/src/tool/code_resolve/guidance.ts +1 -1
- package/src/tool/code_resolve/markdown.ts +121 -34
- package/src/tool/code_resolve/result.ts +18 -15
- package/src/tool/code_resolve/spec.ts +6 -0
- package/src/tool/code_resolve/structured.ts +43 -10
- package/src/tool/namespace.ts +14 -0
- package/src/tool/refactor-markdown.ts +55 -15
- package/src/tool/register.ts +3 -0
- package/src/tool/result/model-budget.ts +2 -2
- package/src/tool/result/refactor-preview.ts +118 -0
- package/src/tool/result/refactor-unavailable.ts +16 -0
- package/src/tool/result/refactor.ts +8 -2
- package/src/tool/result/types.ts +13 -10
- package/src/tool/schemas.ts +63 -20
- package/src/tool/specs.ts +3 -0
- package/src/ui/status-overlay.ts +1 -1
- package/src/ui/tui/common.ts +10 -10
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Callee ranges for grammars whose call queries capture the whole call node.
|
|
2
|
+
|
|
3
|
+
import { tsPointToPublic } from "../coordinates.ts";
|
|
4
|
+
import type { SyntaxNodeLike } from "../syntax-node.ts";
|
|
5
|
+
import type { GrammarId, SourceRange } from "../types.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Return the callee range for a whole-call capture, so call-site ranges cover the
|
|
9
|
+
* callee expression in every grammar (`a.b` in `a.b(1)`), as JS/TS, Python, Go,
|
|
10
|
+
* and Rust queries capture directly. Returns `null` when the capture already is
|
|
11
|
+
* the callee or no narrower callee exists.
|
|
12
|
+
*/
|
|
13
|
+
export function calleeRangeForCallNode(
|
|
14
|
+
node: SyntaxNodeLike,
|
|
15
|
+
grammarId: GrammarId,
|
|
16
|
+
source: string,
|
|
17
|
+
): SourceRange | null {
|
|
18
|
+
const end = calleeEnd(node, grammarId);
|
|
19
|
+
if (!end) return null;
|
|
20
|
+
const start = tsPointToPublic(node.startPosition, source);
|
|
21
|
+
const publicEnd = tsPointToPublic(end, source);
|
|
22
|
+
return {
|
|
23
|
+
startLine: start.line,
|
|
24
|
+
startCharacter: start.character,
|
|
25
|
+
endLine: publicEnd.line,
|
|
26
|
+
endCharacter: publicEnd.character,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Find the syntax node for one query capture by walking up from the leaf at its start.
|
|
32
|
+
* Returns `null` when no ancestor has the capture's type and range.
|
|
33
|
+
*/
|
|
34
|
+
export function findCaptureNode(
|
|
35
|
+
root: SyntaxNodeLike & {
|
|
36
|
+
descendantForPosition(point: { row: number; column: number }): SyntaxNodeLike | null;
|
|
37
|
+
},
|
|
38
|
+
capture: { nodeType: string; range: SourceRange },
|
|
39
|
+
): SyntaxNodeLike | null {
|
|
40
|
+
const { range } = capture;
|
|
41
|
+
let node = root.descendantForPosition({
|
|
42
|
+
row: range.startLine - 1,
|
|
43
|
+
column: range.startCharacter - 1,
|
|
44
|
+
});
|
|
45
|
+
while (node) {
|
|
46
|
+
if (
|
|
47
|
+
node.type === capture.nodeType &&
|
|
48
|
+
node.startPosition.row === range.startLine - 1 &&
|
|
49
|
+
node.startPosition.column === range.startCharacter - 1 &&
|
|
50
|
+
node.endPosition.row === range.endLine - 1 &&
|
|
51
|
+
node.endPosition.column === range.endCharacter - 1
|
|
52
|
+
) {
|
|
53
|
+
return node;
|
|
54
|
+
}
|
|
55
|
+
node = node.parent;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function calleeEnd(
|
|
61
|
+
node: SyntaxNodeLike,
|
|
62
|
+
grammarId: GrammarId,
|
|
63
|
+
): { row: number; column: number } | null {
|
|
64
|
+
switch (grammarId) {
|
|
65
|
+
case "java":
|
|
66
|
+
return node.type === "method_invocation"
|
|
67
|
+
? (node.childForFieldName("name")?.endPosition ?? null)
|
|
68
|
+
: null;
|
|
69
|
+
case "kotlin":
|
|
70
|
+
return node.type === "call_expression" ? (kotlinCallee(node)?.endPosition ?? null) : null;
|
|
71
|
+
case "ruby":
|
|
72
|
+
return node.type === "call"
|
|
73
|
+
? ((node.childForFieldName("method") ?? node.childForFieldName("receiver"))?.endPosition ??
|
|
74
|
+
null)
|
|
75
|
+
: null;
|
|
76
|
+
default:
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Kotlin nests `f(x) { }` as an outer call (lambda-only suffix) wrapping `f(x)`.
|
|
83
|
+
* Treat both as one call so they share the callee `f`; `f(1)(2)` keeps `f(1)` as
|
|
84
|
+
* the outer callee because its suffix has value arguments.
|
|
85
|
+
*/
|
|
86
|
+
function kotlinCallee(node: SyntaxNodeLike): SyntaxNodeLike | null {
|
|
87
|
+
const callee = node.children[0];
|
|
88
|
+
if (!callee) return null;
|
|
89
|
+
const suffix = node.children.find((child) => child.type === "call_suffix");
|
|
90
|
+
const lambdaOnly =
|
|
91
|
+
suffix !== undefined && !suffix.children.some((child) => child.type === "value_arguments");
|
|
92
|
+
if (callee.type === "call_expression" && lambdaOnly) return kotlinCallee(callee);
|
|
93
|
+
return callee;
|
|
94
|
+
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
/** File-wide call-site extraction using per-grammar tree-sitter queries. */
|
|
2
2
|
|
|
3
3
|
import type { CodeRequestControl } from "@mrclrchtr/supi-code-runtime/api";
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
CallSiteMatch,
|
|
6
|
+
GrammarId,
|
|
7
|
+
QueryCapture,
|
|
8
|
+
SourceRange,
|
|
9
|
+
TreeSitterResult,
|
|
10
|
+
} from "../types.ts";
|
|
5
11
|
import { isTypeOnlyImportCapture } from "../worker/call-context.ts";
|
|
6
12
|
import { queryParsedFile, type TreeSitterRuntime } from "../worker/runtime.ts";
|
|
7
13
|
import { normalizeCallName } from "./call-name.ts";
|
|
14
|
+
import { calleeRangeForCallNode, findCaptureNode } from "./call-range.ts";
|
|
8
15
|
|
|
9
16
|
// ── Per-grammar call-site queries ─────────────────────────────────────
|
|
10
17
|
|
|
@@ -90,17 +97,19 @@ export async function extractCallSites(
|
|
|
90
97
|
const name = normalizeCallName(capture.text, grammarId, capture.nodeType);
|
|
91
98
|
if (name.length === 0) continue;
|
|
92
99
|
|
|
100
|
+
const range = callSiteRange(tree.rootNode, capture, grammarId, source);
|
|
101
|
+
|
|
93
102
|
// Collapse duplicate captures only when they identify the same source range.
|
|
94
|
-
const key = `${
|
|
103
|
+
const key = `${range.startLine}:${range.startCharacter}:${range.endLine}:${range.endCharacter}`;
|
|
95
104
|
if (seen.has(key)) continue;
|
|
96
105
|
seen.add(key);
|
|
97
106
|
|
|
98
107
|
matches.push({
|
|
99
108
|
name,
|
|
100
|
-
startLine:
|
|
101
|
-
startCharacter:
|
|
102
|
-
endLine:
|
|
103
|
-
endCharacter:
|
|
109
|
+
startLine: range.startLine,
|
|
110
|
+
startCharacter: range.startCharacter,
|
|
111
|
+
endLine: range.endLine,
|
|
112
|
+
endCharacter: range.endCharacter,
|
|
104
113
|
});
|
|
105
114
|
}
|
|
106
115
|
|
|
@@ -111,3 +120,14 @@ export async function extractCallSites(
|
|
|
111
120
|
tree.delete();
|
|
112
121
|
}
|
|
113
122
|
}
|
|
123
|
+
|
|
124
|
+
/** Narrow whole-call captures to their callee so ranges match the other grammars. */
|
|
125
|
+
function callSiteRange(
|
|
126
|
+
root: Parameters<typeof findCaptureNode>[0],
|
|
127
|
+
capture: QueryCapture,
|
|
128
|
+
grammarId: GrammarId,
|
|
129
|
+
source: string,
|
|
130
|
+
): SourceRange {
|
|
131
|
+
const node = findCaptureNode(root, capture);
|
|
132
|
+
return (node && calleeRangeForCallNode(node, grammarId, source)) ?? capture.range;
|
|
133
|
+
}
|
|
@@ -9,6 +9,7 @@ import type { GrammarId, SourceRange, TreeSitterResult } from "../types.ts";
|
|
|
9
9
|
import { isTypeOnlyImportCapture } from "../worker/call-context.ts";
|
|
10
10
|
import { queryParsedFile, type TreeSitterRuntime } from "../worker/runtime.ts";
|
|
11
11
|
import { normalizeCallName } from "./call-name.ts";
|
|
12
|
+
import { calleeRangeForCallNode } from "./call-range.ts";
|
|
12
13
|
import { createCalleeDisplayName, createSourceLineStarts } from "./callee-display-name.ts";
|
|
13
14
|
import { extractScopeName } from "./scope.ts";
|
|
14
15
|
|
|
@@ -387,11 +388,13 @@ function filterCalleeCaptures(
|
|
|
387
388
|
|
|
388
389
|
if (isTypeOnlyImportCapture(enclosingNode, capture, grammarId)) continue;
|
|
389
390
|
const name = normalizeCallName(capture.text, grammarId, capture.nodeType);
|
|
390
|
-
const
|
|
391
|
+
const syntaxNode = syntaxNodes.get(captureNodeKey(capture));
|
|
392
|
+
const range =
|
|
393
|
+
(syntaxNode && calleeRangeForCallNode(syntaxNode, grammarId, source)) ?? capture.range;
|
|
394
|
+
const rangeKey = sourceRangeKey(range);
|
|
391
395
|
if (name.length === 0 || seenRanges.has(rangeKey)) continue;
|
|
392
396
|
seenRanges.add(rangeKey);
|
|
393
397
|
|
|
394
|
-
const syntaxNode = syntaxNodes.get(captureNodeKey(capture));
|
|
395
398
|
const displayName = syntaxNode
|
|
396
399
|
? createCalleeDisplayName({
|
|
397
400
|
node: syntaxNode,
|
|
@@ -404,7 +407,7 @@ function filterCalleeCaptures(
|
|
|
404
407
|
callees.push({
|
|
405
408
|
name,
|
|
406
409
|
...(displayName === undefined ? {} : { displayName }),
|
|
407
|
-
range
|
|
410
|
+
range,
|
|
408
411
|
});
|
|
409
412
|
}
|
|
410
413
|
|
|
@@ -91,9 +91,11 @@ const DECLARATION_EXPORT_NODE_TYPES = new Set([
|
|
|
91
91
|
"type_alias_declaration",
|
|
92
92
|
"enum_declaration",
|
|
93
93
|
"lexical_declaration",
|
|
94
|
+
"variable_declaration",
|
|
94
95
|
"ambient_declaration",
|
|
95
96
|
"internal_module",
|
|
96
97
|
"module",
|
|
98
|
+
"import_alias",
|
|
97
99
|
]);
|
|
98
100
|
|
|
99
101
|
function extractDeclarationExport(
|
|
@@ -101,7 +103,7 @@ function extractDeclarationExport(
|
|
|
101
103
|
source: string,
|
|
102
104
|
exports: ExportRecord[],
|
|
103
105
|
): void {
|
|
104
|
-
if (decl.type === "lexical_declaration") {
|
|
106
|
+
if (decl.type === "lexical_declaration" || decl.type === "variable_declaration") {
|
|
105
107
|
extractLexicalDeclarationExports(decl, source, exports);
|
|
106
108
|
return;
|
|
107
109
|
}
|
|
@@ -111,7 +113,11 @@ function extractDeclarationExport(
|
|
|
111
113
|
return;
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
|
|
116
|
+
// `export import X = Y.Z` exports the alias `X`, which may name a value, type, or namespace.
|
|
117
|
+
const name =
|
|
118
|
+
decl.type === "import_alias"
|
|
119
|
+
? (decl.children.find((child) => child.type === "identifier")?.text ?? null)
|
|
120
|
+
: getDeclarationName(decl);
|
|
115
121
|
if (!name) return;
|
|
116
122
|
|
|
117
123
|
exports.push({
|
|
@@ -143,7 +149,7 @@ function extractAmbientDeclarationExport(
|
|
|
143
149
|
const nested = decl.children.find((child) => child.type !== "declare" && child.type !== ";");
|
|
144
150
|
if (!nested) return;
|
|
145
151
|
|
|
146
|
-
if (nested.type === "lexical_declaration") {
|
|
152
|
+
if (nested.type === "lexical_declaration" || nested.type === "variable_declaration") {
|
|
147
153
|
extractLexicalDeclarationExports(nested, source, exports);
|
|
148
154
|
return;
|
|
149
155
|
}
|
|
@@ -177,6 +183,8 @@ function exportKindForDeclaration(type: string): string {
|
|
|
177
183
|
case "internal_module":
|
|
178
184
|
case "module":
|
|
179
185
|
return "namespace";
|
|
186
|
+
case "import_alias":
|
|
187
|
+
return "alias";
|
|
180
188
|
default:
|
|
181
189
|
return type.replace(/_declaration$/, "");
|
|
182
190
|
}
|
|
@@ -217,8 +225,9 @@ function extractDefaultExport(node: SyntaxNodeLike, source: string, exports: Exp
|
|
|
217
225
|
});
|
|
218
226
|
}
|
|
219
227
|
|
|
228
|
+
/** Return the `from "module"` specifier; a string value such as `export default "x"` is not one. */
|
|
220
229
|
function findStringChild(node: SyntaxNodeLike): SyntaxNodeLike | undefined {
|
|
221
|
-
return node.
|
|
230
|
+
return node.childForFieldName("source") ?? undefined;
|
|
222
231
|
}
|
|
223
232
|
|
|
224
233
|
function extractReExport(
|
|
@@ -13,11 +13,7 @@ import {
|
|
|
13
13
|
type StructuralTimingEvent,
|
|
14
14
|
startStructuralTiming,
|
|
15
15
|
} from "../session/structural-timing.ts";
|
|
16
|
-
import {
|
|
17
|
-
collectSyntaxErrorRanges,
|
|
18
|
-
hasSyntaxErrors,
|
|
19
|
-
withSyntaxCompleteness,
|
|
20
|
-
} from "../syntax-errors.ts";
|
|
16
|
+
import { withSyntaxCompleteness } from "../syntax-errors.ts";
|
|
21
17
|
import type { GrammarId, QueryCapture, TreeSitterResult } from "../types.ts";
|
|
22
18
|
import {
|
|
23
19
|
ParsedFileReadError,
|
|
@@ -172,8 +168,6 @@ export class TreeSitterRuntime {
|
|
|
172
168
|
source: string;
|
|
173
169
|
resolvedPath: string;
|
|
174
170
|
grammarId: GrammarId;
|
|
175
|
-
hasSyntaxErrors: boolean;
|
|
176
|
-
errorRanges: ReturnType<typeof collectSyntaxErrorRanges>;
|
|
177
171
|
};
|
|
178
172
|
}
|
|
179
173
|
| Exclude<TreeSitterResult<never>, { kind: "success" | "partial" }>
|
|
@@ -249,8 +243,6 @@ export class TreeSitterRuntime {
|
|
|
249
243
|
source: parsed.source,
|
|
250
244
|
resolvedPath: parsed.resolvedPath,
|
|
251
245
|
grammarId: parsed.grammarId,
|
|
252
|
-
hasSyntaxErrors: hasSyntaxErrors(parsed.tree.rootNode),
|
|
253
|
-
errorRanges: collectSyntaxErrorRanges(parsed.tree.rootNode, parsed.source),
|
|
254
246
|
},
|
|
255
247
|
};
|
|
256
248
|
} catch (err: unknown) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-code-intelligence",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "LSP and AST navigation, search, diagnostics, and refactoring",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"ignore": "^7.0.12",
|
|
44
44
|
"smol-toml": "^1.9.1",
|
|
45
45
|
"yaml": "^2.9.0",
|
|
46
|
-
"@mrclrchtr/supi-code-runtime": "
|
|
47
|
-
"@mrclrchtr/supi-lsp": "
|
|
48
|
-
"@mrclrchtr/supi-tree-sitter": "
|
|
49
|
-
"@mrclrchtr/supi-core": "
|
|
46
|
+
"@mrclrchtr/supi-code-runtime": "12.0.0",
|
|
47
|
+
"@mrclrchtr/supi-lsp": "12.0.0",
|
|
48
|
+
"@mrclrchtr/supi-tree-sitter": "12.0.0",
|
|
49
|
+
"@mrclrchtr/supi-core": "12.0.0"
|
|
50
50
|
},
|
|
51
51
|
"bundledDependencies": [
|
|
52
52
|
"@mrclrchtr/supi-code-runtime",
|
|
@@ -79,20 +79,49 @@ export function formatProjectServerCompiler(
|
|
|
79
79
|
return `${selection.backend}: TypeScript ${selection.compilerVersion ?? "(unknown version)"} via ${selection.packageName}${selection.wrapperVersion ? ` (wrapper ${selection.wrapperVersion})` : ""}`;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Render operation support without hiding server limits or SuPi limits.
|
|
84
|
+
*
|
|
85
|
+
* A server that does not advertise an operation already rules it out, so its
|
|
86
|
+
* SuPi limitation is omitted. Operations with identical details share one
|
|
87
|
+
* entry, so a shared limitation reason appears once.
|
|
88
|
+
*/
|
|
83
89
|
export function formatProjectServerOperationSupport(
|
|
84
90
|
support: ServerOperationSupportMap | undefined,
|
|
85
91
|
): string | null {
|
|
86
92
|
if (!support) return null;
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
const operationsByDetail = new Map<string, string[]>();
|
|
94
|
+
for (const [operation, value] of Object.entries(support)) {
|
|
95
|
+
const detail = formatOperationSupportDetail(value);
|
|
96
|
+
if (!detail) continue;
|
|
97
|
+
const operations = operationsByDetail.get(detail);
|
|
98
|
+
if (operations) operations.push(operation);
|
|
99
|
+
else operationsByDetail.set(detail, [operation]);
|
|
100
|
+
}
|
|
101
|
+
const entries = Array.from(
|
|
102
|
+
operationsByDetail,
|
|
103
|
+
([detail, operations]) => `${operations.join(", ")}: ${detail}`,
|
|
104
|
+
);
|
|
105
|
+
// Details already use ";" and grouped operations use ",", so entries need a third separator.
|
|
106
|
+
return entries.length > 0 ? `operation support: ${entries.join(" | ")}` : null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type OperationSupport = NonNullable<ServerOperationSupportMap[keyof ServerOperationSupportMap]>;
|
|
110
|
+
|
|
111
|
+
/** Describe one operation's limits, or return null when nothing limits it. */
|
|
112
|
+
function formatOperationSupportDetail(value: OperationSupport): string | null {
|
|
113
|
+
if (value.server === "not-advertised") return "server unsupported";
|
|
114
|
+
const details: string[] = [];
|
|
115
|
+
if (value.server === "unknown") details.push("not negotiated");
|
|
116
|
+
if (value.supi === "limited") {
|
|
117
|
+
details.push(`SuPi limitation${value.reason ? `: ${value.reason}` : ""}`);
|
|
118
|
+
}
|
|
119
|
+
if (value.supi === "unsupported") details.push("SuPi unsupported");
|
|
120
|
+
if (value.kinds?.length) details.push(`kinds ${value.kinds.join(", ")}`);
|
|
121
|
+
if (value.anyKind) {
|
|
122
|
+
details.push(
|
|
123
|
+
value.kinds?.length ? "may return unlisted kinds" : "no kinds listed; may return any kind",
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return details.length > 0 ? details.join("; ") : null;
|
|
98
127
|
}
|
package/src/analysis/helpers.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import type { ConfidenceMode } from "@mrclrchtr/supi-code-runtime/api";
|
|
2
|
-
import type { ResolvedTargetData, ResolvedTargetGroupData } from "./target/types.ts";
|
|
3
2
|
|
|
4
3
|
interface FileLineRef {
|
|
5
4
|
file: string;
|
|
6
5
|
line: number;
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
export function isResolvedTargetGroup(
|
|
10
|
-
target: ResolvedTargetData | ResolvedTargetGroupData,
|
|
11
|
-
): target is ResolvedTargetGroupData {
|
|
12
|
-
return "targets" in target;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
8
|
export function highestConfidence(confidences: ConfidenceMode[]): ConfidenceMode {
|
|
16
9
|
if (confidences.includes("semantic")) return "semantic";
|
|
17
10
|
if (confidences.includes("structural")) return "structural";
|
|
@@ -18,6 +18,8 @@ interface ImplementationsResultBase {
|
|
|
18
18
|
/** Provider locations omitted because their URI or position was unusable. */
|
|
19
19
|
invalidLocationCount: number;
|
|
20
20
|
partialReason: RelationLocationPartialReason | null;
|
|
21
|
+
/** Provider explanation when the provider reported partial collection. */
|
|
22
|
+
partialMessage: string | null;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
/** An implementation lookup result with a reason on every unavailable outcome. */
|
|
@@ -43,6 +45,7 @@ export async function collectImplementations(
|
|
|
43
45
|
externalCount: 0,
|
|
44
46
|
invalidLocationCount: 0,
|
|
45
47
|
partialReason: null,
|
|
48
|
+
partialMessage: null,
|
|
46
49
|
confidence: "unavailable",
|
|
47
50
|
message: "No semantic implementations provider",
|
|
48
51
|
};
|
|
@@ -57,6 +60,7 @@ export async function collectImplementations(
|
|
|
57
60
|
externalCount: 0,
|
|
58
61
|
invalidLocationCount: 0,
|
|
59
62
|
partialReason: null,
|
|
63
|
+
partialMessage: null,
|
|
60
64
|
confidence: "unavailable",
|
|
61
65
|
message: result.reason,
|
|
62
66
|
};
|
|
@@ -79,6 +83,7 @@ export async function collectImplementations(
|
|
|
79
83
|
externalCount: normalized.external.length,
|
|
80
84
|
invalidLocationCount: normalized.invalidLocationCount,
|
|
81
85
|
partialReason: result.kind === "partial" ? "provider-limited" : normalized.partialReason,
|
|
86
|
+
partialMessage: result.kind === "partial" ? result.reason : null,
|
|
82
87
|
confidence: "semantic",
|
|
83
88
|
};
|
|
84
89
|
}
|
|
@@ -21,6 +21,8 @@ interface CallerEvidenceData {
|
|
|
21
21
|
/** Provider locations omitted because their URI or position was unusable. */
|
|
22
22
|
invalidLocationCount: number;
|
|
23
23
|
partialReason: RelationLocationPartialReason | null;
|
|
24
|
+
/** Provider explanation when the provider reported partial collection. */
|
|
25
|
+
partialMessage: string | null;
|
|
24
26
|
evidence: CallerEvidence;
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -47,6 +49,7 @@ export async function collectCallers(
|
|
|
47
49
|
externalCount: 0,
|
|
48
50
|
invalidLocationCount: 0,
|
|
49
51
|
partialReason: null,
|
|
52
|
+
partialMessage: null,
|
|
50
53
|
evidence: "semantic-references",
|
|
51
54
|
confidence: "unavailable",
|
|
52
55
|
message: "No semantic references provider",
|
|
@@ -62,6 +65,7 @@ export async function collectCallers(
|
|
|
62
65
|
externalCount: 0,
|
|
63
66
|
invalidLocationCount: 0,
|
|
64
67
|
partialReason: null,
|
|
68
|
+
partialMessage: null,
|
|
65
69
|
evidence: "semantic-references",
|
|
66
70
|
confidence: "unavailable",
|
|
67
71
|
message: result.reason,
|
|
@@ -83,6 +87,7 @@ export async function collectCallers(
|
|
|
83
87
|
externalCount: normalized.external.length,
|
|
84
88
|
invalidLocationCount: normalized.invalidLocationCount,
|
|
85
89
|
partialReason: result.kind === "partial" ? "provider-limited" : normalized.partialReason,
|
|
90
|
+
partialMessage: result.kind === "partial" ? result.reason : null,
|
|
86
91
|
evidence: "semantic-references",
|
|
87
92
|
confidence: "semantic",
|
|
88
93
|
};
|
|
@@ -30,6 +30,9 @@ const DECLARATION_NODE_TYPES = new Set([
|
|
|
30
30
|
"export_statement",
|
|
31
31
|
]);
|
|
32
32
|
|
|
33
|
+
/** Tree-sitter name tokens; Kotlin names its identifiers `simple_identifier`. */
|
|
34
|
+
const IDENTIFIER_NODE_TYPES = new Set(["identifier", "simple_identifier"]);
|
|
35
|
+
|
|
33
36
|
/** Tree-sitter nodes that cannot identify a declaration name. */
|
|
34
37
|
const NON_SYMBOL_NODE_TYPES = new Set([
|
|
35
38
|
"comment",
|
|
@@ -94,7 +97,7 @@ export async function resolveFromStructural(
|
|
|
94
97
|
),
|
|
95
98
|
};
|
|
96
99
|
}
|
|
97
|
-
if (node.type
|
|
100
|
+
if (!IDENTIFIER_NODE_TYPES.has(node.type)) {
|
|
98
101
|
return {
|
|
99
102
|
kind: "error",
|
|
100
103
|
message: coordinateNotOnSymbolMessage(file, requested, node.type),
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File outline merge: pair the language server's and the syntax parser's
|
|
3
|
+
* observations of one declaration, then order the outline.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { DiscoveredTargetData } from "./file.ts";
|
|
7
|
+
import {
|
|
8
|
+
reconcileContainer,
|
|
9
|
+
reconcileLevel,
|
|
10
|
+
refineLatexSectionNameAnchor,
|
|
11
|
+
} from "./file-refinement.ts";
|
|
12
|
+
import {
|
|
13
|
+
canonicalDeclarationKind,
|
|
14
|
+
canonicalFileDeclarationKind,
|
|
15
|
+
canonicalFileDeclarationName,
|
|
16
|
+
declarationOccurrencesFor,
|
|
17
|
+
} from "./identity.ts";
|
|
18
|
+
import type { ResolvedTargetData } from "./types.ts";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Merge duplicate provider observations without collapsing repeated declarations.
|
|
22
|
+
* Semantic facts win a matched pair while retaining both provider sources.
|
|
23
|
+
*/
|
|
24
|
+
export function mergeDiscoveries(
|
|
25
|
+
structural: readonly DiscoveredTargetData[],
|
|
26
|
+
semantic: readonly DiscoveredTargetData[],
|
|
27
|
+
): DiscoveredTargetData[] {
|
|
28
|
+
const unmatchedSemantic = new Set(semantic.map((_target, index) => index));
|
|
29
|
+
const mergedStructural = structural.flatMap((structuralTarget) => {
|
|
30
|
+
const semanticIndex = findSemanticMatch(structuralTarget, semantic, unmatchedSemantic);
|
|
31
|
+
if (semanticIndex === null) return [structuralTarget];
|
|
32
|
+
unmatchedSemantic.delete(semanticIndex);
|
|
33
|
+
const semanticTarget = semantic[semanticIndex];
|
|
34
|
+
const refinedSemantic = refineLatexSectionNameAnchor(semanticTarget, structuralTarget);
|
|
35
|
+
return [
|
|
36
|
+
{
|
|
37
|
+
...refinedSemantic,
|
|
38
|
+
provenance: ["semantic", "structural"] as const,
|
|
39
|
+
nativeKind: structuralTarget.nativeKind ?? semanticTarget.nativeKind,
|
|
40
|
+
container: reconcileContainer(semanticTarget, structuralTarget),
|
|
41
|
+
level: reconcileLevel(semanticTarget.level, structuralTarget.level),
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
});
|
|
45
|
+
const semanticOnly = semantic.filter((_target, index) => unmatchedSemantic.has(index));
|
|
46
|
+
const sourceOrdered = [...mergedStructural, ...semanticOnly].sort(compareDeclarations);
|
|
47
|
+
const identified = assignDeclarationOccurrences(sourceOrdered);
|
|
48
|
+
return identified.sort(compareFileOrientationDeclarations);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function findSemanticMatch(
|
|
52
|
+
structural: DiscoveredTargetData,
|
|
53
|
+
semantic: readonly DiscoveredTargetData[],
|
|
54
|
+
unmatched: ReadonlySet<number>,
|
|
55
|
+
): number | null {
|
|
56
|
+
const matches = semantic
|
|
57
|
+
.map((target, index) => ({ target, index }))
|
|
58
|
+
.filter(({ target, index }) => unmatched.has(index) && sameDeclaration(target, structural))
|
|
59
|
+
.sort(
|
|
60
|
+
(left, right) =>
|
|
61
|
+
Math.abs(left.target.declarationAnchor.character - structural.declarationAnchor.character) -
|
|
62
|
+
Math.abs(
|
|
63
|
+
right.target.declarationAnchor.character - structural.declarationAnchor.character,
|
|
64
|
+
) ||
|
|
65
|
+
left.target.declarationAnchor.character - right.target.declarationAnchor.character ||
|
|
66
|
+
compareDeclarations(left.target, right.target) ||
|
|
67
|
+
(left.target.container ?? "").localeCompare(right.target.container ?? "") ||
|
|
68
|
+
left.target.level.localeCompare(right.target.level) ||
|
|
69
|
+
left.index - right.index,
|
|
70
|
+
);
|
|
71
|
+
return matches[0]?.index ?? null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function sameDeclaration(
|
|
75
|
+
semantic: DiscoveredTargetData,
|
|
76
|
+
structural: DiscoveredTargetData,
|
|
77
|
+
): boolean {
|
|
78
|
+
return (
|
|
79
|
+
canonicalFileDeclarationName(semantic.file, semantic.kind, semantic.name) ===
|
|
80
|
+
canonicalFileDeclarationName(structural.file, structural.kind, structural.name) &&
|
|
81
|
+
compatibleContainerEvidence(semantic, structural) &&
|
|
82
|
+
sameDeclarationLine(semantic, structural) &&
|
|
83
|
+
declarationIdentityKind(semantic) === declarationIdentityKind(structural)
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Both providers start the declaration on one line, or the language server's
|
|
89
|
+
* range also covers leading decorators (Python, for example) while its name
|
|
90
|
+
* sits on the line where the syntax parser starts the declaration.
|
|
91
|
+
*/
|
|
92
|
+
function sameDeclarationLine(
|
|
93
|
+
semantic: DiscoveredTargetData,
|
|
94
|
+
structural: DiscoveredTargetData,
|
|
95
|
+
): boolean {
|
|
96
|
+
const line = structural.declarationAnchor.line;
|
|
97
|
+
return (
|
|
98
|
+
semantic.declarationAnchor.line === line ||
|
|
99
|
+
(semantic.anchorKind === "name" &&
|
|
100
|
+
semantic.declarationAnchor.line < line &&
|
|
101
|
+
semantic.displayLine === line)
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Container conflicts match only when both providers report the exact declaration anchor. */
|
|
106
|
+
function compatibleContainerEvidence(
|
|
107
|
+
left: DiscoveredTargetData,
|
|
108
|
+
right: DiscoveredTargetData,
|
|
109
|
+
): boolean {
|
|
110
|
+
return (
|
|
111
|
+
left.container === right.container ||
|
|
112
|
+
left.declarationAnchor.character === right.declarationAnchor.character
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function assignDeclarationOccurrences(
|
|
117
|
+
targets: readonly DiscoveredTargetData[],
|
|
118
|
+
): DiscoveredTargetData[] {
|
|
119
|
+
const candidates = targets.map((target) => ({
|
|
120
|
+
name: target.name,
|
|
121
|
+
identityKind: declarationIdentityKind(target),
|
|
122
|
+
declarationAnchor: target.declarationAnchor,
|
|
123
|
+
nameAnchor: { line: target.displayLine, character: target.displayCharacter },
|
|
124
|
+
container: target.container,
|
|
125
|
+
}));
|
|
126
|
+
const occurrences = declarationOccurrencesFor(candidates);
|
|
127
|
+
return targets.map((target, index) => {
|
|
128
|
+
const declarationOccurrence = occurrences[index];
|
|
129
|
+
if (declarationOccurrence === undefined) {
|
|
130
|
+
throw new Error("The declaration occurrence was not assigned.");
|
|
131
|
+
}
|
|
132
|
+
return { ...target, declarationOccurrence };
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function declarationIdentityKind(target: ResolvedTargetData): string {
|
|
137
|
+
return (
|
|
138
|
+
target.identityKind ??
|
|
139
|
+
canonicalFileDeclarationKind(target.file, target.kind, target.name) ??
|
|
140
|
+
canonicalDeclarationKind(target.kind)
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function compareFileOrientationDeclarations(
|
|
145
|
+
left: DiscoveredTargetData,
|
|
146
|
+
right: DiscoveredTargetData,
|
|
147
|
+
): number {
|
|
148
|
+
return topLevelRank(left) - topLevelRank(right) || compareDeclarations(left, right);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function topLevelRank(target: DiscoveredTargetData): number {
|
|
152
|
+
return target.level === "top-level" ? 0 : 1;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function compareDeclarations(left: ResolvedTargetData, right: ResolvedTargetData): number {
|
|
156
|
+
return (
|
|
157
|
+
left.displayLine - right.displayLine ||
|
|
158
|
+
left.displayCharacter - right.displayCharacter ||
|
|
159
|
+
(left.name ?? "").localeCompare(right.name ?? "") ||
|
|
160
|
+
(left.kind ?? "").localeCompare(right.kind ?? "")
|
|
161
|
+
);
|
|
162
|
+
}
|