--- name: codex-lsp-rust description: Use codex-lsp with Rust Cargo workspaces for semantic navigation, feature-aware diagnostics and verified refactors, including examples and macro-heavy crates. --- Use [shared CLI essentials](../codex-lsp/SKILL.md) once for commands, output and edit boundaries. Keep Rust setup and verification tied to the actual Cargo target. ## Cargo membership and analysis Discover manifests and target kinds before choosing a probe or run command: ```sh cargo metadata --no-deps --format-version 1 ``` Read the matching package's `manifest_path` and targets' `kind`, `name`, `src_path` and `required-features`. Workspace directories named `examples` can themselves be packages. Auto examples normally live at `/examples/NAME.rs`; a flat file beside explicitly listed examples needs its own target registration. Confirm a newly created file appears in metadata before asking RA to rename it. Dev dependencies are available to examples/tests; an ordinary bin can lack them. Use the discovered target: `cargo run -p PACKAGE --example NAME`, `--bin NAME`, or `cargo test --manifest-path PATH`, with its required features. Preserve existing manifests when an auto-discovered target suffices. `doctor --file PATH` reports the nearest analysis root. Cargo workspace, excluded example and Git edit boundaries can differ. Install the required toolchain/dependencies explicitly; LSP subprocesses disable implicit rustup installation. If Cargo.lock exists, use `cargo metadata --locked` for dependency failures; allow an initial unlocked run when it is absent. ## Query and verify Use `lint --file PATH --tool clippy` for Cargo/Clippy diagnostics and `format --file PATH --tool rustfmt --check` for project-edition formatting. Prepare locked dependencies and the installed toolchain first. Clippy selects the source's Cargo target and shares runs for files in the same target with the same features. Inspect `checked[].providers[].cargo` for that build context. Configure required features in the existing `.codex/lsp.json` rust-analyzer settings, e.g. `{"rust-analyzer":{"settings":{"rust-analyzer":{"cargo":{"features":["full"]}}}}}` for a project declaring `full`; `features:"all"` and `noDefaultFeatures:true` also work. Keep existing settings when editing. Default features leave inactive `cfg` branches outside compiler checks. Save machine-applicable lint fixes or format edits with `--plan PATH.json`, review, then apply; verify the actual Cargo target afterwards. See [lint/format workflows](../codex-lsp/references/tooling.md). `snippet --file PATH --line N --symbol NAME` reads the enclosing Rust item without Cargo/RA startup. It shows source syntax before macro expansion. `signature-help --symbol NAME` belongs on a call-site line; ast-grep handles qualified/turbofish calls and picks that call's arguments. Use an explicit column for later active parameters. For local bindings, find the current line with snippet/ast-grep and use `hover --symbol NAME`; document-symbol results follow the server's item outline. Use `types --view computed|declared|expected --fields summary` for a focused semantic type answer. `setup rust-types` checks the optional Cargo-installed native helper and gives installation guidance. Select a complete argument/RHS expression for `expected`; check `expectedSource`, `incomplete` and the helper's disabled build-script/proc-macro scope. `type.adjusted` is separate from the original computed type. Read [Rust type queries](../codex-lsp/references/rust-types.md) for Cargo settings, supported contexts and session invalidation. Snippets preserve attached outer attributes such as `cfg` and `must_use`. From a declaration anchor, find a call with `references` or `ast-grep run --lang Rust --pattern '$RECV.method($$$ARGS)' FILE` before requesting a signature; replace `method` with the intended method name. AST search excludes documentation examples. Nearby call-name hints identify syntax matches, so check their receivers. Macro bodies can expose token trees without parsed calls. If automatic signature selection explains this limit, use an explicit column after the call's `(`. RA can still have no semantic signature for a macro template; inspect the expanded call or the trait/function declaration in that case. For an isolated clone, preserve any existing ignored `Cargo.lock` and required generated files from the prepared checkout; Git cloning omits them. Check dependency preparation before retrying an indexing timeout. Large cold workspaces may need `--timeout 120`. Use inspect to share startup for related questions. A no-reference response warrants checking the declaration, target membership and enabled cfg/features. For macros/generated code, check build scripts and Cargo health before trusting an empty result. Read [derived implementations](references/derives.md) for derive imports and generated names. For repeated handle queries, use one `session --stdio --targets`; separate CLI calls each start a fresh rust-analyzer. Watch an existing Cargo target or register a temporary probe before expecting diagnostic deltas. A quickfix without `isPreferred` can be reviewed and explicitly selected with `fix --file ... --kind quickfix --query INDEX --plan ...`. Check `applied` and `applicationState` even if output formatting fails. API diff reports public syntax; dependency `use`/`mod` paths still require the relevant cfg/features. Read [continuous workflows](../codex-lsp/references/workflows.md). Rust diagnostics enable Cargo check. Match `settings.rust-analyzer.cargo.features` and `noDefaultFeatures` to the intended build/test configuration. Verify a rename with the relevant Cargo target and check that tests actually run; inactive cfg hints or a zero-test run leave that branch untested.