Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Neovim configuration information #1545

Merged
merged 8 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 31 additions & 3 deletions src/building/suggested.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,9 +33,6 @@ If you have enough free disk space and you would like to be able to run `x.py` c
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:

Expand All @@ -56,6 +55,35 @@ Task] instead:

[Build Task]: https://code.visualstudio.com/docs/editor/tasks


### Neovim

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. 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)

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`
Expand Down