aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/dev/architecture.md28
-rw-r--r--docs/user/manual.adoc90
2 files changed, 111 insertions, 7 deletions
diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md
index 56ebaa3df..7a88ebc0f 100644
--- a/docs/dev/architecture.md
+++ b/docs/dev/architecture.md
@@ -21,7 +21,7 @@ See also these implementation-related blog posts:
21 21
22## Bird's Eye View 22## Bird's Eye View
23 23
24![](https://user-images.githubusercontent.com/1711539/50114578-e8a34280-0255-11e9-902c-7cfc70747966.png) 24![](https://user-images.githubusercontent.com/4789492/107129398-0ab70f00-687a-11eb-9bfc-d4eb023aec06.png)
25 25
26On the highest level, rust-analyzer is a thing which accepts input source code from the client and produces a structured semantic model of the code. 26On the highest level, rust-analyzer is a thing which accepts input source code from the client and produces a structured semantic model of the code.
27 27
@@ -39,6 +39,14 @@ The client can submit a small delta of input data (typically, a change to a sing
39 39
40The underlying engine makes sure that model is computed lazily (on-demand) and can be quickly updated for small modifications. 40The underlying engine makes sure that model is computed lazily (on-demand) and can be quickly updated for small modifications.
41 41
42## Entry Points
43
44`crates/rust-analyzer/src/bin/main.rs` contains the main function which spawns LSP.
45This is *the* entry point, but it front-loads a lot of complexity, so its fine to just skim through it.
46
47`crates/rust-analyzer/src/handlers.rs` implements all LSP requests and is a great place to start if you are already familiar with LSP.
48
49`Analysis` and `AnalysisHost` types define the main API.
42 50
43## Code Map 51## Code Map
44 52
@@ -75,7 +83,7 @@ Original [libsyntax parser](https://github.com/rust-lang/rust/blob/6b99adeb11313
75 83
76**Architecture Invariant:** the parser is independent of the particular tree structure and particular representation of the tokens. 84**Architecture Invariant:** the parser is independent of the particular tree structure and particular representation of the tokens.
77It transforms one flat stream of events into another flat stream of events. 85It transforms one flat stream of events into another flat stream of events.
78Token independence allows us to pares out both text-based source code and `tt`-based macro input. 86Token independence allows us to parse out both text-based source code and `tt`-based macro input.
79Tree independence allows us to more easily vary the syntax tree implementation. 87Tree independence allows us to more easily vary the syntax tree implementation.
80It should also unlock efficient light-parsing approaches. 88It should also unlock efficient light-parsing approaches.
81For example, you can extract the set of names defined in a file (for typo correction) without building a syntax tree. 89For example, you can extract the set of names defined in a file (for typo correction) without building a syntax tree.
@@ -254,6 +262,22 @@ A single `rust-analyzer` process can serve many projects, so it is important tha
254These crates implement macros as token tree -> token tree transforms. 262These crates implement macros as token tree -> token tree transforms.
255They are independent from the rest of the code. 263They are independent from the rest of the code.
256 264
265`tt` crate defined `TokenTree`, a single token or a delimited sequence of token trees.
266`mbe` crate contains tools for transforming between syntax trees and token tree.
267And it also handles the actual parsing and expansion of declarative macro (a-la "Macros By Example" or mbe).
268
269For proc macros, the client-server model are used.
270We pass an argument `--proc-macro` to `rust-analyzer` binary to start a separate process (`proc_macro_srv`).
271And the client (`proc_macro_api`) provides an interface to talk to that server separately.
272
273And then token trees are passed from client, and the server will load the corresponding dynamic library (which built by `cargo`).
274And due to the fact the api for getting result from proc macro are always unstable in `rustc`,
275we maintain our own copy (and paste) of that part of code to allow us to build the whole thing in stable rust.
276
277 **Architecture Invariant:**
278Bad proc macros may panic or segfault accidentally. So we run it in another process and recover it from fatal error.
279And they may be non-deterministic which conflict how `salsa` works, so special attention is required.
280
257### `crates/cfg` 281### `crates/cfg`
258 282
259This crate is responsible for parsing, evaluation and general definition of `cfg` attributes. 283This crate is responsible for parsing, evaluation and general definition of `cfg` attributes.
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc
index 10d4fd606..a2c7f56b3 100644
--- a/docs/user/manual.adoc
+++ b/docs/user/manual.adoc
@@ -194,6 +194,8 @@ $ pacman -S rust-analyzer
194 194
195=== Emacs 195=== Emacs
196 196
197Note this excellent https://robert.kra.hn/posts/2021-02-07_rust-with-emacs/[guide] from https://github.com/rksm[@rksm].
198
197Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. 199Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>.
198 200
199Emacs 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]. 201Emacs 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].
@@ -307,6 +309,52 @@ EOF
307 309
308See https://sharksforarms.dev/posts/neovim-rust/ for more tips on getting started. 310See https://sharksforarms.dev/posts/neovim-rust/ for more tips on getting started.
309 311
312==== vim-lsp
313
314vim-lsp is installed by following https://github.com/prabirshrestha/vim-lsp[the plugin instructions].
315It can be as simple as adding this line to your `.vimrc`:
316
317[source,vim]
318----
319Plug 'prabirshrestha/vim-lsp'
320----
321
322Next you need to register the `rust-analyzer` binary.
323If it is available in `$PATH`, you may want to add this to your `.vimrc`:
324
325[source,vim]
326----
327if executable('rust-analyzer')
328 au User lsp_setup call lsp#register_server({
329 \ 'name': 'Rust Language Server',
330 \ 'cmd': {server_info->['rust-analyzer']},
331 \ 'whitelist': ['rust'],
332 \ })
333endif
334----
335
336There is no dedicated UI for the server configuration, so you would need to send any options as a value of the `initialization_options` field, as described in the <<_configuration,Configuration>> section.
337Here is an example of how to enable the proc-macro support:
338
339[source,vim]
340----
341if executable('rust-analyzer')
342 au User lsp_setup call lsp#register_server({
343 \ 'name': 'Rust Language Server',
344 \ 'cmd': {server_info->['rust-analyzer']},
345 \ 'whitelist': ['rust'],
346 \ 'initialization_options': {
347 \ 'cargo': {
348 \ 'loadOutDirsFromCheck': v:true,
349 \ },
350 \ 'procMacro': {
351 \ 'enable': v:true,
352 \ },
353 \ },
354 \ })
355endif
356----
357
310=== Sublime Text 3 358=== Sublime Text 3
311 359
312Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. 360Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>.
@@ -331,17 +379,49 @@ If you get an error saying `No such file or directory: 'rust-analyzer'`, see the
331GNOME Builder 3.37.1 and newer has native `rust-analyzer` support. 379GNOME Builder 3.37.1 and newer has native `rust-analyzer` support.
332If the LSP binary is not available, GNOME Builder can install it when opening a Rust file. 380If the LSP binary is not available, GNOME Builder can install it when opening a Rust file.
333 381
382
383=== Eclipse IDE
384
385Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>.
386
387Support for Rust development in the Eclipse IDE is provided by link:https://github.com/eclipse/corrosion[Eclipse Corrosion].
388While it currently uses RLS as default, you can successfully configure it so the IDE will use `rust-analyzer` instead.
389To do so, with an Eclipse IDE where Corrosion is installed, just go to __Window > Preferences > Rust__ and edit the __Path to Rust Language Server__ entry to reference the path to `rust-analyzer`.
390You'll need to close and reopen all .rs and Cargo files, or to restart the IDE, for this change to take effect.
391
334== Configuration 392== Configuration
335 393
336**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs[config.rs] 394**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs[config.rs]
337 395
338rust-analyzer is configured via LSP messages, which means that it's up to the editor to decide on the exact format and location of configuration files. 396The <<_installation,Installation>> section contains details on configuration for some of the editors.
339Please consult your editor's documentation to learn how to configure LSP servers. 397In general `rust-analyzer` is configured via LSP messages, which means that it's up to the editor to decide on the exact format and location of configuration files.
398
399Some clients, such as <<vs-code,VS Code>> or <<coc-rust-analyzer,COC plugin in Vim>> provide `rust-analyzer` specific configuration UIs. Others may require you to know a bit more about the interaction with `rust-analyzer`.
400
401For the later category, it might help to know that the initial configuration is specified as a value of the `intializationOptions` field of the https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize[`InitializeParams` message, in the LSP protocol].
402The spec says that the field type is `any?`, but `rust-analyzer` is looking for a JSON object that is constructed using settings from the list below.
403Name of the setting, ignoring the `rust-analyzer.` prefix, is used as a path, and value of the setting becomes the JSON property value.
404
405For example, a very common configuration is to enable proc-macro support, can be achieved by sending this JSON:
406
407[source,json]
408----
409{
410 "cargo": {
411 "loadOutDirsFromCheck": true,
412 },
413 "procMacro": {
414 "enable": true,
415 }
416}
417----
418
419Please consult your editor's documentation to learn more about how to configure https://microsoft.github.io/language-server-protocol/[LSP servers].
340 420
341To verify which configuration is actually used by rust-analyzer, set `RA_LOG` environment variable to `rust_analyzer=info` and look for config-related messages. 421To verify which configuration is actually used by `rust-analyzer`, set `RA_LOG` environment variable to `rust_analyzer=info` and look for config-related messages.
342Logs should show both the JSON that rust-analyzer sees as well as the updated config. 422Logs should show both the JSON that `rust-analyzer` sees as well as the updated config.
343 423
344This is the list of config options rust-analyzer supports: 424This is the list of config options `rust-analyzer` supports:
345 425
346include::./generated_config.adoc[] 426include::./generated_config.adoc[]
347 427