@@ -19,6 +19,8 @@ You can also install the hook as a step of running `./x.py setup`!
19
19
20
20
## Configuring ` rust-analyzer ` for ` rustc `
21
21
22
+ ### Visual Studio Code
23
+
22
24
` rust-analyzer ` can help you check and format your code whenever you save
23
25
a file. By default, ` rust-analyzer ` runs the ` cargo check ` and ` rustfmt `
24
26
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
27
29
This will ask ` rust-analyzer ` to use ` ./x.py check ` to check the sources, and the
28
30
stage 0 rustfmt to format them.
29
31
32
+ If you have enough free disk space and you would like to be able to run ` x.py ` commands while
33
+ rust-analyzer runs in the background, you can also add ` --build-dir build-rust-analyzer ` to the
34
+ ` overrideCommand ` to avoid x.py locking.
30
35
31
- For Neovim users there are several options for configuring for rustc. The easiest way is by using
32
- [ nlsp-settings] ( https://github.com/tamago324/nlsp-settings.nvim ) , which allows for project-local
33
- configuration files with the native LSP. The steps for how to use it are below.
36
+ If running ` ./x.py check ` on save is inconvenient, in VS Code you can use a [ Build
37
+ Task] instead:
34
38
35
- 1 . First install the plugin
36
- 2 . Run ` :LspSettings local rust_analyzer ` while the rust repo is open.
39
+ ``` JSON
40
+ // .vscode/tasks.json
41
+ {
42
+ "version" : " 2.0.0" ,
43
+ "tasks" : [
44
+ {
45
+ "label" : " ./x.py check" ,
46
+ "command" : " ./x.py check" ,
47
+ "type" : " shell" ,
48
+ "problemMatcher" : " $rustc" ,
49
+ "presentation" : { "clear" : true },
50
+ "group" : { "kind" : " build" , "isDefault" : true }
51
+ }
52
+ ]
53
+ }
54
+ ```
55
+
56
+ [ Build Task ] : https://code.visualstudio.com/docs/editor/tasks
37
57
38
- This will create and open a JSON file to put the above JSON in.
39
58
40
- 3 . Open a Rust buffer that causes Rust Analyzer to attach.
41
- 4 . Run ` :LspSettings update rust_analyzer `
59
+ ### Neovim
42
60
43
- The final step must be repeated every time you open Neovim after you open a Rust buffer.
61
+ For Neovim users there are several options for configuring for rustc. The easiest way is by using
62
+ [ neoconf.nvim] ( https://github.com/folke/neoconf.nvim/ ) , which allows for project-local
63
+ configuration files with the native LSP. The steps for how to use it are below. Note that requires
64
+ Rust-Analyzer to already be configured with Neovim. Steps for this can be
65
+ [ found here] ( https://rust-analyzer.github.io/manual.html#nvim-lsp ) .
66
+
67
+ 1 . First install the plugin. This can be done by following the steps in the README.
68
+ 2 . Run ` x.py setup ` , which will have a prompt for it to create a ` .vscode/settings.json ` file. ` neoconf `
69
+ is able to read and update Rust-Analyzer settings automatically when the project is opened when this
70
+ file is detected.
71
+
72
+ If you're running ` coc.nvim ` , you can use ` :CocLocalConfig ` to create a
73
+ ` .vim/coc-settings.json ` and copy the settings from
74
+ [ this file] ( https://github.com/rust-lang/rust/blob/master/src/etc/vscode_settings.json ) .
44
75
45
76
Another way is without a plugin, and creating your own logic in your configuration. The required
46
77
Lua for doing so is below.
@@ -78,35 +109,6 @@ Lua for doing so is below.
78
109
}
79
110
```
80
111
81
- If you're running ` coc.nvim ` , you can use ` :CocLocalConfig ` to create a
82
- ` .vim/coc-settings.json ` and copy the settings from [ this file] ( https://github.com/rust-lang/rust/blob/master/src/etc/vscode_settings.json ) .
83
-
84
- If you have enough free disk space and you would like to be able to run ` x.py ` commands while
85
- rust-analyzer runs in the background, you can also add ` --build-dir build-rust-analyzer ` to the
86
- ` overrideCommand ` to avoid x.py locking.
87
-
88
- If running ` ./x.py check ` on save is inconvenient, in VS Code you can use a [ Build
89
- Task] instead:
90
-
91
- ``` JSON
92
- // .vscode/tasks.json
93
- {
94
- "version" : " 2.0.0" ,
95
- "tasks" : [
96
- {
97
- "label" : " ./x.py check" ,
98
- "command" : " ./x.py check" ,
99
- "type" : " shell" ,
100
- "problemMatcher" : " $rustc" ,
101
- "presentation" : { "clear" : true },
102
- "group" : { "kind" : " build" , "isDefault" : true }
103
- }
104
- ]
105
- }
106
- ```
107
-
108
- [ Build Task ] : https://code.visualstudio.com/docs/editor/tasks
109
-
110
112
## Check, check, and check again
111
113
112
114
When doing simple refactorings, it can be useful to run ` ./x.py check `
0 commit comments