Skip to content

fix(workspace/symbol): use name span in ProvideWorkspaceSymbols#3836

Open
joj wants to merge 2 commits into
microsoft:mainfrom
joj:dev/joj/fix-workspace-symbol-range
Open

fix(workspace/symbol): use name span in ProvideWorkspaceSymbols#3836
joj wants to merge 2 commits into
microsoft:mainfrom
joj:dev/joj/fix-workspace-symbol-range

Conversation

@joj
Copy link
Copy Markdown
Member

@joj joj commented May 13, 2026

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.

Copilot AI review requested due to automatic review settings May 13, 2026 22:19
@joj joj force-pushed the dev/joj/fix-workspace-symbol-range branch from b504efe to 50792b5 Compare May 13, 2026 22:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 nameRange from ast.GetNameOfDeclaration and 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

Comment thread internal/ls/symbols.go
Comment on lines +568 to +575
// 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 {
@andrewbranch
Copy link
Copy Markdown
Member

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 DocumentSymbolResponse includes both the full range and the name range, so your cursor snaps to the name. Now your cursor snaps to the name in workspace symbols, too.

@jakebailey
Copy link
Copy Markdown
Member

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.
@joj joj force-pushed the dev/joj/fix-workspace-symbol-range branch 2 times, most recently from 70cd6e9 to ca906fe Compare May 14, 2026 17:36
Update baseline and fourslash test range annotations to reflect
name-only spans for workspace symbols.
@joj joj force-pushed the dev/joj/fix-workspace-symbol-range branch from ca906fe to 191f1a1 Compare May 14, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants