diff options
Diffstat (limited to 'docs')
-rw-r--r-- | docs/dev/README.md | 5 | ||||
-rw-r--r-- | docs/user/README.md | 63 | ||||
-rw-r--r-- | docs/user/assists.md | 18 |
3 files changed, 59 insertions, 27 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md index 0f64d7e5f..2f6215d6b 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md | |||
@@ -124,9 +124,8 @@ Logging is done by both rust-analyzer and VS Code, so it might be tricky to | |||
124 | figure out where logs go. | 124 | figure out where logs go. |
125 | 125 | ||
126 | Inside rust-analyzer, we use the standard `log` crate for logging, and | 126 | Inside rust-analyzer, we use the standard `log` crate for logging, and |
127 | `flexi_logger` for logging frotend. By default, log goes to stderr (the same as | 127 | `env_logger` for logging frontend. By default, log goes to stderr, but the |
128 | with `env_logger`), but the stderr itself is processed by VS Code. To mirror | 128 | stderr itself is processed by VS Code. |
129 | logs to a `./log` directory, set `RA_LOG_DIR=1` environmental variable. | ||
130 | 129 | ||
131 | To see stderr in the running VS Code instance, go to the "Output" tab of the | 130 | To see stderr in the running VS Code instance, go to the "Output" tab of the |
132 | panel and select `rust-analyzer`. This shows `eprintln!` as well. Note that | 131 | panel and select `rust-analyzer`. This shows `eprintln!` as well. Note that |
diff --git a/docs/user/README.md b/docs/user/README.md index 1b2d98608..968d2e34c 100644 --- a/docs/user/README.md +++ b/docs/user/README.md | |||
@@ -1,14 +1,19 @@ | |||
1 | The main interface to rust-analyzer is the | 1 | The main interface to rust-analyzer is the |
2 | [LSP](https://microsoft.github.io/language-server-protocol/) implementation. To | 2 | [LSP](https://microsoft.github.io/language-server-protocol/) implementation. To |
3 | install lsp server, use `cargo xtask install --server`, which is a shorthand for `cargo | 3 | install lsp server, clone the repository and then run `cargo xtask install |
4 | install --package ra_lsp_server`. The binary is named `ra_lsp_server`, you | 4 | --server` (which is shorthand for `cargo install --path |
5 | should be able to use it with any LSP-compatible editor. We use custom | 5 | ./crates/ra_lsp_server`). This will produce a binary named `ra_lsp_server` which |
6 | you should be able to use it with any LSP-compatible editor. We use custom | ||
6 | extensions to LSP, so special client-side support is required to take full | 7 | extensions to LSP, so special client-side support is required to take full |
7 | advantage of rust-analyzer. This repository contains support code for VS Code | 8 | advantage of rust-analyzer. This repository contains support code for VS Code |
8 | and Emacs. | 9 | and Emacs. |
9 | 10 | ||
10 | Rust Analyzer needs sources of rust standard library to work, so you might need | 11 | ``` |
11 | to execute | 12 | $ git clone [email protected]:rust-analyzer/rust-analyzer && cd rust-analyzer |
13 | $ cargo xtask install --server | ||
14 | ``` | ||
15 | Rust Analyzer needs sources of rust standard library to work, so | ||
16 | you might also need to execute | ||
12 | 17 | ||
13 | ``` | 18 | ``` |
14 | $ rustup component add rust-src | 19 | $ rustup component add rust-src |
@@ -133,43 +138,31 @@ Prerequisites: | |||
133 | Installation: | 138 | Installation: |
134 | 139 | ||
135 | * add | 140 | * add |
136 | [ra-emacs-lsp.el](https://github.com/rust-analyzer/rust-analyzer/blob/69ee5c9c5ef212f7911028c9ddf581559e6565c3/editors/emacs/ra-emacs-lsp.el) | 141 | [ra-emacs-lsp.el](../../editors/emacs/ra-emacs-lsp.el) |
137 | to load path and require it in `init.el` | 142 | to load path and require it in `init.el` |
138 | * run `lsp` in a rust buffer | 143 | * run `lsp` in a rust buffer |
139 | * (Optionally) bind commands like `rust-analyzer-join-lines`, `rust-analyzer-extend-selection` and `rust-analyzer-expand-macro` to keys, and enable `rust-analyzer-inlay-hints-mode` to get inline type hints | 144 | * (Optionally) bind commands like `rust-analyzer-join-lines`, `rust-analyzer-extend-selection` and `rust-analyzer-expand-macro` to keys, and enable `rust-analyzer-inlay-hints-mode` to get inline type hints |
140 | 145 | ||
141 | 146 | ||
142 | ## Vim and NeoVim | 147 | ## Vim and NeoVim (coc-rust-analyzer) |
143 | 148 | ||
144 | Neovim 0.5 has a built in language server. For a quick start configuration of | 149 | * Install coc.nvim by following the instructions at [coc.nvim][] (nodejs required) |
145 | rust-analyzer, use [neovim/nvim-lsp](https://github.com/neovim/nvim-lsp#rust_analyzer). | 150 | * Run `:CocInstall coc-rust-analyzer` to install [coc-rust-analyzer], this extension implements _most_ of the features supported in the VSCode extension: |
146 | Once `neovim/nvim-lsp` is installed, you can use `call nvim_lsp#setup("rust_analyzer", {})` | ||
147 | or `lua require'nvim_lsp'.rust_analyzer.setup({})` to quickly get set up. | ||
148 | |||
149 | * Install coc.nvim by following the instructions at [coc.nvim] | ||
150 | - You will need nodejs installed. | ||
151 | - You may want to include some of the sample vim configurations [from here][coc-vim-conf] | ||
152 | - Note that if you use a plugin manager other than `vim-plug`, you may need to manually | ||
153 | checkout the `release` branch wherever your plugin manager cloned it. Otherwise you will | ||
154 | get errors about a missing javascript file. | ||
155 | * Run `:CocInstall coc-rust-analyzer` to install [coc-rust-analyzer], this extension implemented _most_ of the features supported in the VSCode extension: | ||
156 | - same configurations as VSCode extension, `rust-analyzer.raLspServerPath`, `rust-analyzer.enableCargoWatchOnStartup` etc. | 151 | - same configurations as VSCode extension, `rust-analyzer.raLspServerPath`, `rust-analyzer.enableCargoWatchOnStartup` etc. |
157 | - same commands too, `rust-analyzer.analyzerStatus`, `rust-analyzer.startCargoWatch` etc. | 152 | - same commands too, `rust-analyzer.analyzerStatus`, `rust-analyzer.startCargoWatch` etc. |
158 | - highlighting and inlay_hints are not implemented yet | 153 | - highlighting and inlay_hints are not implemented yet |
159 | 154 | ||
160 | [coc.nvim]: https://github.com/neoclide/coc.nvim | 155 | [coc.nvim]: https://github.com/neoclide/coc.nvim |
161 | [coc-vim-conf]: https://github.com/neoclide/coc.nvim/#example-vim-configuration | ||
162 | [coc-rust-analyzer]: https://github.com/fannheyward/coc-rust-analyzer | 156 | [coc-rust-analyzer]: https://github.com/fannheyward/coc-rust-analyzer |
163 | 157 | ||
164 | ## Vim and NeoVim Alternative | 158 | ## Vim and NeoVim (LanguageClient-neovim) |
165 | 159 | ||
166 | * Install LanguageClient-neovim by following the instructions [here][lang-client-neovim] | 160 | * Install LanguageClient-neovim by following the instructions [here][lang-client-neovim] |
167 | - No extra run-time is required as this server is written in Rust | ||
168 | - The github project wiki has extra tips on configuration | 161 | - The github project wiki has extra tips on configuration |
169 | 162 | ||
170 | * Configure by adding this to your vim/neovim config file (replacing the existing rust specific line if it exists): | 163 | * Configure by adding this to your vim/neovim config file (replacing the existing rust specific line if it exists): |
171 | 164 | ||
172 | ``` | 165 | ```vim |
173 | let g:LanguageClient_serverCommands = { | 166 | let g:LanguageClient_serverCommands = { |
174 | \ 'rust': ['ra_lsp_server'], | 167 | \ 'rust': ['ra_lsp_server'], |
175 | \ } | 168 | \ } |
@@ -177,6 +170,13 @@ let g:LanguageClient_serverCommands = { | |||
177 | 170 | ||
178 | [lang-client-neovim]: https://github.com/autozimu/LanguageClient-neovim | 171 | [lang-client-neovim]: https://github.com/autozimu/LanguageClient-neovim |
179 | 172 | ||
173 | ## NeoVim (nvim-lsp) | ||
174 | |||
175 | NeoVim 0.5 (not yet released) has built in language server support. For a quick start configuration | ||
176 | of rust-analyzer, use [neovim/nvim-lsp](https://github.com/neovim/nvim-lsp#rust_analyzer). | ||
177 | Once `neovim/nvim-lsp` is installed, you can use `call nvim_lsp#setup("rust_analyzer", {})` | ||
178 | or `lua require'nvim_lsp'.rust_analyzer.setup({})` to quickly get set up. | ||
179 | |||
180 | 180 | ||
181 | ## Sublime Text 3 | 181 | ## Sublime Text 3 |
182 | 182 | ||
@@ -208,4 +208,19 @@ Installation: | |||
208 | 208 | ||
209 | * You can now invoke the command palette and type LSP enable to locally/globally enable the rust-analyzer LSP (type LSP enable, then choose either locally or globally, then select rust-analyzer) | 209 | * You can now invoke the command palette and type LSP enable to locally/globally enable the rust-analyzer LSP (type LSP enable, then choose either locally or globally, then select rust-analyzer) |
210 | 210 | ||
211 | * Note that `ra_lsp_server` binary must be in `$PATH` for this to work. If it's not the case, you can specify full path to the binary, which is typically `.cargo/bin/ra_lsp_server`. | 211 | ### Setting up the `PATH` variable |
212 | |||
213 | On Unix systems, `rustup` adds `~/.cargo/bin` to `PATH` by modifying the shell's | ||
214 | startup file. Depending on your configuration, your Desktop Environment might not | ||
215 | actually load it. If you find that `rust-analyzer` only runs when starting the | ||
216 | editor from the terminal, you will have to set up your `PATH` variable manually. | ||
217 | |||
218 | There are a couple of ways to do that: | ||
219 | |||
220 | - for Code, set `rust-analyzer.raLspServerPath` to `~/.cargo/bin` (the `~` is | ||
221 | automatically resolved by the extension) | ||
222 | - copy the binary to a location that is already in `PATH`, e.g. `/usr/local/bin` | ||
223 | - on Linux, use PAM to configure the `PATH` variable, by e.g. putting | ||
224 | `PATH DEFAULT=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:@{HOME}/.cargo/bin:@{HOME}/.local/bin` | ||
225 | in your `~/.pam_environment` file; note that this might interfere with other | ||
226 | defaults set by the system administrator via `/etc/environment`. | ||
diff --git a/docs/user/assists.md b/docs/user/assists.md index 6f4c30bee..334ba450f 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md | |||
@@ -3,6 +3,24 @@ | |||
3 | Cursor position or selection is signified by `┃` character. | 3 | Cursor position or selection is signified by `┃` character. |
4 | 4 | ||
5 | 5 | ||
6 | ## `add_custom_impl` | ||
7 | |||
8 | Adds impl block for derived trait. | ||
9 | |||
10 | ```rust | ||
11 | // BEFORE | ||
12 | #[derive(Deb┃ug, Display)] | ||
13 | struct S; | ||
14 | |||
15 | // AFTER | ||
16 | #[derive(Display)] | ||
17 | struct S; | ||
18 | |||
19 | impl Debug for S { | ||
20 | |||
21 | } | ||
22 | ``` | ||
23 | |||
6 | ## `add_derive` | 24 | ## `add_derive` |
7 | 25 | ||
8 | Adds a new `#[derive()]` clause to a struct or enum. | 26 | Adds a new `#[derive()]` clause to a struct or enum. |