Enable Crate Features in Helix Editor With rust-analyzer

Published , with updates on

So you’re using helix, you’re working on a rust crate, and you need to turn a feature flag on. Here’s how:

[[language]]
name = "rust"
[language-server.rust-analyzer.config.cargo]
features = [ "some_feature" ]

This will enable the feature! Restart helix (or reload config + restart lsp) and you’re good to go. You can also configure anything else you can find in rust-analyzer’s config docs because the config object is just passed right on in to rust-analyzer as json. Note that anywhere rust-analyzer’s docs write the rust-analyzer. prefix, you instead want language-server.rust-analyzer.config. in your toml.

For example, here’s what i have in my global languages.toml, to let rust-analyzer run longer and to use clippy:

[[language]]
name = "rust"
[language-server.rust-analyzer]
timeout = 120

# rust-analyzer docs specify this as `rust-analyzer.check.command`
[language-server.rust-analyzer.config.check]
command = "clippy"

If you want, you can also use .helix/ to configure other helix settings on a per-project basis like disabling autoformat or setting indent levels or whatever.