Improve linked symbol anchors with tree-sitter fallback#5105
Improve linked symbol anchors with tree-sitter fallback#5105pranavvaid-ac wants to merge 3 commits intomicrosoft:mainfrom
Conversation
|
@pranavvaid-ac please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
Pull request overview
Adds an eager tree-sitter-based fallback to the linkify pipeline so linked-backtick symbol anchors can open near a symbol before document symbols are available, while still allowing later LSP-based upgrades.
Changes:
- Injects parser-based symbol lookup into
SymbolLinkifierand keeps the existing document-symbol resolve path for later upgrades. - Adds
findSymbolLocationInFileplus shared symbol-name extraction to support exact and qualified-name fallback with per-linkification file-symbol caching. - Expands linkify tests to cover initial tree-sitter locations, declaration preference, qualified fallback, cache reuse, and LSP upgrade behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/extension/linkify/vscode-node/symbolLinkifier.ts |
Uses tree-sitter to seed initial linked-symbol locations and adds resolve-time logging/helpers. |
src/extension/linkify/vscode-node/findWord.ts |
Adds file-level symbol lookup/cache logic used by linked symbol anchors. |
src/extension/linkify/vscode-node/findSymbol.ts |
Exports shared inline-code symbol-part extraction. |
src/extension/linkify/test/vscode-node/symbolLinkifier.test.ts |
Adds integration-style tests for tree-sitter fallback, cache reuse, and LSP upgrades. |
src/extension/linkify/test/vscode-node/findWord.test.ts |
Adds unit tests for exact/declaration/qualified-name symbol lookup and cache behavior. |
| const initialLocation = await findSymbolLocationInFile(this.parserService, resolvedUri, symbolText, token, symbolFileCache) | ||
| .catch(() => undefined); | ||
| console.log(`[SymbolLinkifier] tree-sitter initial symbol="${symbolText}" uri="${resolvedUri.toString()}" location=${formatLocationForLog(initialLocation)}`); |
| let bestMatch: { symbol: FileSymbol; matchIndex: number } | undefined; | ||
| for (const symbol of symbols) { | ||
| const matchIndex = symbolParts.indexOf(symbol.identifier); | ||
| if (matchIndex !== -1 && (!bestMatch || matchIndex > bestMatch.matchIndex)) { |
| const fullFileRange = new vscode.Range(0, 0, Number.MAX_SAFE_INTEGER, 0); | ||
| const [classDeclarations, functionDefinitions, typeDeclarations, genericSymbols] = await Promise.all([ | ||
| ast.getClassDeclarations(), | ||
| ast.getFunctionDefinitions(), | ||
| ast.getTypeDeclarations(), | ||
| ast.getSymbols({ | ||
| startIndex: doc.offsetAt(fullFileRange.start), | ||
| endIndex: doc.offsetAt(fullFileRange.end), | ||
| }), | ||
| ]); | ||
| symbols = [ | ||
| ...classDeclarations, | ||
| ...functionDefinitions, | ||
| ...typeDeclarations, | ||
| ...genericSymbols, | ||
| ]; |
Adds an eager tree-sitter fallback for linked-backtick symbol references so links open near the referenced symbol even before an LSP DocumentSymbolProvider result is available. Before this PR, links to referenced symbols would just take you to the top of the file if an LSP was not available.
Changes: