@mrclrchtr/supi-code-intelligence 11.3.0 → 11.4.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +3 -3
  3. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +2 -1
  5. package/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  6. package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -5
  7. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  8. package/node_modules/@mrclrchtr/supi-lsp/README.md +1 -1
  9. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  10. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +2 -1
  11. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  12. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -5
  13. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  14. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/range.js +2 -2
  15. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/constants.js +30 -0
  16. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/package.json +1 -1
  18. package/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
  19. package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +10 -0
  20. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-typescript-coverage.ts +118 -0
  21. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +64 -2
  22. package/node_modules/@mrclrchtr/supi-lsp/src/manager/typescript-file-local.ts +87 -0
  23. package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +22 -17
  24. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +49 -4
  25. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +1 -1
  26. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  27. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +2 -1
  28. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/declaration-level.ts +34 -0
  29. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -5
  30. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  31. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  32. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm +0 -0
  33. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +5 -1
  34. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm +0 -0
  35. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +5 -1
  36. package/package.json +5 -5
  37. package/src/analysis/helpers.ts +0 -7
  38. package/src/analysis/relations/implementations.ts +5 -0
  39. package/src/analysis/relations/references.ts +5 -0
  40. package/src/analysis/target/file-merge.ts +162 -0
  41. package/src/analysis/target/file-outline-omissions.ts +146 -0
  42. package/src/analysis/target/file-refinement.ts +7 -7
  43. package/src/analysis/target/file.ts +44 -156
  44. package/src/analysis/target/symbol.ts +5 -1
  45. package/src/analysis/target/types.ts +32 -6
  46. package/src/api.ts +1 -1
  47. package/src/app/app.ts +9 -3
  48. package/src/session/graph/collect.ts +2 -0
  49. package/src/session/graph-types.ts +3 -1
  50. package/src/session/graph-workflow.ts +5 -4
  51. package/src/session/orientation/workspace-context.ts +3 -0
  52. package/src/session/orientation-workflow.ts +6 -3
  53. package/src/session/refactor-workflow.ts +3 -2
  54. package/src/session/session.ts +87 -12
  55. package/src/session/target-workflow.ts +23 -21
  56. package/src/tool/code_graph/section.ts +4 -0
  57. package/src/tool/code_orientation/directory-navigation.ts +20 -31
  58. package/src/tool/code_orientation/workspace-output.ts +40 -13
  59. package/src/tool/code_orientation/workspace-sections.ts +45 -2
  60. package/src/tool/code_resolve/guidance.ts +1 -1
  61. package/src/tool/code_resolve/markdown.ts +121 -34
  62. package/src/tool/code_resolve/result.ts +18 -15
  63. package/src/tool/code_resolve/structured.ts +43 -10
  64. package/src/tool/result/model-budget.ts +2 -2
  65. package/src/tool/result/types.ts +13 -10
  66. package/src/ui/tui/common.ts +10 -10
