diff options
Diffstat (limited to 'docs/user')
-rw-r--r-- | docs/user/assists.md | 22 | ||||
-rw-r--r-- | docs/user/features.md | 4 | ||||
-rw-r--r-- | docs/user/readme.adoc | 77 |
3 files changed, 84 insertions, 19 deletions
diff --git a/docs/user/assists.md b/docs/user/assists.md index 6c6943622..ee515949e 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md | |||
@@ -175,7 +175,9 @@ trait Trait<T> { | |||
175 | } | 175 | } |
176 | 176 | ||
177 | impl Trait<u32> for () { | 177 | impl Trait<u32> for () { |
178 | fn foo(&self) -> u32 { todo!() } | 178 | fn foo(&self) -> u32 { |
179 | todo!() | ||
180 | } | ||
179 | 181 | ||
180 | } | 182 | } |
181 | ``` | 183 | ``` |
@@ -695,3 +697,21 @@ use std::┃collections::HashMap; | |||
695 | // AFTER | 697 | // AFTER |
696 | use std::{collections::HashMap}; | 698 | use std::{collections::HashMap}; |
697 | ``` | 699 | ``` |
700 | |||
701 | ## `unwrap_block` | ||
702 | |||
703 | This assist removes if...else, for, while and loop control statements to just keep the body. | ||
704 | |||
705 | ```rust | ||
706 | // BEFORE | ||
707 | fn foo() { | ||
708 | if true {┃ | ||
709 | println!("foo"); | ||
710 | } | ||
711 | } | ||
712 | |||
713 | // AFTER | ||
714 | fn foo() { | ||
715 | println!("foo"); | ||
716 | } | ||
717 | ``` | ||
diff --git a/docs/user/features.md b/docs/user/features.md index 56d2969fd..b9a365fc1 100644 --- a/docs/user/features.md +++ b/docs/user/features.md | |||
@@ -140,8 +140,8 @@ space or `;` depending on the return type of the function. | |||
140 | When completing a function call, `()` are automatically inserted. If a function | 140 | When completing a function call, `()` are automatically inserted. If a function |
141 | takes arguments, the cursor is positioned inside the parenthesis. | 141 | takes arguments, the cursor is positioned inside the parenthesis. |
142 | 142 | ||
143 | There are postifx completions, which can be triggerd by typing something like | 143 | There are postfix completions, which can be triggered by typing something like |
144 | `foo().if`. The word after `.` determines postifx completion. Possible variants are: | 144 | `foo().if`. The word after `.` determines postfix completion. Possible variants are: |
145 | 145 | ||
146 | - `expr.if` -> `if expr {}` | 146 | - `expr.if` -> `if expr {}` |
147 | - `expr.match` -> `match expr {}` | 147 | - `expr.match` -> `match expr {}` |
diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc index ce5704836..69f5b13d6 100644 --- a/docs/user/readme.adoc +++ b/docs/user/readme.adoc | |||
@@ -23,7 +23,7 @@ https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/readme.adoc | |||
23 | 23 | ||
24 | == Installation | 24 | == Installation |
25 | 25 | ||
26 | In theory, one should be able to just install the server binary and have it automatically work with any editor. | 26 | In theory, one should be able to just install the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>> and have it automatically work with any editor. |
27 | We are not there yet, so some editor specific setup is required. | 27 | We are not there yet, so some editor specific setup is required. |
28 | 28 | ||
29 | Additionally, rust-analyzer needs the sources of the standard library. | 29 | Additionally, rust-analyzer needs the sources of the standard library. |
@@ -57,7 +57,11 @@ To disable this notification put the following to `settings.json` | |||
57 | ---- | 57 | ---- |
58 | ==== | 58 | ==== |
59 | 59 | ||
60 | The server binary is stored in `~/.config/Code/User/globalStorage/matklad.rust-analyzer` (Linux) or in `~/.Library/Application Support/Code/User/globalStorage/matklad.rust-analyzer` (macOS) or in `%APPDATA%\Code\User\globalStorage` (Windows). | 60 | The server binary is stored in: |
61 | |||
62 | * Linux: `~/.config/Code/User/globalStorage/matklad.rust-analyzer` | ||
63 | * macOS: `~/Library/Application Support/Code/User/globalStorage/matklad.rust-analyzer` | ||
64 | * Windows: `%APPDATA%\Code\User\globalStorage` | ||
61 | 65 | ||
62 | Note that we only support the latest version of VS Code. | 66 | Note that we only support the latest version of VS Code. |
63 | 67 | ||
@@ -108,15 +112,26 @@ Here are some useful self-diagnostic commands: | |||
108 | * To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Server Trace` in the panel. | 112 | * To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Server Trace` in the panel. |
109 | * To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open the `Console` tab of VS Code developer tools. | 113 | * To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open the `Console` tab of VS Code developer tools. |
110 | 114 | ||
111 | === Language Server Binary | 115 | === rust-analyzer Language Server Binary |
112 | 116 | ||
113 | Other editors generally require the `rust-analyzer` binary to be in `$PATH`. | 117 | Other editors generally require the `rust-analyzer` binary to be in `$PATH`. |
114 | You can download the pre-built binary from the https://github.com/rust-analyzer/rust-analyzer/releases[releases] page. Typically, you then need to rename the binary for your platform, e.g. `rust-analyzer-mac` if you're on Mac OS, to `rust-analzyer` and make it executable in addition to moving it into a directory in your `$PATH`. | 118 | You can download the pre-built binary from the https://github.com/rust-analyzer/rust-analyzer/releases[releases] page. Typically, you then need to rename the binary for your platform, e.g. `rust-analyzer-mac` if you're on Mac OS, to `rust-analyzer` and make it executable in addition to moving it into a directory in your `$PATH`. |
119 | |||
120 | On Linux to install the `rust-analyzer` binary into `~/.local/bin`, this commands could be used | ||
121 | |||
122 | [source,bash] | ||
123 | ---- | ||
124 | $ curl -L https://github.com/rust-analyzer/rust-analyzer/releases/latest/download/rust-analyzer-linux -o ~/.local/bin/rust-analyzer | ||
125 | $ chmod +x ~/.local/bin/rust-analyzer | ||
126 | ---- | ||
127 | |||
128 | Ensure `~/.local/bin` is listed in the `$PATH` variable. | ||
115 | 129 | ||
116 | Alternatively, you can install it from source using the following command: | 130 | Alternatively, you can install it from source using the following command: |
117 | 131 | ||
118 | [source,bash] | 132 | [source,bash] |
119 | ---- | 133 | ---- |
134 | $ git clone https://github.com/rust-analyzer/rust-analyzer.git && cd rust-analyzer | ||
120 | $ cargo xtask install --server | 135 | $ cargo xtask install --server |
121 | ---- | 136 | ---- |
122 | 137 | ||
@@ -139,28 +154,34 @@ $ yay -S rust-analyzer-bin | |||
139 | 154 | ||
140 | === Emacs | 155 | === Emacs |
141 | 156 | ||
142 | Emacs support is maintained https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-rust.el[upstream]. | 157 | Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. |
158 | |||
159 | Emacs support is maintained as part of the https://github.com/emacs-lsp/lsp-mode[Emacs-LSP] package in https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-rust.el[lsp-rust.el]. | ||
143 | 160 | ||
144 | 1. Install the most recent version of `emacs-lsp` package by following the instructions https://github.com/emacs-lsp/lsp-mode[here]. | 161 | 1. Install the most recent version of `emacs-lsp` package by following the https://github.com/emacs-lsp/lsp-mode[Emacs-LSP instructions]. |
145 | 2. Set `lsp-rust-server` to `'rust-analyzer`. | 162 | 2. Set `lsp-rust-server` to `'rust-analyzer`. |
146 | 3. Run `lsp` in a Rust buffer. | 163 | 3. Run `lsp` in a Rust buffer. |
147 | 4. (Optionally) bind commands like `lsp-rust-analyzer-join-lines`, `lsp-extend-selection` and `lsp-rust-analyzer-expand-macro` to keys. | 164 | 4. (Optionally) bind commands like `lsp-rust-analyzer-join-lines`, `lsp-extend-selection` and `lsp-rust-analyzer-expand-macro` to keys. |
148 | 165 | ||
149 | === Vim | 166 | === Vim/NeoVim |
150 | 167 | ||
151 | The are several LSP client implementations for vim: | 168 | Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. Not needed if the extension can install/update it on its own, coc-rust-analyzer is one example. |
169 | |||
170 | The are several LSP client implementations for vim or neovim: | ||
152 | 171 | ||
153 | ==== coc-rust-analyzer | 172 | ==== coc-rust-analyzer |
154 | 173 | ||
155 | 1. Install coc.nvim by following the instructions at | 174 | 1. Install coc.nvim by following the instructions at |
156 | https://github.com/neoclide/coc.nvim[coc.nvim] | 175 | https://github.com/neoclide/coc.nvim[coc.nvim] |
157 | (nodejs required) | 176 | (Node.js required) |
158 | 2. Run `:CocInstall coc-rust-analyzer` to install | 177 | 2. Run `:CocInstall coc-rust-analyzer` to install |
159 | https://github.com/fannheyward/coc-rust-analyzer[coc-rust-analyzer], | 178 | https://github.com/fannheyward/coc-rust-analyzer[coc-rust-analyzer], |
160 | this extension implements _most_ of the features supported in the VSCode extension: | 179 | this extension implements _most_ of the features supported in the VSCode extension: |
180 | * automatically install and upgrade stable/nightly releases | ||
161 | * same configurations as VSCode extension, `rust-analyzer.serverPath`, `rust-analyzer.cargo.features` etc. | 181 | * same configurations as VSCode extension, `rust-analyzer.serverPath`, `rust-analyzer.cargo.features` etc. |
162 | * same commands too, `rust-analyzer.analyzerStatus`, `rust-analyzer.ssr` etc. | 182 | * same commands too, `rust-analyzer.analyzerStatus`, `rust-analyzer.ssr` etc. |
163 | * highlighting and inlay_hints are not implemented yet | 183 | * inlay hints for method chaining support, _Neovim Only_ |
184 | * semantic highlighting is not implemented yet | ||
164 | 185 | ||
165 | ==== LanguageClient-neovim | 186 | ==== LanguageClient-neovim |
166 | 187 | ||
@@ -180,11 +201,11 @@ let g:LanguageClient_serverCommands = { | |||
180 | ==== YouCompleteMe | 201 | ==== YouCompleteMe |
181 | 202 | ||
182 | 1. Install YouCompleteMe by following the instructions | 203 | 1. Install YouCompleteMe by following the instructions |
183 | https://ycm-core.github.io/YouCompleteMe/#rust-semantic-completion[here] | 204 | https://github.com/ycm-core/lsp-examples#rust-rust-analyzer[here] |
184 | 205 | ||
185 | 2. Configure by adding this to your vim/neovim config file (replacing the existing Rust-specific line if it exists): | 206 | 2. Configure by adding this to your vim/neovim config file (replacing the existing Rust-specific line if it exists): |
186 | + | 207 | + |
187 | [source,vim] | 208 | [source,vim] |
188 | ---- | 209 | ---- |
189 | let g:ycm_language_server = | 210 | let g:ycm_language_server = |
190 | \ [ | 211 | \ [ |
@@ -197,6 +218,21 @@ let g:ycm_language_server = | |||
197 | \ ] | 218 | \ ] |
198 | ---- | 219 | ---- |
199 | 220 | ||
221 | ==== ALE | ||
222 | |||
223 | To add the LSP server to https://github.com/dense-analysis/ale[ale]: | ||
224 | |||
225 | [source,vim] | ||
226 | ---- | ||
227 | call ale#linter#Define('rust', { | ||
228 | \ 'name': 'rust-analyzer', | ||
229 | \ 'lsp': 'stdio', | ||
230 | \ 'executable': 'rust-analyzer', | ||
231 | \ 'command': '%e', | ||
232 | \ 'project_root': '.', | ||
233 | \}) | ||
234 | ---- | ||
235 | |||
200 | ==== nvim-lsp | 236 | ==== nvim-lsp |
201 | 237 | ||
202 | NeoVim 0.5 (not yet released) has built-in language server support. | 238 | NeoVim 0.5 (not yet released) has built-in language server support. |
@@ -205,7 +241,7 @@ Once `neovim/nvim-lsp` is installed, use `+lua require'nvim_lsp'.rust_analyzer.s | |||
205 | 241 | ||
206 | === Sublime Text 3 | 242 | === Sublime Text 3 |
207 | 243 | ||
208 | Prerequisites: You have installed the <<language-server-binary,`rust-analyzer` binary>>. | 244 | Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. |
209 | 245 | ||
210 | You also need the `LSP` package. To install it: | 246 | You also need the `LSP` package. To install it: |
211 | 247 | ||
@@ -214,11 +250,20 @@ You also need the `LSP` package. To install it: | |||
214 | * Type `Install Package Control`, press enter | 250 | * Type `Install Package Control`, press enter |
215 | 2. In the command palette, run `Package control: Install package`, and in the list that pops up, type `LSP` and press enter. | 251 | 2. In the command palette, run `Package control: Install package`, and in the list that pops up, type `LSP` and press enter. |
216 | 252 | ||
217 | Finally, with your Rust project open, in the command palette, run `LSP: Enable Language Server In Project` or `LSP: Enable Language Server Globally`, then select `rust-analyzer` in the list that pops up to enable the rust-analyzer LSP. The latter means that rust-analzyer is enabled by default in Rust projects. | 253 | Finally, with your Rust project open, in the command palette, run `LSP: Enable Language Server In Project` or `LSP: Enable Language Server Globally`, then select `rust-analyzer` in the list that pops up to enable the rust-analyzer LSP. The latter means that rust-analyzer is enabled by default in Rust projects. |
254 | |||
255 | If it worked, you should see "rust-analyzer, Line X, Column Y" on the left side of the bottom bar, and after waiting a bit, functionality like tooltips on hovering over variables should become available. | ||
256 | |||
257 | If you get an error saying `No such file or directory: 'rust-analyzer'`, see the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>> section on installing the language server binary. | ||
258 | |||
259 | === Gnome Builder | ||
260 | |||
261 | Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. | ||
218 | 262 | ||
219 | If it worked, you should see "rust-analzyer, Line X, Column Y" on the left side of the bottom bar, and after waiting a bit, functionality like tooltips on hovering over variables should become available. | 263 | Gnome Builder currently has support for RLS, and there's no way to configure the language server executable. A future version might support `rust-analyzer` out of the box. |
220 | 264 | ||
221 | If you get an error saying `No such file or directory: 'rust-analyzer'`, see the <<language-server-binary,section on installing the language server binary>>. | 265 | 1. Rename, symlink or copy the `rust-analyzer` binary to `rls` and place it somewhere Builder can find (in `PATH`, or under `~/.cargo/bin`). |
266 | 2. Enable the Rust Builder plugin. | ||
222 | 267 | ||
223 | == Usage | 268 | == Usage |
224 | 269 | ||