Rust
Rust support is built in.
| Feature | Provided by |
|---|---|
| Language server | rust-analyzer |
| Formatting | rustfmt, through rust-analyzer. Format on save is on by default. |
| Debugging | CodeLLDB |
Install Rust with rustup so that cargo and rustfmt are available.
Which rust-analyzer runs
Tyrn looks in this order:
- The one from a toolchain override in your project, through
rustup. - A
rust-analyzeron yourPATH. - A copy it downloads and keeps up to date.
To use a specific binary, or to ignore the one on your PATH:
{ "lsp": { "rust-analyzer": { "binary": { "path": "/Users/me/bin/rust-analyzer", "arguments": [] } } }}binary.path must be an absolute path. Use "ignore_system_version": true under binary to always use the downloaded copy, and "fetch": { "pre_release": true } to follow nightly releases.
Configure rust-analyzer
Options go in initialization_options. They merge with Tyrn’s defaults.
{ "lsp": { "rust-analyzer": { "initialization_options": { "check": { "command": "clippy" }, "cargo": { "allTargets": false }, "inlayHints": { "lifetimeElisionHints": { "enable": "skip_trivial", "useParameterNames": true }, "closureReturnTypeHints": { "enable": "always" } } } } }}Show inlay hints by setting inlay_hints.enabled to true.
Use a separate target directory
By default rust-analyzer and cargo build can fight over the target folder lock. Give rust-analyzer its own:
{ "lsp": { "rust-analyzer": { "initialization_options": { "rust": { "analyzerTargetDir": true } } } }}true uses target/rust-analyzer. You can also give a path as a string.
Large projects
For big workspaces, trade some diagnostics for speed:
{ "lsp": { "rust-analyzer": { "initialization_options": { "checkOnSave": false, "cargo": { "allTargets": false }, "check": { "workspace": false } } } }}Several Cargo projects
Tell rust-analyzer about projects that are not in one workspace:
{ "lsp": { "rust-analyzer": { "initialization_options": { "linkedProjects": ["./a/Cargo.toml", "./b/Cargo.toml"] } } }}Tasks and tests
Tyrn marks runnable code, such as main and tests, with a run indicator. Run it from the code actions menu (cmd-.) or from the task list (cmd-shift-r). Tasks that rust-analyzer provides are included. Set lsp.rust-analyzer.enable_lsp_tasks to false to hide them. See Tasks.
Debugging
Press f4 and pick a configuration for your binary or test. To set environment variables for the adapter, use dap.CodeLLDB.env:
{ "dap": { "CodeLLDB": { "env": { "RUST_LOG": "info" } } }}See Debugger.