Skip to content

Introduce lsp_references tool for enhanced code navigation#14

Merged
linw1995 merged 4 commits intomainfrom
copilot/fix-7794f033-10f1-4377-9773-73ed1137d6ea
Aug 11, 2025
Merged

Introduce lsp_references tool for enhanced code navigation#14
linw1995 merged 4 commits intomainfrom
copilot/fix-7794f033-10f1-4377-9773-73ed1137d6ea

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 11, 2025

This PR implements the lsp_references tool as requested in issue #11, providing enhanced code navigation capabilities by exposing Neovim's LSP textDocument/references functionality through the MCP interface.

What's New

The new lsp_references tool allows clients to find all references to a symbol at a specific position in a buffer, following the LSP specification for textDocument/references.

Tool Parameters

{
  "connection_id": "string",
  "id": 123,
  "lsp_client_name": "rust_analyzer",
  "line": 10,
  "character": 5,
  "include_declaration": true
}
  • connection_id: Unique identifier for the target Neovim instance
  • id: Neovim Buffer ID
  • lsp_client_name: Name of the LSP client to query
  • line/character: Zero-indexed position of the symbol
  • include_declaration: Whether to include the symbol's declaration in results

Response Format

Returns an array of Location objects:

[
  {
    "uri": "file:///path/to/file.rs",
    "range": {
      "start": {"line": 5, "character": 10},
      "end": {"line": 5, "character": 15}
    }
  }
]

Implementation Details

The implementation follows the established patterns in the codebase:

  1. LSP Integration: Added ReferenceParams and ReferenceContext structs following LSP specification
  2. Client Interface: Extended NeovimClientTrait with lsp_references method
  3. Lua Script: Created lsp_references.lua for making LSP requests to Neovim
  4. MCP Tool: Registered the tool with proper parameter validation and error handling
  5. Testing: Added unit tests for parameter serialization and integration test verification

The tool maintains consistency with existing LSP tools (buffer_hover, document_symbols, workspace_symbols) and uses the same connection-aware architecture for multi-instance Neovim support.

Usage Example

# Find all references to a symbol at line 10, character 5 in buffer 1
echo '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "lsp_references",
    "arguments": {
      "connection_id": "abc123",
      "id": 1,
      "lsp_client_name": "rust_analyzer", 
      "line": 10,
      "character": 5,
      "include_declaration": true
    }
  }
}' | nvim-mcp

This enhancement enables AI assistants and other MCP clients to perform sophisticated code navigation tasks, making it easier to understand code relationships and dependencies across projects.


💡 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.

Copilot AI and others added 2 commits August 11, 2025 10:21
Co-authored-by: linw1995 <13523027+linw1995@users.noreply.github.com>
Co-authored-by: linw1995 <13523027+linw1995@users.noreply.github.com>
Copilot AI changed the title [WIP] Resolve @linw1995/nvim-mcp/issues/11 Introduce lsp_references tool for enhanced code navigation Aug 11, 2025
Copilot AI requested a review from linw1995 August 11, 2025 10:26
@linw1995 linw1995 marked this pull request as ready for review August 11, 2025 12:04
- Use unwrap_or_default() instead of unwrap_or_else(Vec::new)
- Add missing newline at end of lsp_references.lua file
@linw1995 linw1995 merged commit 8f65d0e into main Aug 11, 2025
1 check passed
@linw1995 linw1995 deleted the copilot/fix-7794f033-10f1-4377-9773-73ed1137d6ea branch August 11, 2025 12:15
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.

2 participants