@@ -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
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * File outline omissions: which discovered declarations an outline leaves out
3
+ * and how they are counted. Imported names, export-list names, and
4
+ * `export … from` statements bind or forward names the file does not declare;
5
+ * local declarations live inside function bodies.
6
+ */
7
+
8
+ import type {
9
+ CodeRequestControl,
10
+ StructuralProvider as StructuralSubstrate,
11
+ } from "@mrclrchtr/supi-code-runtime/api";
12
+ import { isCodeRequestInterruption } from "@mrclrchtr/supi-code-runtime/api";
13
+ import type { DiscoveredTargetData } from "./file.ts";
14
+ import type { FileOutlineNameSpan, FileOutlineNotListed, ResolvedTargetData } from "./types.ts";
15
+
16
+ interface SourceSpan {
17
+ readonly startLine: number;
18
+ readonly startCharacter: number;
19
+ readonly endLine: number;
20
+ readonly endCharacter: number;
21
+ }
22
+
23
+ /** Statements that bind names the file does not declare itself. */
24
+ interface BindingRanges {
25
+ readonly imports: readonly SourceSpan[];
26
+ /** Specifiers of `export { … }` lists, with or without `from`. */
27
+ readonly exportLists: readonly SourceSpan[];
28
+ /**
29
+ * Specifiers of `export { … } from`, and whole `export * from` or
30
+ * `export * as name from` statements, which have no outline row.
31
+ */
32
+ readonly reExports: readonly SourceSpan[];
33
+ }
34
+
35
+ /** Syntax ranges of import statements and export-list specifiers, or null when unknown. */
36
+ export async function collectBindingRanges(
37
+ file: string,
38
+ structural: StructuralSubstrate | undefined,
39
+ control?: CodeRequestControl,
40
+ ): Promise<BindingRanges | null> {
41
+ if (!structural) return null;
42
+ try {
43
+ const [imports, exports] = await Promise.all([
44
+ structural.imports(file, control),
45
+ structural.exports(file, control),
46
+ ]);
47
+ const exportData = exports.kind === "success" || exports.kind === "partial" ? exports.data : [];
48
+ return {
49
+ imports: imports.kind === "success" || imports.kind === "partial" ? imports.data : [],
50
+ exportLists: exportData.filter(
51
+ (entry) => entry.kind === "export" || entry.kind === "re-export",
52
+ ),
53
+ reExports: exportData.filter((entry) => entry.kind === "re-export"),
54
+ };
55
+ } catch (error) {
56
+ if (isCodeRequestInterruption(error, control)) throw error;
57
+ return null;
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Split discovered declarations into the listed outline and counted omissions.
63
+ *
64
+ * Local declarations are omitted by level. A name only the language server
65
+ * reported inside an import statement or an export list is a binding, not a
66
+ * declaration of this file. A syntax-parser export statement that contains a
67
+ * re-export only forwards names; an own `export { … }` list stays listed.
68
+ * Without binding ranges such entries stay listed rather than being guessed.
69
+ */
70
+ export function partitionOutline(
71
+ targets: readonly DiscoveredTargetData[],
72
+ ranges: BindingRanges | null,
73
+ ): { targets: DiscoveredTargetData[]; notListed: FileOutlineNotListed } {
74
+ const listed: DiscoveredTargetData[] = [];
75
+ const lines = { imported: [] as number[], exportList: [] as number[], reExport: [] as number[] };
76
+ const reExportRows: SourceSpan[] = [];
77
+ let localDeclarations = 0;
78
+ for (const target of targets) {
79
+ const omission = classifyOmission(target, ranges);
80
+ if (omission === "local") localDeclarations++;
81
+ else if (omission === null) listed.push(target);
82
+ else {
83
+ lines[omission].push(target.displayLine);
84
+ if (omission === "reExport") reExportRows.push(statementSpan(target));
85
+ }
86
+ }
87
+ // `export *` statements have no outline row; each record is one statement.
88
+ for (const record of ranges?.reExports ?? []) {
89
+ if (!reExportRows.some((row) => containsLines(row, record))) {
90
+ lines.reExport.push(record.startLine);
91
+ }
92
+ }
93
+ return {
94
+ targets: listed,
95
+ notListed: {
96
+ importedNames: nameSpan(lines.imported),
97
+ exportListNames: nameSpan(lines.exportList),
98
+ reExportStatements: nameSpan(lines.reExport),
99
+ localDeclarations,
100
+ },
101
+ };
102
+ }
103
+
104
+ /** Why the outline leaves `target` out, or null when it is listed. */
105
+ function classifyOmission(
106
+ target: DiscoveredTargetData,
107
+ ranges: BindingRanges | null,
108
+ ): "local" | "imported" | "exportList" | "reExport" | null {
109
+ if (target.level === "local") return "local";
110
+ if (!ranges) return null;
111
+ if (isReExportStatement(target, ranges)) return "reExport";
112
+ if (target.provenance.includes("structural")) return null;
113
+ if (ranges.imports.some((range) => containsTarget(range, target))) return "imported";
114
+ if (ranges.exportLists.some((range) => containsTarget(range, target))) return "exportList";
115
+ return null;
116
+ }
117
+
118
+ /** A syntax-parser `export` statement row whose lines hold a re-export. */
119
+ function isReExportStatement(target: DiscoveredTargetData, ranges: BindingRanges): boolean {
120
+ if (target.kind !== "export" || target.provenance.includes("semantic")) return false;
121
+ const row = statementSpan(target);
122
+ return ranges.reExports.some((range) => containsLines(row, range));
123
+ }
124
+
125
+ function statementSpan(target: DiscoveredTargetData): SourceSpan {
126
+ const startLine = target.declarationAnchor.line;
127
+ return { startLine, startCharacter: 1, endLine: target.endLine ?? startLine, endCharacter: 1 };
128
+ }
129
+
130
+ function containsLines(outer: SourceSpan, inner: SourceSpan): boolean {
131
+ return inner.startLine >= outer.startLine && inner.endLine <= outer.endLine;
132
+ }
133
+
134
+ function containsTarget(range: SourceSpan, target: ResolvedTargetData): boolean {
135
+ const { displayLine: line, displayCharacter: character } = target;
136
+ const afterStart =
137
+ line > range.startLine || (line === range.startLine && character >= range.startCharacter);
138
+ const beforeEnd =
139
+ line < range.endLine || (line === range.endLine && character <= range.endCharacter);
140
+ return afterStart && beforeEnd;
141
+ }
142
+
143
+ function nameSpan(lines: readonly number[]): FileOutlineNameSpan | null {
144
+ if (lines.length === 0) return null;
145
+ return { count: lines.length, startLine: Math.min(...lines), endLine: Math.max(...lines) };
146
+ }
@@ -24,11 +24,11 @@ export function refineLatexSectionNameAnchor(
24
24
  };
25
25
  }
26
26
 
27
- /** Prefer known hierarchy, but keep conflicts unknown. */
28
- export function reconcileNesting(
29
- semantic: DiscoveredTargetData["nesting"],
30
- structural: DiscoveredTargetData["nesting"],
31
- ): DiscoveredTargetData["nesting"] {
27
+ /** Prefer a known declaration level, but keep conflicts unknown. */
28
+ export function reconcileLevel(
29
+ semantic: DiscoveredTargetData["level"],
30
+ structural: DiscoveredTargetData["level"],
31
+ ): DiscoveredTargetData["level"] {
32
32
  if (semantic === structural) return semantic;
33
33
  if (semantic === "unknown") return structural;
34
34
  if (structural === "unknown") return semantic;
@@ -41,10 +41,10 @@ export function reconcileContainer(
41
41
  structural: DiscoveredTargetData,
42
42
  ): string | null {
43
43
  if (semantic.container === structural.container) return semantic.container;
44
- if (semantic.nesting === "unknown" && semantic.container === null) {
44
+ if (semantic.level === "unknown" && semantic.container === null) {
45
45
  return structural.container;
46
46
  }
47
- if (structural.nesting === "unknown" && structural.container === null) {
47
+ if (structural.level === "unknown" && structural.container === null) {
48
48
  return semantic.container;
49
49
  }
50
50
  return null;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * File target discovery — collects every evidence-backed declaration in one
2
+ * File outline discovery — collects every evidence-backed declaration in one
3
3
  * file after the Target workflow has established semantic readiness.
4
4
  *
5
5
  * Semantic and structural facts are merged. Semantic facts win duplicate
@@ -11,7 +11,8 @@ import * as fs from "node:fs";
11
11
  import * as path from "node:path";
12
12
  import {
13
13
  type CodeRequestControl,
14
- type DeclarationNesting,
14
+ childDeclarationLevel,
15
+ type DeclarationLevel,
15
16
  type DocumentCodeSymbol,
16
17
  isCodeRequestInterruption,
17
18
  type OutlineData,
@@ -21,19 +22,14 @@ import {
21
22
  import type { AnchorKind } from "../../session/target-store.ts";
22
23
  import { normalizePath } from "../search/paths.ts";
23
24
  import { mergeDiscoveryPartial, type TargetDiscoveryResult } from "./discovery.ts";
24
- import {
25
- reconcileContainer,
26
- reconcileNesting,
27
- refineLatexSectionNameAnchor,
28
- } from "./file-refinement.ts";
25
+ import { mergeDiscoveries } from "./file-merge.ts";
26
+ import { collectBindingRanges, partitionOutline } from "./file-outline-omissions.ts";
29
27
  import {
30
28
  canonicalDeclarationKind,
31
29
  canonicalFileDeclarationKind,
32
- canonicalFileDeclarationName,
33
- declarationOccurrencesFor,
34
30
  refineTypeAliasIdentity,
35
31
  } from "./identity.ts";
36
- import type { ResolvedTargetData, ResolvedTargetGroupData } from "./types.ts";
32
+ import type { FileOutlineData, ResolvedTargetData } from "./types.ts";
37
33
 
38
34
  const BINARY_EXTENSIONS = new Set([
39
35
  ".png",
@@ -65,8 +61,10 @@ const BINARY_EXTENSIONS = new Set([
65
61
  type DiscoveryResult = TargetDiscoveryResult<DiscoveredTargetData>;
66
62
 
67
63
  export interface DiscoveredTargetData extends ResolvedTargetData {
68
- /** Provider-backed hierarchy used only for file-result presentation ranking. */
69
- readonly nesting: DeclarationNesting;
64
+ /** Provider-backed position in the file, used only for outline ranking. */
65
+ readonly level: DeclarationLevel;
66
+ /** 1-based last line of a syntax-parser declaration, used to classify export statements. */
67
+ readonly endLine?: number;
70
68
  }
71
69
 
72
70
  /** Validated file-discovery input with its normalized absolute path. */
@@ -83,8 +81,8 @@ export function validateFileTargetDiscovery(file: string, cwd: string): FileDisc
83
81
  : { kind: "valid", file: resolvedFile };
84
82
  }
85
83
 
86
- /** Discover a Target group for one file without rendering or registering handles. */
87
- export async function resolveFileTargetGroup(
84
+ /** Discover the File outline of one file without rendering or registering handles. */
85
+ export async function resolveFileOutline(
88
86
  file: string,
89
87
  cwd: string,
90
88
  deps: {
@@ -93,7 +91,7 @@ export async function resolveFileTargetGroup(
93
91
  } = {},
94
92
  control?: CodeRequestControl,
95
93
  ): Promise<
96
- | { kind: "resolved"; group: ResolvedTargetGroupData }
94
+ | { kind: "resolved"; outline: FileOutlineData }
97
95
  | { kind: "invalid-input"; message: string }
98
96
  | { kind: "unavailable"; message: string }
99
97
  > {
@@ -101,9 +99,10 @@ export async function resolveFileTargetGroup(
101
99
  if (validation.kind === "invalid-input") return validation;
102
100
  const resolvedFile = validation.file;
103
101
 
104
- const [semantic, structural] = await Promise.all([
102
+ const [semantic, structural, bindingRanges] = await Promise.all([
105
103
  discoverSemantic(resolvedFile, deps.semantic, deps.structural, control),
106
104
  discoverStructural(resolvedFile, deps.structural, control),
105
+ collectBindingRanges(resolvedFile, deps.structural, control),
107
106
  ]);
108
107
  if (!semantic.available && !structural.available) {
109
108
  const displayFile = path.relative(cwd, resolvedFile) || file;
@@ -113,30 +112,34 @@ export async function resolveFileTargetGroup(
113
112
  };
114
113
  }
115
114
 
116
- const targets = mergeDiscoveries(structural.targets, semantic.targets);
117
- const unknownNestingCount = targets.filter((target) => target.nesting === "unknown").length;
115
+ const { targets, notListed } = partitionOutline(
116
+ mergeDiscoveries(structural.targets, semantic.targets),
117
+ bindingRanges,
118
+ );
119
+ const unknownLevelCount = targets.filter((target) => target.level === "unknown").length;
118
120
  const discoveryProvenance = [
119
121
  ...(semantic.available ? (["semantic"] as const) : []),
120
122
  ...(structural.available ? (["structural"] as const) : []),
121
123
  ];
122
124
  return {
123
125
  kind: "resolved",
124
- group: {
126
+ outline: {
125
127
  file: resolvedFile,
126
128
  displayName: path.relative(cwd, resolvedFile) || resolvedFile,
127
129
  targets,
128
130
  discoveryProvenance,
129
- confidence: targetGroupConfidence(targets, discoveryProvenance),
130
- unknownNestingCount,
131
+ confidence: fileOutlineConfidence(targets, discoveryProvenance),
132
+ unknownLevelCount,
131
133
  ...mergeDiscoveryPartial(semantic, structural),
134
+ notListed,
132
135
  },
133
136
  };
134
137
  }
135
138
 
136
- function targetGroupConfidence(
139
+ function fileOutlineConfidence(
137
140
  targets: readonly ResolvedTargetData[],
138
- discoveryProvenance: ResolvedTargetGroupData["discoveryProvenance"],
139
- ): ResolvedTargetGroupData["confidence"] {
141
+ discoveryProvenance: FileOutlineData["discoveryProvenance"],
142
+ ): FileOutlineData["confidence"] {
140
143
  if (targets.length === 0) {
141
144
  return discoveryProvenance.includes("semantic") ? "semantic" : "structural";
142
145
  }
@@ -173,7 +176,7 @@ async function discoverSemantic(
173
176
  result.data.map(async (symbol) => {
174
177
  const target = targetFromSymbol(file, symbol);
175
178
  const refined = await refineTypeAliasIdentity(target, structural, control);
176
- return { ...refined, nesting: target.nesting };
179
+ return { ...refined, level: target.level };
177
180
  }),
178
181
  ),
179
182
  ...(result.kind === "partial" ? { partial: { reason: result.reason, errorRanges: [] } } : {}),
@@ -201,13 +204,15 @@ function targetFromSymbol(file: string, symbol: DocumentCodeSymbol): DiscoveredT
201
204
  provenance: ["semantic"],
202
205
  anchorKind: (symbol.nameAnchor ? "name" : "declaration") as AnchorKind,
203
206
  container: symbol.container ?? null,
204
- nesting: normalizeNesting(symbol.nesting),
207
+ level: normalizeLevel(symbol.level),
205
208
  };
206
209
  }
207
210
 
208
211
  /** Normalize process-global or legacy provider observations at the discovery seam. */
209
- function normalizeNesting(value: unknown): DeclarationNesting {
210
- if (value === "top-level" || value === "nested" || value === "unknown") return value;
212
+ function normalizeLevel(value: unknown): DeclarationLevel {
213
+ if (value === "top-level" || value === "member" || value === "local" || value === "unknown") {
214
+ return value;
215
+ }
211
216
  return "unknown";
212
217
  }
213
218
 
@@ -238,10 +243,14 @@ async function discoverStructural(
238
243
  function flattenOutline(
239
244
  file: string,
240
245
  items: readonly OutlineData[],
241
- container: string | null = null,
242
- nesting: DeclarationNesting = "top-level",
246
+ parent: {
247
+ readonly name: string;
248
+ readonly kind: string;
249
+ readonly level: DeclarationLevel;
250
+ } | null = null,
243
251
  ): DiscoveredTargetData[] {
244
252
  return items.flatMap((item) => {
253
+ const level: DeclarationLevel = parent ? childDeclarationLevel(parent, item.kind) : "top-level";
245
254
  const nameAnchor = item.nameAnchor ?? {
246
255
  line: item.startLine,
247
256
  character: item.startCharacter,
@@ -252,6 +261,7 @@ function flattenOutline(
252
261
  displayLine: nameAnchor.line,
253
262
  displayCharacter: nameAnchor.character,
254
263
  declarationAnchor: { line: item.startLine, character: item.startCharacter },
264
+ endLine: item.endLine,
255
265
  declarationOccurrence: 0,
256
266
  name: item.name,
257
267
  kind: item.kind,
@@ -262,132 +272,10 @@ function flattenOutline(
262
272
  confidence: "structural",
263
273
  provenance: ["structural"],
264
274
  anchorKind: item.nameAnchor ? "name" : "declaration",
265
- container,
266
- nesting,
275
+ container: parent?.name ?? null,
276
+ level,
267
277
  };
268
- return [target, ...flattenOutline(file, item.children ?? [], item.name, "nested")];
269
- });
270
- }
271
-
272
- /**
273
- * Merge duplicate provider observations without collapsing repeated declarations.
274
- * Semantic facts win a matched pair while retaining both provider sources.
275
- */
276
- function mergeDiscoveries(
277
- structural: readonly DiscoveredTargetData[],
278
- semantic: readonly DiscoveredTargetData[],
279
- ): DiscoveredTargetData[] {
280
- const unmatchedSemantic = new Set(semantic.map((_target, index) => index));
281
- const mergedStructural = structural.flatMap((structuralTarget) => {
282
- const semanticIndex = findSemanticMatch(structuralTarget, semantic, unmatchedSemantic);
283
- if (semanticIndex === null) return [structuralTarget];
284
- unmatchedSemantic.delete(semanticIndex);
285
- const semanticTarget = semantic[semanticIndex];
286
- const refinedSemantic = refineLatexSectionNameAnchor(semanticTarget, structuralTarget);
287
- return [
288
- {
289
- ...refinedSemantic,
290
- provenance: ["semantic", "structural"] as const,
291
- nativeKind: structuralTarget.nativeKind ?? semanticTarget.nativeKind,
292
- container: reconcileContainer(semanticTarget, structuralTarget),
293
- nesting: reconcileNesting(semanticTarget.nesting, structuralTarget.nesting),
294
- },
295
- ];
296
- });
297
- const semanticOnly = semantic.filter((_target, index) => unmatchedSemantic.has(index));
298
- const sourceOrdered = [...mergedStructural, ...semanticOnly].sort(compareDeclarations);
299
- const identified = assignDeclarationOccurrences(sourceOrdered);
300
- return identified.sort(compareFileOrientationDeclarations);
301
- }
302
-
303
- function findSemanticMatch(
304
- structural: DiscoveredTargetData,
305
- semantic: readonly DiscoveredTargetData[],
306
- unmatched: ReadonlySet<number>,
307
- ): number | null {
308
- const matches = semantic
309
- .map((target, index) => ({ target, index }))
310
- .filter(({ target, index }) => unmatched.has(index) && sameDeclaration(target, structural))
311
- .sort(
312
- (left, right) =>
313
- Math.abs(left.target.declarationAnchor.character - structural.declarationAnchor.character) -
314
- Math.abs(
315
- right.target.declarationAnchor.character - structural.declarationAnchor.character,
316
- ) ||
317
- left.target.declarationAnchor.character - right.target.declarationAnchor.character ||
318
- compareDeclarations(left.target, right.target) ||
319
- (left.target.container ?? "").localeCompare(right.target.container ?? "") ||
320
- left.target.nesting.localeCompare(right.target.nesting) ||
321
- left.index - right.index,
322
- );
323
- return matches[0]?.index ?? null;
324
- }
325
-
326
- function sameDeclaration(left: DiscoveredTargetData, right: DiscoveredTargetData): boolean {
327
- return (
328
- canonicalFileDeclarationName(left.file, left.kind, left.name) ===
329
- canonicalFileDeclarationName(right.file, right.kind, right.name) &&
330
- compatibleContainerEvidence(left, right) &&
331
- left.declarationAnchor.line === right.declarationAnchor.line &&
332
- declarationIdentityKind(left) === declarationIdentityKind(right)
333
- );
334
- }
335
-
336
- /** Container conflicts match only when both providers report the exact declaration anchor. */
337
- function compatibleContainerEvidence(
338
- left: DiscoveredTargetData,
339
- right: DiscoveredTargetData,
340
- ): boolean {
341
- return (
342
- left.container === right.container ||
343
- left.declarationAnchor.character === right.declarationAnchor.character
344
- );
345
- }
346
-
347
- function assignDeclarationOccurrences(
348
- targets: readonly DiscoveredTargetData[],
349
- ): DiscoveredTargetData[] {
350
- const candidates = targets.map((target) => ({
351
- name: target.name,
352
- identityKind: declarationIdentityKind(target),
353
- declarationAnchor: target.declarationAnchor,
354
- nameAnchor: { line: target.displayLine, character: target.displayCharacter },
355
- container: target.container,
356
- }));
357
- const occurrences = declarationOccurrencesFor(candidates);
358
- return targets.map((target, index) => {
359
- const declarationOccurrence = occurrences[index];
360
- if (declarationOccurrence === undefined) {
361
- throw new Error("The declaration occurrence was not assigned.");
362
- }
363
- return { ...target, declarationOccurrence };
278
+ const childParent = { name: item.name, kind: item.kind, level };
279
+ return [target, ...flattenOutline(file, item.children ?? [], childParent)];
364
280
  });
365
281
  }
366
-
367
- function declarationIdentityKind(target: ResolvedTargetData): string {
368
- return (
369
- target.identityKind ??
370
- canonicalFileDeclarationKind(target.file, target.kind, target.name) ??
371
- canonicalDeclarationKind(target.kind)
372
- );
373
- }
374
-
375
- function compareFileOrientationDeclarations(
376
- left: DiscoveredTargetData,
377
- right: DiscoveredTargetData,
378
- ): number {
379
- return topLevelRank(left) - topLevelRank(right) || compareDeclarations(left, right);
380
- }
381
-
382
- function topLevelRank(target: DiscoveredTargetData): number {
383
- return target.nesting === "top-level" ? 0 : 1;
384
- }
385
-
386
- function compareDeclarations(left: ResolvedTargetData, right: ResolvedTargetData): number {
387
- return (
388
- left.displayLine - right.displayLine ||
389
- left.displayCharacter - right.displayCharacter ||
390
- (left.name ?? "").localeCompare(right.name ?? "") ||
391
- (left.kind ?? "").localeCompare(right.kind ?? "")
392
- );
393
- }
@@ -310,7 +310,11 @@ function emptySymbolOutcome(
310
310
  }
311
311
  return {
312
312
  kind: "error",
313
- message: `Symbol not found: \`${symbol}\`${scope ? ` in path \`${scope}\`` : ""}. Try \`code_resolve\` to search for it, or use an anchor target (file/line/character) if you know the location.`,
313
+ message: [
314
+ `Symbol not found: \`${symbol}\`${scope ? ` in path \`${scope}\`` : ""}.`,
315
+ "Workspace-symbol search covers only files in projects the language server has loaded; files outside them (e.g. excluded by tsconfig or in another toolchain's subtree) are not searched.",
316
+ 'Next: `code_find` with `mode: "ast"` and `kind: "definition"` for a structural search, `code_resolve` with `target.file` if the file is known, or an anchor target (file/line/character) if the location is known.',
317
+ ].join(" "),
314
318
  };
315
319
  }
316
320