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