fix(workspace/symbol): use name span in ProvideWorkspaceSymbols#3836
fix(workspace/symbol): use name span in ProvideWorkspaceSymbols#3836joj wants to merge 2 commits into
Conversation
b504efe to
50792b5
Compare
There was a problem hiding this comment.
Pull request overview
Adjusts workspace/symbol results in the TypeScript-Go language server so LSP SymbolInformation.Location.Range targets just the declaration’s name span (matching TS5 navto behavior), improving VS selection/cursor placement.
Changes:
- Compute a
nameRangefromast.GetNameOfDeclarationand use it for the returned symbol location. - Fall back to a zero-width range at the declaration start for anonymous declarations.
Show a summary per file
| File | Description |
|---|---|
| internal/ls/symbols.go | Change workspace symbol locations from full-declaration spans to name-only spans (with anonymous fallback). |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 1
| // Use the name node's span so that VS selects just the symbol name (matching | ||
| // the TS5 navto behaviour). Fall back to the declaration start position if the | ||
| // declaration has no explicit name node (e.g. anonymous default exports). | ||
| var nameRange core.TextRange | ||
| if nameNode := ast.GetNameOfDeclaration(node); nameNode != nil { | ||
| nameStart := astnav.GetStartOfNode(nameNode, sourceFile, false /*includeJsDoc*/) | ||
| nameRange = core.NewTextRange(nameStart, nameNode.End()) | ||
| } else { |
|
I checked whether this would change what gets highlighted in VS Code, but only document symbols renders a highlight range; workspace symbols do not. IMO this PR makes the workspace symbol behavior closer to that of document symbols, because |
|
You modified generated tests which isn't allowed; the top of the generated tests says how to manually modify them. |
Return the name node span instead of the full declaration span for workspace symbol locations.
70cd6e9 to
ca906fe
Compare
Update baseline and fourslash test range annotations to reflect name-only spans for workspace symbols.
ca906fe to
191f1a1
Compare
The ProvideWorkspaceSymbols handler was returning the full declaration span (from 'function' keyword to closing '}') as the symbol location range. VS uses this range to select the result in the editor; a whole-declaration range causes the cursor to land at the keyword with nothing selected.
TS5 navto returns just the name identifier span (e.g. 'balance' in 'function balance()'), so VS expects the same from the TS7 path.
Fix: resolve the declaration's name node via GetNameOfDeclaration and use that node's text span for the location. Fall back to a zero-width range at the declaration start for anonymous declarations.