Introduction
There are many good IDE's for developing in Rust, let's see how to setup Sublime Text for this language.
What we're going to achieve :
- auto completion
- errors / fix suggestions within the editor
- doc information on mouse hover (including external dependencies)
- auto formatting on save
Note: The following configuration has been successfully tested on build 4169.
Configuration
Syntax highlighting and auto formatting
- Open the command palette (Ctrl+Shift+P)
-
Install Package
-->Rust Enhanced
-
Install Package
-->RustFmt
At this stage, syntax highlighting should be enabled, as well as auto formatting on save (otherwise check RustFmt settings under Preferences
--> Package Settings
)
Auto completion and errors / fix suggestions
Firstly, we need the rust-analyzer binary :
rustup component add rust-analyzer
rust-analyzer
needs Rust sources, the easiest way to install them is :
rustup component add rust-src
Note that only the latest version of Rust is fully supported by rust-analyzer, if you need to handle older ones, check this doc
Then we can install LSP (Language Server Protocol) plugins :
- Open the command palette (Ctrl+Shift+P)
-
Install Package
-->LSP
-
Install Package
-->LSP-rust-analyzer
At this stage, you should see a little window containing some documentation on mouse hover (as well as links to the definition, references...), and auto completion should also work for all sources (including external dependencies defined in Cargo.toml
).
If it doesn't work
Important: it only works if you add a folder containing a Cargo.toml
file, a single file alone won't work.
- Open the command palette (Ctrl+Shift+P)
LSP: Restart Server
- Relaunch Sublime Text
Still not working ? Your environment may need a specific configuration, please check the rust-analyzer doc
Top comments (0)