Skip to content

Handle LSP textDocument/documentSymbol requests #1363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 6, 2025

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Jul 6, 2025

This PR implements textDocument/documentSymbol request handling. This enables the following functionality in VS Code:

  • Go to Symbol in Editor (Ctrl-Shift-O).
  • Outline View.
  • Breadcrumbs navigation bar.

Fixes #1295

@ahejlsberg ahejlsberg requested review from Copilot, jakebailey, DanielRosenwasser and RyanCavanaugh and removed request for Copilot July 6, 2025 20:58
Copy link
Contributor

@Copilot 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

This PR adds support for handling textDocument/documentSymbol requests in the LSP server, enabling symbol outline features in editors.

  • Introduces a handleDocumentSymbol handler in the server.
  • Implements ProvideDocumentSymbols and related helpers to traverse the AST and produce DocumentSymbol entries.
  • Cleans up unused assignment-declaration kinds in the type checker.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/lsp/server.go Register and implement textDocument/documentSymbol handling
internal/ls/symbols.go Add ProvideDocumentSymbols and helper functions for AST traversal and symbol creation
internal/checker/types.go Remove AssignmentDeclarationKind type and associated constants
Comments suppressed due to low confidence (3)

internal/lsp/server.go:799

  • [nitpick] The variable name hover is misleading since it holds document symbols. Consider renaming it to symbols or docSymbols for clarity.
	hover, err := languageService.ProvideDocumentSymbols(ctx, params.TextDocument.Uri)

internal/ls/symbols.go:20

  • No tests were added to validate ProvideDocumentSymbols. Add compiler tests in testdata/tests/cases/compiler to cover documentSymbol functionality and ensure correct output baselines.
func (l *LanguageService) ProvideDocumentSymbols(ctx context.Context, documentURI lsproto.DocumentUri) ([]*lsproto.DocumentSymbol, error) {

internal/checker/types.go:297

  • You removed AssignmentDeclarationKind and its constants, which may break code relying on that type. Verify that all references are updated or confirm this deletion is intended.
	AccessFlagsPersistent                             = AccessFlagsIncludeUndefined

@ahejlsberg ahejlsberg added this pull request to the merge queue Jul 6, 2025
Merged via the queue into main with commit 76d4e43 Jul 6, 2025
22 checks passed
@ahejlsberg ahejlsberg deleted the lsp-document-symbols branch July 6, 2025 21:55
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.

vscode - The active text editor does not provide symbol information
2 participants