As there is no specific editor for Rust development on Fuchsia,
VS Code are the
most popular options. However, documentation for setting up any editor is welcome in this document.
rust-analyzer uses a file in the
out/ directory called
rust-project.json that is
generated based on the build graph at
gn gen time. A symlink to the
rust-project.json is located
in the root directory of the Fuchsia tree.
rust-project.json file format is currently unstable. Sometimes this can cause an
unexpected version mismatch where GN produces a
not expecting, causing
rust-analyzer to not work correctly.
Currently supported version
Currently, use the latest version of
Visual Studio Code
rust-analyzer on VS Code, see the VS Code guide
Additional Vs Code extensions for Fuchsia.
rust-lang/rust.vim, which also integrates with:
Tagbar: universal-ctags is strongly recommended, but other ctags implementations are also supported.
cargoas a syntax checker for Rust. Yet it will fail unless you set up cargo. If you want to disable the integration (or use
rust-analyzerto check the code, e.g. via YouCompleteMe), add the following to your
let g:syntastic_rust_checkers = 
Auto formatting: to run
rustfmton save (disabled by default), add the following to
let g:rustfmt_command = 'FUCHSIA_DIR/prebuilt/third_party/rust/HOST_OS/bin/rustfmt' let g:rustfmt_autosave = 1
For IDE support, see the vim section of the rust-analyzer
manual. For YouCompleteMe, add
--all) if you are installing from source, and it should work out of the
box. You can also specify the path to a standalone
rust-analyzer in your
~/.vimrc (this is not
guaranteed to work due to version compatibility); here is an example assuming it is installed to
~/.local/bin/rust-analyzer (note the intentional absence of
/bin in the path):
let g:ycm_rust_toolchain_root = $HOME . '/.local'
See the rust-analyzer manual for instructions.
Check on save
You will be using flycheck to compile your Rust files when you save them. flycheck will parse those outputs and highlight errors. You'll also use flycheck-rust so that it will compile with cargo and not with rustc. Both are available from melpa.
Note that this workflow is based on cargo, which is more likely to break than rust-analyzer based workflows.
If you don't yet have melpa, follow the instructions here.
M-x list-packages. Type
to queue for installation what you are missing and then
x to execute.
Next, make sure that flycheck-rust is run at startup. Put this in your
(with-eval-after-load 'rust-mode (add-hook 'flycheck-mode-hook #'flycheck-rust-setup))
You'll want cargo to run "check" and not "test" so set
nil. You can do this by typing
flycheck-rust-check-tests<RET> and then customizing the variable in the normal
Now, you'll want to make sure that the default
rustc that you are
using are Fuchsia versions of those. If you haven't already,
install rustup. Then, from your Fuchsia root, type:
rustup toolchain link fuchsia FUCHSIA_DIR/prebuilt/third_party/rust/HOST_OS rustup default fuchsia
Finally, follow the steps to generate a
Cargo.toml for the GN target that you
want to work on.
You can read about
adjusting flycheck to display your errors as you like. Type
flycheck-highlighting-mode<RET> and customize it. Also customize
Now restart emacs and try it out.
Test and debug
To test that it works, you can run
M-x flycheck-compile and see the
command-line that flycheck is using to check syntax. It ought to look like one
of these depending on whether you are in a lib or bin:
cargo check --lib --message-format\=json cargo check --bin recovery_netstack --message-format\=json
If it runs
rustc instead of
cargo, that's because you didn't
Note that it might report errors on the first line of the current file. Those are actually errors from a different file. The error's comment will name the problematic file.
Using Rust-Enhanced for syntax checking
Follow the instructions to generate
.cargo/config, which will also
cargo to use the Fuchsia Rust toolchain.
Then, install the Rust Enhanced plugin.
Now, you should have syntax checking on save and be able to run
cargo check from the
context menu / command palette. Thanks to
fargo, some tests also appear to run OK, but this
hasn't been thoroughly tested.
Using a language server for intellisense / hover tooltips / go-to-definition
In order for the language server to work, you need to open a folder that contains a
as the root of your Sublime project. There are two ways you can do this:
- Open a new Sublime window for the folder that contains the
- Or, go to the top menu bar -> Project -> Add Folder to Project. This will keep all your files
inside one Sublime window, and works even if you have the broader
fuchsiafolder also open.
You may need to restart Sublime after these steps.
Intellij (Custom code completion)
See instructions on the Intellij Rust site.
Finally, follow these steps to generate a
Cargo.toml file for use by Intellij.
Note that cargo-based workflows are more likely to break than rust-analyzer based ones.