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