1# rust-analyzer-chromiumos-wrapper 2 3## Intro 4 5rust-analyzer is an LSP server for the Rust language. It allows editors like 6vim, emacs, or VS Code to provide IDE-like features for Rust. 7 8This program, `rust-analyzer-chromiumos-wrapper`, is a wrapper around 9`rust-analyzer`. It exists to translate paths between an instance of 10rust-analyzer running inside the chromiumos chroot and a client running outside 11the chroot. 12 13It is of course possible to simply run `rust-analyzer` outside the chroot, but 14version mismatch issues may lead to a suboptimal experience. 15 16It should run outside the chroot. If invoked in a `chromiumos` repo in a 17subdirectory of either `chromiumos/src` or `chromiumos/chroot`, it will attempt 18to invoke `rust-analyzer` inside the chroot and translate paths. Otherwise, it 19will attempt to invoke a `rust-analyzer` outside the chroot and will not 20translate paths. 21 22It only supports a limited set of rust-analyzer's command line options, which 23aren't necessary for acting as a LSP server anyway. 24 25## Quickstart 26 27*Outside* the chroot, install the `rust-analyzer-chromiumos-wrapper` binary: 28 29``` 30cargo install --path /path-to-a-chromiumos-checkout/src/third_party/toolchain-utils/rust-analyzer-chromiumos-wrapper 31``` 32 33Make sure `~/.cargo/bin` is in your PATH, or move/symlink 34`~/.cargo/bin/rust-analyzer-chromiumos-wrapper` to a location in your PATH. 35 36Configure your editor to use the binary `rust-analyzer-chromiumos-wrapper` as 37`rust-analyzer`. This configuration is specific to your editor, but see the 38[Rust analyzer manual] for more about several different editors. 39 40The following sections explain how this can be done for various editors. 41 42[Rust analyzer manual]: https://rust-analyzer.github.io/manual.html 43 44## Neovim 45 46In Neovim, if you're using [nvim-lspconfig], this can be done by 47putting the following in your `init.lua`: 48 49``` 50require('lspconfig')['rust_analyzer'].setup { 51 cmd = {'rust-analyzer-chromiumos-wrapper'}, 52} 53``` 54 55[nvim-lspconfig]: https://github.com/neovim/nvim-lspconfig 56 57## VSCode 58 59In VSCode the [rust-analyzer extension] handles interaction with the LSP. 60After installation, `rust-analyzer` is configured via `settings.json`. To use 61`rust-analyzer-chromiumos-wrapper` for chromiumos, edit the repositories 62`.vscode/settings.json` file. It should be present in any chromiumos checkout 63that you edited with VSCode. 64 65Then add the following line: 66``` 67"rust-analyzer.server.path": "/usr/local/google/home/bkersting/.cargo/bin/rust-analyzer-chromiumos-wrapper" 68``` 69 70Due to having all chromiumos crates distributed in the workspace (and no global 71`Cargo.toml` defining the workspace), the crates you would like edit with 72rust-analyzer need to be declared in the `rust-analyzer.linkedProjects` 73setting. If you e.g. want to work on libchromeos-rs, put the following lines 74into `settings.json`: 75``` 76"rust-analyzer.linkedProjects": [ 77 "/path-to-chromiumos/src/platform2/libchromeos-rs/Cargo.toml", 78] 79``` 80 81[rust-analyzer extension]: https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer 82 83## Misc 84 85Inside chroot we already have a rust-analyzer installation that is installed 86with the rust toolchain. 87 88A wrapper isn't necessary for clangd, because clangd supports the option 89`--path-mappings` to translate paths. In principle a similar option could be 90added to `rust-analyzer`, obviating the need for this wrapper. See this 91[issue on github]. 92 93[issue on github]: https://github.com/rust-lang/rust-analyzer/issues/12485 94