rust-analyzer-context-indexing
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-10-16
- Stars
- ★ 0
- Forks
- 0
02 资源文件 6
03 SKILL.md 正文
rust-analyzer Context Indexing
Purpose
Build and query code-context indexes for Rust workspaces through rust-analyzer: Cargo metadata-driven crate graph loading, LSP symbol, hover, definition, and reference extraction across crates, traits, and macros, flycheck-gated freshness, and ranked query answers bounded for AI agent consumption.
Use when
- An agent needs accurate Rust definitions, trait implementations, macro expansions, or cross-crate references from a Cargo workspace.
- rust-analyzer rolling 2026-09-01 or newer plus a working
cargo metadatainvocation are available. - Index freshness must survive file edits via rust-analyzer incremental salsa revisions without full workspace reloads.
- Query answers must fit a fixed token budget with deterministic ranking.
Do not use when
- The target language is not Rust; use the matching engine skill instead.
- Only lexical search over
.rsfiles is required with no need for trait resolution, generics, or macro expansion. - The workspace cannot run
cargo metadatasuccessfully, for example missing vendored registries with no network access and no vendor directory.
Required context
- Workspace root,
cargo metadata --format-version 1output, rust-analyzer version, and sysroot source for std symbols. - Token budget for a single query answer: at most 40 symbols and 12000 tokens of emitted context.
- Performance targets: workspace load time, query p95 latency, and the golden symbol recall set.
- Flycheck command used for diagnostics, normally
cargo check --workspace --message-format=json.
Procedure
- Load the crate graph: run
cargo metadata --format-version 1 --no-depsto enumerate packages and targets, then start rust-analyzer withcargo.targetDirset and confirm the status notification reaches ready. Abort indexing if metadata fails; an empty symbol set must never masquerade as an index. - Extract symbols per crate: request
workspace/symbolwith an empty query capped at 500 results per crate for the bulk pass, thentextDocument/documentSymbolper file for hierarchical detail including traits, impl blocks, structs, enums, functions, and macros. - Resolve relations: map
textDocument/hoverfor type signatures,textDocument/definitionfor jump targets, andtextDocument/referenceswithincludeDeclaration: truefor call sites. Record trait-to-impl edges explicitly since they are the highest-value Rust context. - Gate freshness on flycheck: subscribe to
textDocument/publishDiagnosticsfed bycargo check --workspace --message-format=json; documents with errors keep their last-good symbols flagged stale, and salsa revisions advance the index incrementally on each saved change. - Serve ranked queries: expose
symbols --name 'ledger::apply_entry',impls --trait 'LedgerStore', andrefs --symbol <path>with ranking by exact path match, then same-crate proximity, then dependency-distance hops, then recency, truncating at the 40-symbol and 12000-token caps. - Verify against goldens: run
scripts/verify.sh, assert query p95 under 300 ms warm, and require 100% recall on the golden set covering generics, trait objects, async fns, and macro-generated items.
Decision rules
- Metadata first: no
cargo metadata, no index; symbol extraction against a failed crate graph is forbidden. - Stale flags are explicit: symbols from files with flycheck errors are served only with a stale marker, never as fresh truth.
- Trait edges are mandatory: every indexed trait stores its known implementations; a trait without impl edges is an incomplete record.
- Macro expansions recorded:
macro_rules!and derive-generated items are indexed at their expansion sites with the generating macro named. - Bounded answers always: every query path enforces the symbol and token caps even when the caller requests unlimited results.
Evidence required
- Index specification following
templates/rust-analyzer-context-indexing-spec.mdwith metadata output, versions, and flycheck command. - Crate list with per-crate symbol counts and trait-to-impl edge counts.
- Golden recall log with measured query p95 latency.
- Passing execution log from
scripts/verify.sh.
Output contract
- Loaded rust-analyzer workspace with ready status and crate graph report.
- Queryable symbol, reference, trait-implementation, and hover-signature index.
- Freshness report showing stale-flagged files and salsa revision watermark.
Stop conditions
- Golden symbol recall reaches 100% with query p95 under 300 ms on a warm workspace.
- Single-file save propagates through salsa to fresh query results in under 4 seconds.
- Token budget exhausted.
- Blocked on external dependency.
Escalation rules
- Escalate to the Rust build owner if
cargo metadataor flycheck fails due to registry access, missing toolchains, or broken feature unification. - Escalate to the lead architect if proc-macro expansion is nondeterministic or too slow to index within budget, so expansion can be scoped or cached explicitly.
04 同仓库更多 Skills
zoom-reflow
暂无简介
wireframe-styleguide
暂无简介
visual-regression
Pixel-by-pixel snapshot testing, Playwright integration, dynamic content masking, deterministic font rendering, and cross-browser CI gates
ui-implementation
Component-driven UI implementation, multi-state matrix (default, hover, focus-visible, active, disabled, loading, empty, error), DTCG design tokens, responsive layout contracts, and accessibility tree mapping.
tui-editor-engine
Text buffer and editing semantics for a terminal code editor — index conversion, transaction-first editing, multi-cursor invariants, undo grouping, and large-file behaviour.
tree-sitter-context-indexing
暂无简介