From 92befb7fb885e218e6e262c10c02ff27d3f6b2a6 Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Thu, 5 Jan 2023 22:40:07 -0500 Subject: [PATCH 1/8] Add Neovim configuration information The JSON provided for VSCode works with coc and nlsp-settings. This is verified by https://github.com/fannheyward/coc-rust-analyzer/blob/9d8bdb9290e2a9644367594a1ceed0288506efcd/README.md for coc, and feeding the JSON in to this schema https://github.com/tamago324/nlsp-settings.nvim/blob/215b537cfb3fad7c9c2e352fe47a10698b0993e0/schemas/_generated/rust_analyzer.json for validating nlsp-settings. The Lua translation is straight-forward and is how all rust-analyzer settings must be used with native nvim lsp. --- src/building/suggested.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/building/suggested.md b/src/building/suggested.md index 38801723e..839dcbfe0 100644 --- a/src/building/suggested.md +++ b/src/building/suggested.md @@ -27,6 +27,44 @@ you to create a `.vscode/settings.json` file which will configure Visual Studio This will ask `rust-analyzer` to use `./x.py check` to check the sources, and the stage 0 rustfmt to format them. + +For Neovim users there are several options for configuring for rustc. You can use the native LSP server and make your own logic for changing the rust-analyzer configuration to the above. You can also use [nlsp-settings](https://github.com/tamago324/nlsp-settings.nvim), which allows for project-local configuration files. This plugin allows for the above JSON to be directly put in to a file located at `rust/.nlsp-settings/rust_analyzer.json`. If you use [coc-rust-analyzer](https://github.com/fannheyward/coc-rust-analyzer) you can also use the above JSON, but placed in `rust/.vim/coc-settings.json`. + +Below is the Lua needed to configure the native Neovim LSP the same as the above VSCode configuration + +```lua +{ + ["rust-analyzer"] = { + checkOnSave = { + overrideCommand = { + {"python3", "x.py", "check", "--json-output"} + } + }, + rustfmt = { + overrideCommand = { + {"./build/host/stage0/bin/rustfmt", "--edition=2021"} + } + }, + procMacro = { + server = "./build/host/stage0/libexec/rust-analyzer-proc-macro-srv", + enable = true + }, + cargo = { + buildScripts = { + enable = true, + invocationLocation = "root", + invocationStrategy = "once", + overrideCommand = {"python3", "x.py", "check", "--json-output"} + }, + sysroot = "./build/host/stage0-sysroot" + }, + rustc = { + source = "./Cargo.toml" + } + } +} +``` + If you have enough free disk space and you would like to be able to run `x.py` commands while rust-analyzer runs in the background, you can also add `--build-dir build-rust-analyzer` to the `overrideCommand` to avoid x.py locking. From 1d7bdefc6716f23da545d8fdd3930bf9b8404d0e Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Thu, 5 Jan 2023 22:52:30 -0500 Subject: [PATCH 2/8] Fix line lengths --- src/building/suggested.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/building/suggested.md b/src/building/suggested.md index 839dcbfe0..1f1dfc45a 100644 --- a/src/building/suggested.md +++ b/src/building/suggested.md @@ -28,9 +28,16 @@ This will ask `rust-analyzer` to use `./x.py check` to check the sources, and th stage 0 rustfmt to format them. -For Neovim users there are several options for configuring for rustc. You can use the native LSP server and make your own logic for changing the rust-analyzer configuration to the above. You can also use [nlsp-settings](https://github.com/tamago324/nlsp-settings.nvim), which allows for project-local configuration files. This plugin allows for the above JSON to be directly put in to a file located at `rust/.nlsp-settings/rust_analyzer.json`. If you use [coc-rust-analyzer](https://github.com/fannheyward/coc-rust-analyzer) you can also use the above JSON, but placed in `rust/.vim/coc-settings.json`. - -Below is the Lua needed to configure the native Neovim LSP the same as the above VSCode configuration +For Neovim users there are several options for configuring for rustc. You can use the native LSP +server and make your own logic for changing the rust-analyzer configuration to the above. You can +also use [nlsp-settings](https://github.com/tamago324/nlsp-settings.nvim), which allows for +project-local configuration files. This plugin allows for the above JSON to be directly put in to +a file located at `rust/.nlsp-settings/rust_analyzer.json`. If you use +[coc-rust-analyzer](https://github.com/fannheyward/coc-rust-analyzer) you can also use the above +JSON, but placed in `rust/.vim/coc-settings.json`. + +Below is the Lua needed to configure the native Neovim LSP the same as the above VSCode +configuration ```lua { From 1147d90c3ba32717f7487f2968ded25e85589843 Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Fri, 6 Jan 2023 22:38:37 -0500 Subject: [PATCH 3/8] Removed coc since there is already a section and cleaned up wording. --- src/building/suggested.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/building/suggested.md b/src/building/suggested.md index 1f1dfc45a..f6a3628c2 100644 --- a/src/building/suggested.md +++ b/src/building/suggested.md @@ -28,16 +28,14 @@ This will ask `rust-analyzer` to use `./x.py check` to check the sources, and th stage 0 rustfmt to format them. -For Neovim users there are several options for configuring for rustc. You can use the native LSP -server and make your own logic for changing the rust-analyzer configuration to the above. You can -also use [nlsp-settings](https://github.com/tamago324/nlsp-settings.nvim), which allows for -project-local configuration files. This plugin allows for the above JSON to be directly put in to -a file located at `rust/.nlsp-settings/rust_analyzer.json`. If you use -[coc-rust-analyzer](https://github.com/fannheyward/coc-rust-analyzer) you can also use the above -JSON, but placed in `rust/.vim/coc-settings.json`. +For Neovim users there are several options for configuring for rustc. The easiest way is by using +[nlsp-settings](https://github.com/tamago324/nlsp-settings.nvim), which allows for project-local +configuration files with the native LSP. First install the plugin by however you manage your +plugins. Then run `:LspSettings local rust_analyzer` to create a JSON configuration file. Then +just paste the above JSON in. -Below is the Lua needed to configure the native Neovim LSP the same as the above VSCode -configuration +Another way is without a plugin, and creating your own logic in your configuration. The required +Lua for doing so is below. ```lua { @@ -72,13 +70,13 @@ configuration } ``` +If you're running `coc.nvim`, you can use `:CocLocalConfig` to create a +`.vim/coc-settings.json` and copy the settings from [this file](https://github.com/rust-lang/rust/blob/master/src/etc/vscode_settings.json). + If you have enough free disk space and you would like to be able to run `x.py` commands while rust-analyzer runs in the background, you can also add `--build-dir build-rust-analyzer` to the `overrideCommand` to avoid x.py locking. -If you're running `coc.nvim`, you can use `:CocLocalConfig` to create a -`.vim/coc-settings.json` and copy the settings from [this file](https://github.com/rust-lang/rust/blob/master/src/etc/vscode_settings.json). - If running `./x.py check` on save is inconvenient, in VS Code you can use a [Build Task] instead: From 4431c3dfc76bfa92299c55fa35ac99ebca3fed2a Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Sat, 7 Jan 2023 00:54:46 -0500 Subject: [PATCH 4/8] Make the steps clear First open a Rust buffer Then update RA settings If you don't open a buffer first then nothing will happen. This is because the plugin makes a raw LSP RPC, so RA must be attached. --- src/building/suggested.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/building/suggested.md b/src/building/suggested.md index f6a3628c2..367c7a974 100644 --- a/src/building/suggested.md +++ b/src/building/suggested.md @@ -30,9 +30,17 @@ stage 0 rustfmt to format them. For Neovim users there are several options for configuring for rustc. The easiest way is by using [nlsp-settings](https://github.com/tamago324/nlsp-settings.nvim), which allows for project-local -configuration files with the native LSP. First install the plugin by however you manage your -plugins. Then run `:LspSettings local rust_analyzer` to create a JSON configuration file. Then -just paste the above JSON in. +configuration files with the native LSP. The steps for how to use it are below. + +1. First install the plugin +2. Run `:LspSettings local rust_analyzer` while the rust repo is open. + +This will create and open a JSON file to put the above JSON in. + +3. Open a Rust buffer that causes Rust Analyzer to attach. +4. Run `:LspSettings update rust_analyzer` + +The final step must be repeated every time you open Neovim after you open a Rust buffer. Another way is without a plugin, and creating your own logic in your configuration. The required Lua for doing so is below. From 61a81543b5559c77308f72116fd8da569e67bbd8 Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Thu, 9 Feb 2023 12:03:58 -0500 Subject: [PATCH 5/8] Rebase and update with seperate sections for VSCode and Nvim --- src/building/suggested.md | 78 ++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/src/building/suggested.md b/src/building/suggested.md index 367c7a974..49d070daa 100644 --- a/src/building/suggested.md +++ b/src/building/suggested.md @@ -19,6 +19,8 @@ You can also install the hook as a step of running `./x.py setup`! ## Configuring `rust-analyzer` for `rustc` +### Visual Studio Code + `rust-analyzer` can help you check and format your code whenever you save a file. By default, `rust-analyzer` runs the `cargo check` and `rustfmt` commands, but you can override these commands to use more adapted versions @@ -27,20 +29,49 @@ you to create a `.vscode/settings.json` file which will configure Visual Studio This will ask `rust-analyzer` to use `./x.py check` to check the sources, and the stage 0 rustfmt to format them. +If you have enough free disk space and you would like to be able to run `x.py` commands while +rust-analyzer runs in the background, you can also add `--build-dir build-rust-analyzer` to the +`overrideCommand` to avoid x.py locking. -For Neovim users there are several options for configuring for rustc. The easiest way is by using -[nlsp-settings](https://github.com/tamago324/nlsp-settings.nvim), which allows for project-local -configuration files with the native LSP. The steps for how to use it are below. +If running `./x.py check` on save is inconvenient, in VS Code you can use a [Build +Task] instead: -1. First install the plugin -2. Run `:LspSettings local rust_analyzer` while the rust repo is open. +```JSON +// .vscode/tasks.json +{ + "version": "2.0.0", + "tasks": [ + { + "label": "./x.py check", + "command": "./x.py check", + "type": "shell", + "problemMatcher": "$rustc", + "presentation": { "clear": true }, + "group": { "kind": "build", "isDefault": true } + } + ] +} +``` + +[Build Task]: https://code.visualstudio.com/docs/editor/tasks -This will create and open a JSON file to put the above JSON in. -3. Open a Rust buffer that causes Rust Analyzer to attach. -4. Run `:LspSettings update rust_analyzer` +### Neovim -The final step must be repeated every time you open Neovim after you open a Rust buffer. +For Neovim users there are several options for configuring for rustc. The easiest way is by using +[neoconf.nvim](https://github.com/folke/neoconf.nvim/), which allows for project-local +configuration files with the native LSP. The steps for how to use it are below. Note that requires +Rust-Analyzer to already be configured with Neovim. Steps for this can be +[found here](https://rust-analyzer.github.io/manual.html#nvim-lsp). + +1. First install the plugin. This can be done by following the steps in the README. +2. Run `x.py setup`, which will have a prompt for it to create a `.vscode/settings.json` file. `neoconf` +is able to read and update Rust-Analyzer settings automatically when the project is opened when this +file is detected. + +If you're running `coc.nvim`, you can use `:CocLocalConfig` to create a +`.vim/coc-settings.json` and copy the settings from +[this file](https://github.com/rust-lang/rust/blob/master/src/etc/vscode_settings.json). Another way is without a plugin, and creating your own logic in your configuration. The required Lua for doing so is below. @@ -78,35 +109,6 @@ Lua for doing so is below. } ``` -If you're running `coc.nvim`, you can use `:CocLocalConfig` to create a -`.vim/coc-settings.json` and copy the settings from [this file](https://github.com/rust-lang/rust/blob/master/src/etc/vscode_settings.json). - -If you have enough free disk space and you would like to be able to run `x.py` commands while -rust-analyzer runs in the background, you can also add `--build-dir build-rust-analyzer` to the -`overrideCommand` to avoid x.py locking. - -If running `./x.py check` on save is inconvenient, in VS Code you can use a [Build -Task] instead: - -```JSON -// .vscode/tasks.json -{ - "version": "2.0.0", - "tasks": [ - { - "label": "./x.py check", - "command": "./x.py check", - "type": "shell", - "problemMatcher": "$rustc", - "presentation": { "clear": true }, - "group": { "kind": "build", "isDefault": true } - } - ] -} -``` - -[Build Task]: https://code.visualstudio.com/docs/editor/tasks - ## Check, check, and check again When doing simple refactorings, it can be useful to run `./x.py check` From 4edb74f4b1ff9b4ef26097df5117355b44572e0e Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Thu, 9 Feb 2023 16:21:04 -0500 Subject: [PATCH 6/8] Remove the Lua config The reason this is removed is because the JSON no longer lives in this file, so keeping the two in sync is a higher maintence burden than desired. --- src/building/suggested.md | 45 ++++++--------------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/src/building/suggested.md b/src/building/suggested.md index 49d070daa..aeae5a96c 100644 --- a/src/building/suggested.md +++ b/src/building/suggested.md @@ -65,49 +65,18 @@ Rust-Analyzer to already be configured with Neovim. Steps for this can be [found here](https://rust-analyzer.github.io/manual.html#nvim-lsp). 1. First install the plugin. This can be done by following the steps in the README. -2. Run `x.py setup`, which will have a prompt for it to create a `.vscode/settings.json` file. `neoconf` -is able to read and update Rust-Analyzer settings automatically when the project is opened when this -file is detected. +2. Run `x.py setup`, which will have a prompt for it to create a `.vscode/settings.json` file. +`neoconf` is able to read and update Rust-Analyzer settings automatically when the project is +opened when this file is detected. If you're running `coc.nvim`, you can use `:CocLocalConfig` to create a `.vim/coc-settings.json` and copy the settings from [this file](https://github.com/rust-lang/rust/blob/master/src/etc/vscode_settings.json). -Another way is without a plugin, and creating your own logic in your configuration. The required -Lua for doing so is below. - -```lua -{ - ["rust-analyzer"] = { - checkOnSave = { - overrideCommand = { - {"python3", "x.py", "check", "--json-output"} - } - }, - rustfmt = { - overrideCommand = { - {"./build/host/stage0/bin/rustfmt", "--edition=2021"} - } - }, - procMacro = { - server = "./build/host/stage0/libexec/rust-analyzer-proc-macro-srv", - enable = true - }, - cargo = { - buildScripts = { - enable = true, - invocationLocation = "root", - invocationStrategy = "once", - overrideCommand = {"python3", "x.py", "check", "--json-output"} - }, - sysroot = "./build/host/stage0-sysroot" - }, - rustc = { - source = "./Cargo.toml" - } - } -} -``` +Another way is without a plugin, and creating your own logic in your configuration. To do this you +must translate the JSON to Lua yourself. The translation is 1:1 and fairly straight-forward. It +must be put in the `["rust-analyzer"]` key of the setup table, which is +[shown here](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer) ## Check, check, and check again From 592e23e00eb812a18e6e109083ca926ef9d7e6eb Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Thu, 9 Feb 2023 16:24:21 -0500 Subject: [PATCH 7/8] Add a short section on the VSCode tasks. --- src/building/suggested.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/building/suggested.md b/src/building/suggested.md index aeae5a96c..5a1891503 100644 --- a/src/building/suggested.md +++ b/src/building/suggested.md @@ -78,6 +78,12 @@ must translate the JSON to Lua yourself. The translation is 1:1 and fairly strai must be put in the `["rust-analyzer"]` key of the setup table, which is [shown here](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer) +If you would like to use the build task that is described above, you may either make your own +command in your config, or you can install a plugin such as +[overseer.nvim](https://github.com/stevearc/overseer.nvim) that can [read VSCode's `task.json` +files](https://github.com/stevearc/overseer.nvim/blob/master/doc/guides.md#vs-code-tasks), and +follow the same instructions as above. + ## Check, check, and check again When doing simple refactorings, it can be useful to run `./x.py check` From 17eafb7d6e41a192081555da0063c7764a39b05b Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Thu, 9 Feb 2023 16:37:25 -0500 Subject: [PATCH 8/8] Missing one of the dependencies needed to run --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 006ea3231..e501c9161 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ rustdocs][rustdocs]. To build a local static HTML site, install [`mdbook`](https://github.com/rust-lang/mdBook) with: ``` -> cargo install mdbook mdbook-linkcheck mdbook-toc +> cargo install mdbook mdbook-linkcheck mdbook-toc mdbook-mermaid ``` and execute the following command in the root of the repository: