-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathkinds.ts
More file actions
141 lines (128 loc) · 5.18 KB
/
Copy pathkinds.ts
File metadata and controls
141 lines (128 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import path from 'node:path';
import { TYPESCRIPT_EXTENSIONS } from '../domain/parser.js';
import type {
CoreEdgeKind,
CoreSymbolKind,
DeadSubRole,
DynamicKind,
EdgeKind,
ExtendedSymbolKind,
Role,
StructuralEdgeKind,
SymbolKind,
} from '../types.js';
// ── Symbol kind constants ───────────────────────────────────────────
// Original 10 kinds — used as default query scope
export const CORE_SYMBOL_KINDS: readonly CoreSymbolKind[] = [
'function',
'method',
'class',
'interface',
'type',
'struct',
'enum',
'trait',
'record',
'module',
] as const;
// Sub-declaration kinds (Phase 1)
export const EXTENDED_SYMBOL_KINDS: readonly ExtendedSymbolKind[] = [
'parameter',
'property',
'constant',
// Phase 2 (reserved, not yet extracted):
// 'constructor', 'namespace', 'decorator', 'getter', 'setter',
] as const;
// Full set for --kind validation and MCP enum
export const EVERY_SYMBOL_KIND: readonly SymbolKind[] = [
...CORE_SYMBOL_KINDS,
...EXTENDED_SYMBOL_KINDS,
];
/**
* Symbol kinds that represent an actual invocable definition. A call site can
* legitimately target one of these — a class, interface, struct, or plain
* variable/constant binding cannot, in the general case, and must never win a
* same-name lookup that has no other type/receiver information to narrow it.
*
* Guards the "no other signal" tiers of call resolution — the same-file
* bare-name lookup in `resolveCallTargets` and `resolveByGlobal`'s exact
* global-name match (`call-resolver.ts`, `resolver/strategy.ts`) — so an
* unrelated same-named class/interface/variable never masquerades as a real
* callable target purely because those lookups otherwise carry no kind filter
* (#1888).
*/
export const CALLABLE_SYMBOL_KINDS: ReadonlySet<string> = new Set(['function', 'method']);
// Backward compat: ALL_SYMBOL_KINDS stays as the core 10
export const ALL_SYMBOL_KINDS: readonly CoreSymbolKind[] = CORE_SYMBOL_KINDS;
// ── Edge kind constants ─────────────────────────────────────────────
// Core edge kinds — coupling and dependency relationships
export const CORE_EDGE_KINDS: readonly CoreEdgeKind[] = [
'imports',
'imports-type',
'dynamic-imports',
'reexports',
'calls',
'extends',
'implements',
'contains',
] as const;
// Structural edge kinds — parent/child and type relationships
export const STRUCTURAL_EDGE_KINDS: readonly StructuralEdgeKind[] = [
'parameter_of',
'receiver',
] as const;
// Full set for MCP enum and validation
export const EVERY_EDGE_KIND: readonly EdgeKind[] = [...CORE_EDGE_KINDS, ...STRUCTURAL_EDGE_KINDS];
// Dead sub-categories — refine the coarse "dead" bucket
export const DEAD_ROLE_PREFIX = 'dead';
export const DEAD_SUB_ROLES: readonly DeadSubRole[] = [
'dead-leaf',
'dead-entry',
'dead-ffi',
'dead-unresolved',
] as const;
export const VALID_ROLES: readonly Role[] = [
'entry',
'core',
'utility',
'adapter',
'dead',
'test-only',
'leaf',
...DEAD_SUB_ROLES,
];
// ── Dynamic call classification ──────────────────────────────────────
// Dynamic kinds that cannot be resolved statically — a call site tagged with
// one of these, and left with no resolved target, gets a confidence=0.0 sink
// edge to its file node instead of being silently dropped. Shared by the
// WASM/JS full-build path (`buildFileCallEdges`, stages/build-edges.ts) and
// the incremental single-file rebuild path (`buildCallEdges`,
// builder/incremental.ts) — both must emit the same sink edges (#1852).
export const FLAG_ONLY_DYNAMIC_KINDS: ReadonlySet<DynamicKind> = new Set([
'eval',
'computed-key',
'reflection',
'unresolved-dynamic',
]);
// ── TypeScript type-erasure classification ──────────────────────────
// Symbol kinds that are compile-time-only in TypeScript — interfaces and
// type aliases are erased before runtime, so a symbol of one of these kinds
// can never receive a `calls` edge. Importing one — with or without the
// `type` keyword — is the only consumption signal `codegraph exports` can
// observe for these kinds (#1833).
export const TYPE_ERASED_SYMBOL_KINDS: ReadonlySet<string> = new Set(['interface', 'type']);
/**
* True when a named import specifier resolving to `kind` in `file` can only
* ever be consumed as a type — i.e. it's a TypeScript interface/type-alias
* declaration, which no `calls` edge could ever target regardless of the
* `type` keyword on the importing statement.
*
* Scoped to `.ts`/`.tsx` files because other languages reuse the 'interface'/
* 'type' node kinds for constructs that *are* runtime-observable (e.g. a Go
* `type` alias, a Java `interface` implemented and dispatched through at
* runtime) — crediting those on mere import would mask genuinely dead code
* instead of fixing a false positive.
*/
export function isTypeErasedImportTarget(kind: string, file: string): boolean {
return TYPE_ERASED_SYMBOL_KINDS.has(kind) && TYPESCRIPT_EXTENSIONS.has(path.extname(file));
}