diff options
Diffstat (limited to 'docs/user/readme.adoc')
-rw-r--r-- | docs/user/readme.adoc | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc new file mode 100644 index 000000000..553687e78 --- /dev/null +++ b/docs/user/readme.adoc | |||
@@ -0,0 +1,154 @@ | |||
1 | = User Manual | ||
2 | :toc: preamble | ||
3 | :sectanchors: | ||
4 | :page-layout: post | ||
5 | |||
6 | |||
7 | // Master copy of this document lives in the https://github.com/rust-analyzer/rust-analyzer repository | ||
8 | |||
9 | At it's core, rust-analyzer is a *library* for semantic analysis of the Rust code as it changes over time. | ||
10 | This manual focuses on a specific usage of the library -- the implementation of | ||
11 | https://microsoft.github.io/language-server-protocol/[Language Server Protocol]. | ||
12 | LSP allows various code editors, like VS Code, Emacs or Vim, to implement semantic feature like completion or goto definition by talking to an external language server process. | ||
13 | |||
14 | To improve this document, send a pull request against | ||
15 | https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/readme.adoc[this file]. | ||
16 | |||
17 | == Installation | ||
18 | |||
19 | In theory, one should be able to just install the server binary and have it automatically work with any editor. | ||
20 | We are not there yet, so some editor specific setup is required. | ||
21 | |||
22 | === VS Code | ||
23 | |||
24 | This the best supported editor at the moment. | ||
25 | rust-analyzer plugin for VS Code is maintained | ||
26 | https://github.com/rust-analyzer/rust-analyzer/tree/master/editors/code[in tree]. | ||
27 | |||
28 | You can install the latest release of the plugin from | ||
29 | https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer[the marketplace]. | ||
30 | By default, the plugin will download the matching version of the server as well. | ||
31 | |||
32 | // FIXME: update the image (its text has changed) | ||
33 | image::https://user-images.githubusercontent.com/36276403/74103174-a40df100-4b52-11ea-81f4-372c70797924.png[] | ||
34 | |||
35 | The server binary is stored in `~/.config/Code/User/globalStorage/matklad.rust-analyzer`. | ||
36 | |||
37 | Note that we only support the latest version of VS Code. | ||
38 | |||
39 | ==== Updates | ||
40 | |||
41 | The extension will be updated automatically as new versions become available. It will ask your permission to download the matching language server version binary if needed. | ||
42 | |||
43 | ==== Building From Source | ||
44 | |||
45 | Alternatively, both the server and the plugin can be installed from source: | ||
46 | |||
47 | [source] | ||
48 | ---- | ||
49 | $ git clone https://github.com/rust-analyzer/rust-analyzer.git && cd rust-analyzer | ||
50 | $ cargo xtask install | ||
51 | ---- | ||
52 | |||
53 | You'll need Cargo, nodejs and npm for this. | ||
54 | To make VS Code use the freshly build server, add this to the settings: | ||
55 | |||
56 | [source,json] | ||
57 | ---- | ||
58 | { "rust-analyzer.raLspServerPath": "ra_lsp_server" } | ||
59 | ---- | ||
60 | |||
61 | Note that installing via `xtask install` does not work for VS Code Remote, instead you'll need to install the `.vsix` manually. | ||
62 | |||
63 | === Language Server Binary | ||
64 | |||
65 | Other editors generally require `ra_lsp_server` binary to be in `$PATH`. | ||
66 | You can download pre-build binary from | ||
67 | https://github.com/rust-analyzer/rust-analyzer/releases[relases] | ||
68 | page, or you can install it from source using the following command: | ||
69 | |||
70 | [source,bash] | ||
71 | ---- | ||
72 | $ cargo xtask install --server | ||
73 | ---- | ||
74 | |||
75 | === Emacs | ||
76 | |||
77 | Emacs support is maintained https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-rust.el[upstream]. | ||
78 | |||
79 | 1. Install recent version of `emacs-lsp` package by following the instructions https://github.com/emacs-lsp/lsp-mode[here]. | ||
80 | 2. Set `lsp-rust-server` to `'rust-analyzer`. | ||
81 | 3. Run `lsp` in a Rust buffer. | ||
82 | 4. (Optionally) bind commands like `lsp-rust-analyzer-join-lines`, `lsp-extend-selection` and `lsp-rust-analyzer-expand-macro` to keys. | ||
83 | |||
84 | === Vim | ||
85 | |||
86 | The are several LSP client implementations for vim: | ||
87 | |||
88 | ==== coc-rust-analyzer | ||
89 | |||
90 | 1. Install coc.nvim by following the instructions at | ||
91 | https://github.com/neoclide/coc.nvim[coc.nvim] | ||
92 | (nodejs required) | ||
93 | 2. Run `:CocInstall coc-rust-analyzer` to install | ||
94 | https://github.com/fannheyward/coc-rust-analyzer[coc-rust-analyzer], | ||
95 | this extension implements _most_ of the features supported in the VSCode extension: | ||
96 | * same configurations as VSCode extension, `rust-analyzer.raLspServerPath`, `rust-analyzer.enableCargoWatchOnStartup` etc. | ||
97 | * same commands too, `rust-analyzer.analyzerStatus`, `rust-analyzer.startCargoWatch` etc. | ||
98 | * highlighting and inlay_hints are not implemented yet | ||
99 | |||
100 | ==== LanguageClient-neovim | ||
101 | |||
102 | 1. Install LanguageClient-neovim by following the instructions | ||
103 | https://github.com/autozimu/LanguageClient-neovim[here] | ||
104 | * The github project wiki has extra tips on configuration | ||
105 | |||
106 | 2. Configure by adding this to your vim/neovim config file (replacing the existing rust specific line if it exists): | ||
107 | + | ||
108 | [source,vim] | ||
109 | ---- | ||
110 | let g:LanguageClient_serverCommands = { | ||
111 | \ 'rust': ['ra_lsp_server'], | ||
112 | \ } | ||
113 | ---- | ||
114 | |||
115 | ==== nvim-lsp | ||
116 | |||
117 | NeoVim 0.5 (not yet released) has built in language server support. | ||
118 | For a quick start configuration of rust-analyzer, use https://github.com/neovim/nvim-lsp#rust_analyzer[neovim/nvim-lsp]. | ||
119 | Once `neovim/nvim-lsp` is installed, use `lua require'nvim_lsp'.rust_analyzer.setup({})` in your `init.vim`. | ||
120 | |||
121 | === Sublime Text 3 | ||
122 | |||
123 | Prerequisites: | ||
124 | |||
125 | `LSP` package. | ||
126 | |||
127 | Installation: | ||
128 | |||
129 | 1. Invoke the command palette with <kbd>Ctrl+Shift+P</kbd> | ||
130 | 2. Type `LSP Settings` to open the LSP preferences editor | ||
131 | 3. Add the following LSP client definition to your settings: | ||
132 | + | ||
133 | [source,json] | ||
134 | ---- | ||
135 | "rust-analyzer": { | ||
136 | "command": ["ra_lsp_server"], | ||
137 | "languageId": "rust", | ||
138 | "scopes": ["source.rust"], | ||
139 | "syntaxes": [ | ||
140 | "Packages/Rust/Rust.sublime-syntax", | ||
141 | "Packages/Rust Enhanced/RustEnhanced.sublime-syntax" | ||
142 | ], | ||
143 | "initializationOptions": { | ||
144 | "featureFlags": { | ||
145 | } | ||
146 | }, | ||
147 | } | ||
148 | ---- | ||
149 | |||
150 | 4. 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) | ||
151 | |||
152 | == Usage | ||
153 | |||
154 | See https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/features.md[features.md]. | ||