[Feature] LSP navigation tools for the agent: definition, references, symbols
Description
Implement the missing LSP request methods (textDocument/definition, textDocument/references, textDocument/documentSymbol, workspace/symbol) and expose them as agent-callable tools.
This picks up the tool layer designed in #52. That issue delivered the LSP foundation, client, JSON-RPC, auto-discovery, document sync, the VS Code extension, lsp_get_diagnostics, and auto-diagnostics after edits (auto-diagnostics.ts). The navigation tools it specified in Phase 2 didn't land, and docs/battlemap.md now records the consequence:
IDE-level code intelligence. OMP wires full LSP and DAP into the agent's tool surface. Nanocoder has an LSP client but nothing at that depth, and no debugger integration at all.
Not proposing anything new in shape, #52 already specified get_definition, get_references and get_symbols with their signatures, and the launch post described the intent as "10 new AI tools powered by LSP data." This is finishing that surface, starting with the read-only half.
Use Case
Today the agent answers "where is this defined?" and "what calls this?" with search_file_contents text matching that returns every string occurrence, including comments, unrelated identifiers and shadowed names. A language server answers both questions exactly, in one call, with no false positives.
The gap is visible in the code:
| Capability | Declared in protocol.ts |
Sent by lsp-client.ts |
Agent tool |
|---|---|---|---|
textDocument/definition |
yes | no | no |
textDocument/references |
yes | no | no |
textDocument/hover |
yes | no | no |
| document / workspace symbols | no | no | no |
textDocument/diagnostic |
yes | yes | lsp_get_diagnostics |
textDocument/formatting |
yes | yes | #1194 in progress |
| completion, codeAction | yes | yes | no |
protocol.ts also parses the definitionProvider and referencesProvider server capability flags, so we already ask every language server whether it supports features we never call.
This matters most for the models the project targets. A 7B model burning turns on grep results it has to filter itself is exactly the step-count cost tracked in #772.
Proposed Solution
1. Client methods (source/lsp/lsp-client.ts)
async getDefinition(uri: string, position: Position): Promise<Location[]>
async getReferences(uri: string, position: Position, includeDeclaration?: boolean): Promise<Location[]>
async getDocumentSymbols(uri: string): Promise<DocumentSymbol[]>
async getWorkspaceSymbols(query: string): Promise<SymbolInformation[]>
Add workspace/symbol and the document-symbol method to LSPMethods. The didOpen lifecycle these need already exists (openDocument/updateDocument/closeDocument), so this is request plumbing on top of working transport.
2. Manager wrappers (source/lsp/lsp-manager.ts)
Matching path-based wrappers, following the existing getDiagnostics / getCompletions / formatDocument pattern.
3. Symbol-to-position resolution
The one genuinely new piece. The agent knows symbol names; LSP wants a file and a position. Resolve a name to a candidate position (workspace symbols where the server supports it, falling back to the existing search path), then issue the positional request.
4. Agent tools (source/tools/)
lsp_get_definition, where is this symbol defined?lsp_get_references, what calls it?lsp_get_symbols, outline a file, or search workspace symbols
Registered in staticTools following the same shape as lsp-get-diagnostics.tsx and the pattern #1194 is establishing for lsp_format_document. All three are readOnly: true.
5. Degrade cleanly
No server for the language, or the server doesn't advertise the capability, → return a clear result telling the agent to fall back to search_file_contents, never an error and never silence. hasLanguageSupport() and getCapabilities() already exist for this.
Out of scope, deliberately
rename_symbol and apply_code_action from #52 are workspace-wide mutations. They need an approval policy and a diff-preview path, which is a different problem from read-only navigation. Worth a follow-up issue once these land.
get_hover_info and get_type_definition share the same positional plumbing and would be cheap follow-ups, but are left out here to keep the change reviewable.
Alternatives Considered
Leave it to search_file_contents. Works, and stays the fallback. But it cannot distinguish a definition from a mention, and costs the model turns filtering results, the cost #772 is tracking.
Build a symbol index instead (as discussed in #1186). Complementary rather than alternative: an index is always available and approximate, LSP is exact but needs a running server. #1186 Phase 3 assumed both, index-first with LSP escalation. This issue delivers the LSP half, which is useful on its own.
Do all ten #52 tools at once. Too large to review, and mixes read-only navigation with workspace mutations that need their own approval design.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] This feature aligns with the project's goals (local-first AI assistance)
Overlap. #1171 / PR #1194 (@Dhirenderchoudhary) add lsp_format_document and touch source/tools/index.ts and tool-manager.ts — the same landing zone. Happy to wait for #1194 to merge and follow its established pattern rather than land a competing one.
Related. #52 (design and tool specifications) · #1186 Phase 3 (index-first lookup tools, deferred behind Gate 0) · #772 (step-count cost of text-search navigation).
Timing. Not proposing to start before the Phase 0 evaluation harness is done, so the step-count effect can be measured rather than assumed.
Hey @akramcodez,
Would love to take this one, mind assigning it to me?
Plan's basically what's in the issue: the four request methods on lsp-client.ts,
path-based wrappers on lsp-manager.ts, then the three read-only tools shaped like lsp-get-diagnostics.tsx.
Main things I want to get right are normalising what servers actually return (Location vs LocationLink, nested vs flat symbols) and making "no capability" read differently from "no results" so it degrades into a clean fallback instead of silence.
Tests per layer + a changeset.
Happy to sit behind #1194 and match its pattern so we're not both touching tools/index.ts.