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. Just omit the leading rust-analyzer. outer object when you’re putting stuff into the toml here.

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
[language-server.rust-analyzer.config.check]
command = "clippy"

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