Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 13, 2025

Overview

This PR implements workspace symbols support for the protols LSP server, enabling clients to search for symbols across all files in the workspace. This complements the existing document symbols feature by providing a global symbol search capability.

Changes

Server Capabilities

  • Added workspace_symbol_provider to the LSP server capabilities advertised during initialization
  • Registered the WorkspaceSymbolRequest handler in the server router

Implementation

The implementation adds a workspace_symbol method in src/lsp.rs that processes workspace symbol requests with query-based filtering. The method now includes full workspace parsing before symbol collection:

  1. Full Workspace Parsing: Before collecting symbols, the handler parses all .proto files from all workspace folders (similar to references and rename capabilities), ensuring complete coverage
  2. find_workspace_symbols in src/state.rs: Collects symbols from all parsed trees in the workspace, filters them based on the query string (case-insensitive substring match), and returns sorted results
  3. collect_workspace_symbols in src/state.rs: Recursively traverses document symbols to extract workspace symbols, maintaining parent-child relationships via the container_name field
  4. get_workspaces in src/config/workspace.rs: New helper method to retrieve all workspace folder URIs

Features

  • Full workspace coverage: Parses all proto files in all workspace folders, not just opened files and their imports
  • Cross-file symbol search: Search for messages, enums, and other symbols across all proto files in the workspace
  • Query filtering: Case-insensitive substring matching on symbol names
  • Nested symbol support: Correctly handles and reports nested messages with their container names
  • Consistent ordering: Results are sorted alphabetically by name and then by URI for predictable behavior
  • Progress reporting: Supports LSP work done progress tokens for long-running workspace parsing operations

Example Usage

When a client sends a workspace/symbol request with query "author":

{
  "query": "author"
}

The server parses all workspace files and returns all symbols matching "author" across the workspace:

[
  {
    "name": "Author",
    "kind": 23,
    "location": {
      "uri": "file:///path/to/b.proto",
      "range": { "start": { "line": 5, "character": 0 }, ... }
    }
  }
]

Testing

Added comprehensive test coverage in src/workspace/workspace_symbol.rs:

  • Test with empty query (returns all symbols)
  • Test with specific queries ("author", "address")
  • Test that non-matching queries return empty results
  • Uses insta snapshot testing for regression protection

All 29 tests pass successfully (28 existing + 1 new).

Fixes #21

Original prompt

This section details on the original issue you should resolve

<issue_title>Add support for workspace symbols</issue_title>
<issue_description>We already support document symbols, it's time to support workspace symbols as well.</issue_description>

Comments on the Issue (you are @copilot in this section)

@coder3101 can be re-opened if requested.

Fixes #21


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add WorkspaceSymbolRequest handler registration in server.rs
- Implement workspace_symbol method in lsp.rs to handle workspace symbol requests
- Add workspace_symbol_provider capability in initialize response
- Create find_workspace_symbols method in state.rs to collect and filter symbols from all parsed trees
- Add comprehensive test for workspace symbols functionality with snapshots
- Sort symbols by name and URI for consistent ordering

Co-authored-by: coder3101 <22212259+coder3101@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for workspace symbols Add support for workspace symbols Oct 13, 2025
Copilot AI requested a review from coder3101 October 13, 2025 14:39
Copilot finished work on behalf of coder3101 October 13, 2025 14:39
@hujianxin
Copy link

I found that your new protols only recognizes symbols of files I have accessed, and does not actively index files that have not been accessed.

@coder3101
Copy link
Owner

Workspace symbols need full workspace parsing, similar to what references or rename capabilities, otherwise for most of other capabilities, we only parse the opened and recursively imported files.

Probably, AI got this wrong and let me nudge it in the right direction or will take a look at it over the weekend.

@coder3101
Copy link
Owner

@copilot the PR looks good but it only shows the workspace symbols of opened files and files imported by it, when workspace symbols is requested we should fallback to full workspace parsing similar to rename and references. Please update the PR to take this into account.

- Add get_workspaces() method to WorkspaceProtoConfigs to retrieve all workspace folders
- Update workspace_symbol handler to parse all files from all workspaces before collecting symbols
- Add progress reporting support for workspace symbol requests
- Now workspace symbols work across entire workspace, not just opened files

Co-authored-by: coder3101 <22212259+coder3101@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 14, 2025

@copilot the PR looks good but it only shows the workspace symbols of opened files and files imported by it, when workspace symbols is requested we should fallback to full workspace parsing similar to...

Updated the implementation to parse all workspace files before collecting symbols, similar to how references and rename work. The workspace_symbol method now:

  1. Gets all workspace folders via get_workspaces()
  2. Calls parse_all_from_workspace() for each workspace
  3. Supports progress reporting for the parsing operation
  4. Then collects symbols from all parsed trees

Changes in commit: Will be included in the next commit message.

Copilot finished work on behalf of coder3101 October 14, 2025 05:42
@hujianxin
Copy link

@coder3101 new commit looks good for me, I don't know if it need some cache or something to speed up workspace symbols lookup, but it works for now, I feel good, thanks

@coder3101
Copy link
Owner

coder3101 commented Oct 14, 2025

I will merge these changes after a review, thanks for confirming that it works.

Caching can be a follow up if requested.

@coder3101
Copy link
Owner

I will do a commit for non functional changes over the weekend before merging. In the meantime time feel free to use this branch for your testing.

@asharkhan3101 asharkhan3101 marked this pull request as ready for review October 22, 2025 07:08
@abrassel
Copy link

abrassel commented Nov 4, 2025

Hi folks, I think this branch is not quite ready yet. I would love to finish this feature, if you know what work remains.

@coder3101
Copy link
Owner

Yes please, go ahead!

@abrassel
Copy link

abrassel commented Nov 4, 2025

Great, thank you! Do you know what work remains to be done?

@coder3101
Copy link
Owner

coder3101 commented Nov 5, 2025

I believe testing is needed, simple symbol, nested symbols, across different packages etc. Apart from that some lint issue with cargo clippy and that should be all.

Depending on the testing some other fixes might be needed, or else good for merge.

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.

Add support for workspace symbols

4 participants