Skip to content

Commit de2645d

Browse files
committed
feat(symbol-resolver): enhance symbol matching with quote handling and exact match support
1 parent 5601915 commit de2645d

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

src/tools/file/symbol-resolver.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,39 @@ import type {SymbolMatch} from './types.js';
1515
* - "UserService.findById" → child "findById" of "UserService"
1616
* - "findById" → first top-level symbol named "findById"
1717
*/
18+
/**
19+
* Strip surrounding quotes from a string (single or double).
20+
* E.g., "'./augmented'" → "./augmented", "\"foo\"" → "foo"
21+
*/
22+
function stripQuotes(s: string): string {
23+
if (
24+
(s.startsWith("'") && s.endsWith("'")) ||
25+
(s.startsWith('"') && s.endsWith('"'))
26+
) {
27+
return s.slice(1, -1);
28+
}
29+
return s;
30+
}
31+
32+
/**
33+
* Match a symbol name against a target, handling quoted module names.
34+
*/
35+
function nameMatches(symbolName: string, targetName: string): boolean {
36+
if (symbolName === targetName) return true;
37+
return stripQuotes(symbolName) === stripQuotes(targetName);
38+
}
39+
1840
export function resolveSymbolTarget(
1941
symbols: FileSymbol[],
2042
target: string,
2143
): SymbolMatch | undefined {
44+
// First, try exact match at top level (handles module names with dots like './augmented')
45+
const exactMatch = symbols.find(s => nameMatches(s.name, target));
46+
if (exactMatch) {
47+
return {symbol: exactMatch, parent: undefined, path: [target]};
48+
}
49+
50+
// Then try dot-path resolution for nested symbols
2251
const segments = target.split('.');
2352

2453
let currentList = symbols;
@@ -27,7 +56,7 @@ export function resolveSymbolTarget(
2756

2857
for (let i = 0; i < segments.length; i++) {
2958
const name = segments[i];
30-
const found = currentList.find(s => s.name === name);
59+
const found = currentList.find(s => nameMatches(s.name, name));
3160
if (!found) return undefined;
3261

3362
pathSoFar.push(name);

0 commit comments

Comments
 (0)