Skip to content

Add rust-analyzer integration with find_rust_symbol MCP tool - #47

Open
hodgesds wants to merge 2 commits into
facebookexperimental:mainfrom
hodgesds:feature/rust-analyzer-integration
Open

Add rust-analyzer integration with find_rust_symbol MCP tool#47
hodgesds wants to merge 2 commits into
facebookexperimental:mainfrom
hodgesds:feature/rust-analyzer-integration

Conversation

@hodgesds

Copy link
Copy Markdown

Adds rust-analyzer-backed symbol lookup to semcode. When the indexed repository
is a Rust project (has a Cargo.toml), semcode spawns rust-analyzer as a
background LSP process and exposes a new find_rust_symbol MCP tool that answers
workspace/symbol queries using rust-analyzer's exact type inference — more
precise than the tree-sitter index for Rust code.

What's included

Async JSON-RPC rust-analyzer client (src/rust_analyzer.rs)

  • Spawns rust-analyzer over stdio with LSP Content-Length framing, dedicated
    sender/reader tasks, and request routing via a oneshot map.
  • Spawned with kill_on_drop and the handle retained, so the process is
    terminated with the client instead of being orphaned.
  • 30s per-request timeout so a wedged/dead server can't hang callers.
  • Returns the unwrapped JSON-RPC result to callers.

DatabaseManager integration (src/database/connection.rs)

  • attach_rust_analyzer() starts the client only when a Cargo.toml is present;
    the query, LSP, and MCP binaries attach on startup (MCP attaches in the
    background to avoid blocking init).

find_rust_symbol MCP tool (src/bin/semcode-mcp.rs)

  • New tool in the code_lookup category with schema and dispatch.
  • Empty results return an "indexing may still be in progress — retry" hint,
    since workspace/symbol returns nothing until rust-analyzer finishes indexing.

Async workdir index (src/workdir.rs, query.rs, semcode-lsp.rs)

  • WorkdirIndex::build[_incremental] and the workdir-refresh paths are now async
    to support the async client.

Testing

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings: clean.
  • cargo test: all passing, including new unit tests for JSON-RPC framing and
    request/notification serialization, and the updated MCP tool-count tests.

hodgesds added 2 commits July 27, 2026 09:53
Spawn rust-analyzer as a background child process (kill_on_drop, 30s
request timeout) and attach it to DatabaseManager on Rust projects.
Make WorkdirIndex::build[_incremental] and the workdir-refresh paths in
query, lsp, and mcp binaries async.
Add the find_rust_symbol MCP tool backed by rust-analyzer's
workspace/symbol lookup, including schema, category, dispatch, and an
indexing-in-progress hint on empty results.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant