@dimassetoid/septum-mcp 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +124 -2
- package/bin/septum.ts +4 -0
- package/package.json +70 -4
- package/scripts/postinstall.ts +25 -0
- package/src/cli/commands/check.ts +122 -0
- package/src/cli/commands/hook.ts +268 -0
- package/src/cli/commands/init.ts +553 -0
- package/src/cli/commands/serve.ts +5 -0
- package/src/cli/commands/sync.ts +41 -0
- package/src/cli/commands/topology.ts +161 -0
- package/src/cli/index.ts +167 -0
- package/src/cli/scaffold/harness-config.ts +621 -0
- package/src/cli/templates/hooks.ts +75 -0
- package/src/cli/templates/rules.ts +50 -0
- package/src/cli/templates/skill.ts +51 -0
- package/src/cli/ui/prompts.ts +122 -0
- package/src/core/boundary/evaluator.ts +442 -0
- package/src/core/boundary/staged-auditor.ts +58 -0
- package/src/core/config/loader.ts +122 -0
- package/src/core/config/schema.ts +69 -0
- package/src/core/database/client.ts +60 -0
- package/src/core/database/repositories/dependency.repository.ts +712 -0
- package/src/core/database/repositories/domain.repository.ts +330 -0
- package/src/core/database/repositories/environment.repository.ts +207 -0
- package/src/core/database/repositories/file.repository.ts +117 -0
- package/src/core/database/repositories/meta.repository.ts +33 -0
- package/src/core/database/repositories/symbol.repository.ts +508 -0
- package/src/core/database/repository.ts +303 -0
- package/src/core/database/schema.ts +154 -0
- package/src/core/discovery/topology-detector.ts +805 -0
- package/src/core/ingestion/hasher.ts +5 -0
- package/src/core/ingestion/pipeline.ts +623 -0
- package/src/core/parser/behavioral-analyzer.ts +119 -0
- package/src/core/parser/boundary-tracker.ts +443 -0
- package/src/core/parser/extractors/base.ts +67 -0
- package/src/core/parser/extractors/blade.ts +159 -0
- package/src/core/parser/extractors/csharp.ts +244 -0
- package/src/core/parser/extractors/django-semantic.ts +687 -0
- package/src/core/parser/extractors/elysia-semantic.ts +538 -0
- package/src/core/parser/extractors/express-semantic.ts +444 -0
- package/src/core/parser/extractors/fastapi-semantic.ts +736 -0
- package/src/core/parser/extractors/fastify-semantic.ts +774 -0
- package/src/core/parser/extractors/flask-semantic.ts +515 -0
- package/src/core/parser/extractors/frontend.ts +149 -0
- package/src/core/parser/extractors/go-semantic.ts +611 -0
- package/src/core/parser/extractors/go.ts +491 -0
- package/src/core/parser/extractors/hono-semantic.ts +567 -0
- package/src/core/parser/extractors/java.ts +225 -0
- package/src/core/parser/extractors/laravel-semantic.ts +1122 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +368 -0
- package/src/core/parser/extractors/nestjs-semantic.ts +543 -0
- package/src/core/parser/extractors/php.ts +569 -0
- package/src/core/parser/extractors/python.ts +498 -0
- package/src/core/parser/extractors/registry.ts +78 -0
- package/src/core/parser/extractors/ruby.ts +234 -0
- package/src/core/parser/extractors/rust.ts +286 -0
- package/src/core/parser/extractors/semantic-extractor.interface.ts +22 -0
- package/src/core/parser/extractors/symfony-semantic.ts +354 -0
- package/src/core/parser/extractors/typescript.ts +826 -0
- package/src/core/parser/language-capabilities.ts +71 -0
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +216 -0
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +90 -0
- package/src/core/parser/schema/schema-provider-registry.ts +43 -0
- package/src/core/parser/schema/schema-provider.interface.ts +33 -0
- package/src/core/parser/tree-sitter.ts +63 -0
- package/src/core/parser/wasm-assets.ts +25 -0
- package/src/core/parser/wasm-loader.ts +274 -0
- package/src/core/resolver/call-graph-tracer.ts +724 -0
- package/src/core/resolver/import-resolver.ts +437 -0
- package/src/core/resolver/module-resolver.ts +482 -0
- package/src/core/resolver/path-resolver.ts +200 -0
- package/src/core/resolver/symbol-locator.ts +276 -0
- package/src/core/resolver/symbol-reference.ts +53 -0
- package/src/core/resolver/vertical-slice-tracer.ts +366 -0
- package/src/core/resources/ignore.ts +123 -0
- package/src/core/resources/limits.ts +14 -0
- package/src/core/resources/source-files.ts +62 -0
- package/src/core/resources/work-queue.ts +74 -0
- package/src/core/session/session-manager.ts +107 -0
- package/src/core/telemetry/telemetry.ts +97 -0
- package/src/core/topology/environment-detector.ts +973 -0
- package/src/core/topology/types.ts +83 -0
- package/src/index.ts +21 -0
- package/src/mcp/schemas.ts +1105 -0
- package/src/mcp/server.ts +774 -0
- package/src/mcp/tools/boundary.ts +17 -0
- package/src/mcp/tools/check-boundary.ts +387 -0
- package/src/mcp/tools/domain.ts +40 -0
- package/src/mcp/tools/feature.ts +67 -0
- package/src/mcp/tools/get-domain-catalog.ts +226 -0
- package/src/mcp/tools/get-environment-topology.ts +138 -0
- package/src/mcp/tools/get-feature-context.ts +224 -0
- package/src/mcp/tools/get-symbol-hotspots.ts +54 -0
- package/src/mcp/tools/get-symbol-impact.ts +64 -0
- package/src/mcp/tools/get-symbol.ts +175 -0
- package/src/mcp/tools/locate-symbol.ts +196 -0
- package/src/mcp/tools/register-domain.ts +75 -0
- package/src/mcp/tools/register-feature.ts +110 -0
- package/src/mcp/tools/slice.ts +16 -0
- package/src/mcp/tools/symbol.ts +93 -0
- package/src/mcp/tools/trace-vertical-slice.ts +80 -0
- package/src/mcp/workspace-manager.ts +159 -0
- package/src/mcp/workspace-watcher.ts +202 -0
- package/src/types/index.ts +456 -0
- package/src/types/wasm.d.ts +4 -0
- package/src/utils/version-check.ts +209 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { symbolReference } from "./symbol-reference.ts";
|
|
2
|
+
import type { SymbolReference, SymbolSelectionOptions } from "../../types/index.ts";
|
|
3
|
+
import type { SymbolKind } from "../database/repository.ts";
|
|
4
|
+
import type { SeptumRepository } from "../database/repository.ts";
|
|
5
|
+
|
|
6
|
+
export interface ParsedSymbolQuery {
|
|
7
|
+
raw: string;
|
|
8
|
+
container?: string; // e.g. "OrderController" or "App\\Http\\Controllers\\OrderController"
|
|
9
|
+
member?: string; // e.g. "calculateTotal"
|
|
10
|
+
kind?: SymbolKind;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface SuggestionMatch {
|
|
14
|
+
name: string;
|
|
15
|
+
kind: string;
|
|
16
|
+
signature: string;
|
|
17
|
+
line_start: number;
|
|
18
|
+
line_end: number;
|
|
19
|
+
similarity_score: number; // 0.0 - 1.0
|
|
20
|
+
file_path?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface SymbolLocationResult {
|
|
24
|
+
query: string;
|
|
25
|
+
parsed: ParsedSymbolQuery;
|
|
26
|
+
found: boolean;
|
|
27
|
+
status?: "ambiguous" | "stale_reference";
|
|
28
|
+
candidates?: Array<{ name: string; file_path: string; signature: string; symbol_ref: SymbolReference }>;
|
|
29
|
+
symbol_ref?: SymbolReference;
|
|
30
|
+
file_path?: string;
|
|
31
|
+
container_name?: string;
|
|
32
|
+
exact_symbol?: {
|
|
33
|
+
name: string;
|
|
34
|
+
kind: string;
|
|
35
|
+
signature: string;
|
|
36
|
+
visibility: string;
|
|
37
|
+
line_start: number;
|
|
38
|
+
line_end: number;
|
|
39
|
+
};
|
|
40
|
+
sibling_methods?: string[];
|
|
41
|
+
suggestions: SuggestionMatch[];
|
|
42
|
+
message: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class SymbolLocator {
|
|
46
|
+
constructor(private repo: SeptumRepository) {}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Parse error log strings, method call syntax, or symbol names into container & member.
|
|
50
|
+
* Examples:
|
|
51
|
+
* - "Method OrderController::calculateTotal() does not exist"
|
|
52
|
+
* - "Call to undefined method App\\Http\\Controllers\\OrderController::calculateTotal()"
|
|
53
|
+
* - "OrderController->calculateTotal()"
|
|
54
|
+
* - "OrderController.calculateTotal"
|
|
55
|
+
* - "OrderController"
|
|
56
|
+
* - "calculateTotal"
|
|
57
|
+
*/
|
|
58
|
+
public parseQuery(rawQuery: string): ParsedSymbolQuery {
|
|
59
|
+
const trimmed = rawQuery.trim();
|
|
60
|
+
|
|
61
|
+
// 1. Error string matching: "Method X::y() does not exist" or "Call to undefined method X::y()"
|
|
62
|
+
const methodNotExistMatch = trimmed.match(/(?:Method|method)\s+([A-Za-z0-9_\\\/\.]+)::([A-Za-z0-9_]+)\s*\(\)?/i);
|
|
63
|
+
if (methodNotExistMatch) {
|
|
64
|
+
return {
|
|
65
|
+
raw: trimmed,
|
|
66
|
+
container: methodNotExistMatch[1],
|
|
67
|
+
member: methodNotExistMatch[2],
|
|
68
|
+
kind: "method",
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 2. Python / JS error: "'X' object has no attribute 'y'"
|
|
73
|
+
const pyAttrMatch = trimmed.match(/['"]?([A-Za-z0-9_]+)['"]?\s+object has no attribute\s+['"]?([A-Za-z0-9_]+)['"]?/i);
|
|
74
|
+
if (pyAttrMatch) {
|
|
75
|
+
return {
|
|
76
|
+
raw: trimmed,
|
|
77
|
+
container: pyAttrMatch[1],
|
|
78
|
+
member: pyAttrMatch[2],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 3. Class::member or Class->member or Class.member
|
|
83
|
+
const staticCallMatch = trimmed.match(/^([A-Za-z0-9_\\\/\.]+)::([A-Za-z0-9_]+)(?:\(\))?$/);
|
|
84
|
+
if (staticCallMatch) {
|
|
85
|
+
return {
|
|
86
|
+
raw: trimmed,
|
|
87
|
+
container: staticCallMatch[1],
|
|
88
|
+
member: staticCallMatch[2],
|
|
89
|
+
kind: "method",
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const arrowCallMatch = trimmed.match(/^([A-Za-z0-9_\\\/\.]+)->([A-Za-z0-9_]+)(?:\(\))?$/);
|
|
94
|
+
if (arrowCallMatch) {
|
|
95
|
+
return {
|
|
96
|
+
raw: trimmed,
|
|
97
|
+
container: arrowCallMatch[1],
|
|
98
|
+
member: arrowCallMatch[2],
|
|
99
|
+
kind: "method",
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const dotCallMatch = trimmed.match(/^([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)(?:\(\))?$/);
|
|
104
|
+
if (dotCallMatch) {
|
|
105
|
+
return {
|
|
106
|
+
raw: trimmed,
|
|
107
|
+
container: dotCallMatch[1],
|
|
108
|
+
member: dotCallMatch[2],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 4. Function call: "calculateTotal()"
|
|
113
|
+
const funcMatch = trimmed.match(/^([A-Za-z0-9_]+)\(\)$/);
|
|
114
|
+
if (funcMatch) {
|
|
115
|
+
return {
|
|
116
|
+
raw: trimmed,
|
|
117
|
+
member: funcMatch[1],
|
|
118
|
+
kind: "function",
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 5. Bare word: could be class or function
|
|
123
|
+
return {
|
|
124
|
+
raw: trimmed,
|
|
125
|
+
member: trimmed,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Locate the symbol or diagnostic resolution in the database.
|
|
131
|
+
*/
|
|
132
|
+
public locate(rawQuery: string, domainFilter?: string, options: SymbolSelectionOptions = {}): SymbolLocationResult {
|
|
133
|
+
const parsed = this.parseQuery(rawQuery);
|
|
134
|
+
const selection = { ...options, domain: domainFilter ?? options.domain };
|
|
135
|
+
const base = { query: parsed.raw, parsed, found: false, suggestions: [] };
|
|
136
|
+
if (selection.reference) {
|
|
137
|
+
const file = this.repo.getFileByPath(selection.reference.file_path);
|
|
138
|
+
if (!file || file.content_hash !== selection.reference.indexed_content_hash) {
|
|
139
|
+
return { ...base, status: "stale_reference", message: "Declaration reference is stale; locate the symbol again." };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const container = parsed.container?.split(/\\|\//).pop();
|
|
143
|
+
const qualified = parsed.raw === `${parsed.container}.${parsed.member}` ? parsed.raw : `${container}::${parsed.member}`;
|
|
144
|
+
const query = selection.reference?.name ?? (container ? qualified : parsed.member ?? parsed.raw);
|
|
145
|
+
const candidates = this.repo.findSymbolsByName(query, selection);
|
|
146
|
+
if (candidates.length > 1) {
|
|
147
|
+
return {
|
|
148
|
+
...base, status: "ambiguous",
|
|
149
|
+
candidates: candidates.map(c => ({ name: c.name, file_path: c.file_path, signature: c.signature, symbol_ref: c.symbol_ref })),
|
|
150
|
+
message: "Multiple matching declarations; select a candidate with symbol_ref.",
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (candidates.length === 1) {
|
|
154
|
+
const exact = candidates[0]!;
|
|
155
|
+
const details = this.repo.getSymbolDetails(exact.name, { ...selection, reference: exact.symbol_ref, includeDependencies: false });
|
|
156
|
+
return {
|
|
157
|
+
...base, found: true, file_path: exact.file_path, container_name: exact.symbol_ref.container,
|
|
158
|
+
symbol_ref: exact.symbol_ref,
|
|
159
|
+
exact_symbol: { name: exact.name, kind: exact.kind, signature: exact.signature, visibility: exact.visibility, line_start: exact.line_start, line_end: exact.line_end },
|
|
160
|
+
sibling_methods: details?.sibling_methods,
|
|
161
|
+
message: `Found exact symbol '${exact.name}' in ${exact.file_path}:${exact.line_start}`,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const target = parsed.member ?? parsed.raw;
|
|
165
|
+
const owners = container ? this.repo.findSymbolsByName(container, selection)
|
|
166
|
+
.filter(s => ["class", "interface", "trait", "struct", "enum"].includes(s.kind)) : [];
|
|
167
|
+
const owner = owners.length === 1 ? owners[0] : undefined;
|
|
168
|
+
const siblings = owner ? this.repo.getSymbolDetails(owner.name, { ...selection, reference: owner.symbol_ref, includeDependencies: false })?.sibling_methods : undefined;
|
|
169
|
+
const searchable = owner ? this.repo.getSymbolsByFileId(owner.file_id)
|
|
170
|
+
.filter(s => s.kind === "method" && symbolReference({ ...s, file_path: owner.file_path, indexed_content_hash: owner.indexed_content_hash }).container === owner.name)
|
|
171
|
+
.map(s => ({ ...s, file_path: owner.file_path })) : this.repo.getAllSymbolsWithFiles();
|
|
172
|
+
const domainId = selection.domain ? this.repo.getAllDomains().find(d => d.name.toLowerCase() === selection.domain!.toLowerCase())?.id : undefined;
|
|
173
|
+
const suggestions = searchable
|
|
174
|
+
.filter(s => !selection.filePath || s.file_path === selection.filePath)
|
|
175
|
+
.filter(s => !selection.domain || this.repo.getFileByPath(s.file_path)?.domain_id === domainId)
|
|
176
|
+
.map(s => ({
|
|
177
|
+
name: owner ? s.name.split(/::|[.#]/).pop()! : s.name, kind: s.kind, signature: s.signature, line_start: s.line_start, line_end: s.line_end, file_path: s.file_path,
|
|
178
|
+
similarity_score: Math.round(Math.max(calculateSimilarity(target, s.name.split(/::|[.#]/).pop()!), calculateSimilarity(parsed.raw, s.name)) * 100) / 100,
|
|
179
|
+
}))
|
|
180
|
+
.filter(s => s.similarity_score >= 0.3)
|
|
181
|
+
.sort((a, b) => b.similarity_score - a.similarity_score).slice(0, 10);
|
|
182
|
+
return { ...base, file_path: owner?.file_path, container_name: owner?.name, sibling_methods: siblings, suggestions, message: `Symbol '${parsed.raw}' not found.${suggestions.length ? ` Did you mean '${suggestions[0]!.name}'?` : ""}` };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Enhanced similarity matching:
|
|
189
|
+
* Combines Damerau-Levenshtein distance (handling typos & transpositions),
|
|
190
|
+
* prefix/suffix matching, substring inclusion, and token Jaccard similarity.
|
|
191
|
+
*/
|
|
192
|
+
export function calculateSimilarity(source: string, target: string): number {
|
|
193
|
+
const s1 = source.toLowerCase();
|
|
194
|
+
const s2 = target.toLowerCase();
|
|
195
|
+
|
|
196
|
+
if (s1 === s2) return 1.0;
|
|
197
|
+
if (!s1 || !s2) return 0.0;
|
|
198
|
+
|
|
199
|
+
// Prefix bonus: highly relevant for autocomplete-style / partial searches
|
|
200
|
+
let prefixBonus = 0;
|
|
201
|
+
if (s2.startsWith(s1) || s1.startsWith(s2)) {
|
|
202
|
+
const minLen = Math.min(s1.length, s2.length);
|
|
203
|
+
const maxLen = Math.max(s1.length, s2.length);
|
|
204
|
+
prefixBonus = 0.25 * (minLen / maxLen);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Substring inclusion bonus
|
|
208
|
+
let substringBonus = 0;
|
|
209
|
+
if (s2.includes(s1) || s1.includes(s2)) {
|
|
210
|
+
const minLen = Math.min(s1.length, s2.length);
|
|
211
|
+
const maxLen = Math.max(s1.length, s2.length);
|
|
212
|
+
substringBonus = 0.3 * (minLen / maxLen);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Token-based matching (CamelCase, snake_case, kebab-case, namespaces)
|
|
216
|
+
const tokenize = (str: string) =>
|
|
217
|
+
str
|
|
218
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
219
|
+
.toLowerCase()
|
|
220
|
+
.split(/[\s_\-\.\:\/\\]+/)
|
|
221
|
+
.filter((t) => t.length > 1);
|
|
222
|
+
|
|
223
|
+
const t1 = tokenize(source);
|
|
224
|
+
const t2 = tokenize(target);
|
|
225
|
+
let tokenBonus = 0;
|
|
226
|
+
if (t1.length > 0 && t2.length > 0) {
|
|
227
|
+
const sharedTokens = t1.filter((token) =>
|
|
228
|
+
t2.some((t) => t.includes(token) || token.includes(t))
|
|
229
|
+
);
|
|
230
|
+
const allUniqueTokens = new Set([...t1, ...t2]);
|
|
231
|
+
const jaccard = sharedTokens.length / (allUniqueTokens.size || 1);
|
|
232
|
+
tokenBonus = jaccard * 0.35;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Damerau-Levenshtein Matrix
|
|
236
|
+
const len1 = s1.length;
|
|
237
|
+
const len2 = s2.length;
|
|
238
|
+
const matrix: number[][] = [];
|
|
239
|
+
|
|
240
|
+
for (let i = 0; i <= len1; i++) {
|
|
241
|
+
matrix[i] = [i];
|
|
242
|
+
}
|
|
243
|
+
for (let j = 0; j <= len2; j++) {
|
|
244
|
+
matrix[0][j] = j;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
for (let i = 1; i <= len1; i++) {
|
|
248
|
+
for (let j = 1; j <= len2; j++) {
|
|
249
|
+
const cost = s1[i - 1] === s2[j - 1] ? 0 : 1;
|
|
250
|
+
let minCost = Math.min(
|
|
251
|
+
matrix[i - 1][j] + 1, // deletion
|
|
252
|
+
matrix[i][j - 1] + 1, // insertion
|
|
253
|
+
matrix[i - 1][j - 1] + cost // substitution
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
// Transposition check (Damerau)
|
|
257
|
+
if (
|
|
258
|
+
i > 1 &&
|
|
259
|
+
j > 1 &&
|
|
260
|
+
s1[i - 1] === s2[j - 2] &&
|
|
261
|
+
s1[i - 2] === s2[j - 1]
|
|
262
|
+
) {
|
|
263
|
+
minCost = Math.min(minCost, matrix[i - 2][j - 2] + 1);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
matrix[i][j] = minCost;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const distance = matrix[len1][len2];
|
|
271
|
+
const maxLen = Math.max(len1, len2);
|
|
272
|
+
const rawSimilarity = 1.0 - distance / maxLen;
|
|
273
|
+
|
|
274
|
+
const totalScore = rawSimilarity + prefixBonus + substringBonus + tokenBonus;
|
|
275
|
+
return Math.min(1.0, Math.max(0.0, totalScore));
|
|
276
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { SymbolRecord, SymbolReference } from "../../types/index.ts";
|
|
2
|
+
import { getLanguageCapability } from "../parser/language-capabilities.ts";
|
|
3
|
+
|
|
4
|
+
type IndexedSymbol = SymbolRecord & { file_path: string; indexed_content_hash: string };
|
|
5
|
+
|
|
6
|
+
export function symbolReference(symbol: IndexedSymbol): SymbolReference {
|
|
7
|
+
const language = getLanguageCapability(symbol.file_path)?.id ?? "unknown";
|
|
8
|
+
let receiver: string | undefined;
|
|
9
|
+
let container = symbol.name.match(/^(.*)(?:::|[.#])[^:.#]+$/)?.[1];
|
|
10
|
+
if (language === "go" && symbol.kind === "method") {
|
|
11
|
+
const receiverClause = symbol.signature.match(/^\s*func\s*\(([^)]+)\)/)?.[1]?.trim();
|
|
12
|
+
if (receiverClause) {
|
|
13
|
+
const typeMatch = receiverClause.match(/^(?:[a-zA-Z0-9_]+\s+)?(\*?[a-zA-Z0-9_]+(?:\[[^\]]*\])?)$/);
|
|
14
|
+
if (typeMatch) {
|
|
15
|
+
receiver = typeMatch[1];
|
|
16
|
+
} else {
|
|
17
|
+
const spaceIdx = receiverClause.indexOf(" ");
|
|
18
|
+
receiver = spaceIdx !== -1 ? receiverClause.slice(spaceIdx + 1).trim() : receiverClause;
|
|
19
|
+
}
|
|
20
|
+
container = receiver?.replace(/^\*/, "").replace(/\[.*\]$/, "");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
file_path: symbol.file_path, language, name: symbol.name, kind: symbol.kind,
|
|
25
|
+
signature: symbol.signature, start_line: symbol.line_start, end_line: symbol.line_end,
|
|
26
|
+
indexed_content_hash: symbol.indexed_content_hash,
|
|
27
|
+
...(container ? { container } : {}), ...(receiver ? { receiver } : {}),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function matchesSymbolName(symbol: IndexedSymbol, query: string): boolean {
|
|
32
|
+
const ref = symbolReference(symbol);
|
|
33
|
+
const normalize = (name: string) => {
|
|
34
|
+
const plain = name.replace(/\(\)$/, "");
|
|
35
|
+
return ref.language === "ruby" ? plain : plain.replace(/->|[.#]/g, "::");
|
|
36
|
+
};
|
|
37
|
+
const target = normalize(query);
|
|
38
|
+
const name = normalize(symbol.name);
|
|
39
|
+
if (name === target || name.endsWith(`::${target}`) || name.endsWith(`\\${target}`)) return true;
|
|
40
|
+
if (!/::|[.#\\]/.test(target) && name.split(/::|[.#\\]/).pop() === target) return true;
|
|
41
|
+
if (ref.receiver && ref.container) {
|
|
42
|
+
if (`${ref.container}::${name}` === target) return true;
|
|
43
|
+
if (`${ref.receiver}::${name}` === target || `(${ref.receiver})::${name}` === target) return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// shortcut: identical signatures/ranges on one line remain ambiguous; add persisted columns when exact column selection is needed.
|
|
49
|
+
export function matchesSymbolReference(actual: SymbolReference, expected: SymbolReference): boolean {
|
|
50
|
+
return actual.file_path === expected.file_path && actual.name === expected.name && actual.kind === expected.kind
|
|
51
|
+
&& actual.signature === expected.signature && actual.start_line === expected.start_line && actual.end_line === expected.end_line
|
|
52
|
+
&& actual.indexed_content_hash === expected.indexed_content_hash && actual.language === expected.language;
|
|
53
|
+
}
|