aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/dev/README.md27
-rw-r--r--docs/dev/architecture.md3
-rw-r--r--docs/dev/lsp-extensions.md35
-rw-r--r--docs/dev/syntax.md4
-rw-r--r--docs/user/manual.adoc120
5 files changed, 146 insertions, 43 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md
index 6b6824ded..417352c9d 100644
--- a/docs/dev/README.md
+++ b/docs/dev/README.md
@@ -177,6 +177,9 @@ There are many benefits to this:
177* less stuff printed during printf-debugging 177* less stuff printed during printf-debugging
178* less time to run test 178* less time to run test
179 179
180It also makes sense to format snippets more compactly (for example, by placing enum defitions like `enum E { Foo, Bar }` on a single line),
181as long as they are still readable.
182
180## Order of Imports 183## Order of Imports
181 184
182We separate import groups with blank lines 185We separate import groups with blank lines
@@ -311,7 +314,7 @@ We don't have specific rules around git history hygiene.
311Maintaining clean git history is encouraged, but not enforced. 314Maintaining clean git history is encouraged, but not enforced.
312We use rebase workflow, it's OK to rewrite history during PR review process. 315We use rebase workflow, it's OK to rewrite history during PR review process.
313 316
314Avoid @mentioning people in commit messages, as such messages create a lot of duplicate notification traffic during rebases. 317Avoid @mentioning people in commit messages and pull request descriptions (they are added to commit message by bors), as such messages create a lot of duplicate notification traffic during rebases.
315 318
316# Architecture Invariants 319# Architecture Invariants
317 320
@@ -358,14 +361,24 @@ There are two kinds of tests:
358The purpose of inline tests is not to achieve full coverage by test cases, but to explain to the reader of the code what each particular `if` and `match` is responsible for. 361The purpose of inline tests is not to achieve full coverage by test cases, but to explain to the reader of the code what each particular `if` and `match` is responsible for.
359If you are tempted to add a large inline test, it might be a good idea to leave only the simplest example in place, and move the test to a manual `parser/ok` test. 362If you are tempted to add a large inline test, it might be a good idea to leave only the simplest example in place, and move the test to a manual `parser/ok` test.
360 363
361To update test data, run with `UPDATE_EXPECTATIONS` variable: 364To update test data, run with `UPDATE_EXPECT` variable:
362 365
363```bash 366```bash
364env UPDATE_EXPECTATIONS=1 cargo qt 367env UPDATE_EXPECT=1 cargo qt
365``` 368```
366 369
367After adding a new inline test you need to run `cargo xtest codegen` and also update the test data as described above. 370After adding a new inline test you need to run `cargo xtest codegen` and also update the test data as described above.
368 371
372## TypeScript Tests
373
374If you change files under `editors/code` and would like to run the tests and linter, install npm and run:
375
376```bash
377cd editors/code
378npm ci
379npm run lint
380```
381
369# Logging 382# Logging
370 383
371Logging is done by both rust-analyzer and VS Code, so it might be tricky to 384Logging is done by both rust-analyzer and VS Code, so it might be tricky to
@@ -394,13 +407,7 @@ To log all communication between the server and the client, there are two choice
394 407
395There are also two VS Code commands which might be of interest: 408There are also two VS Code commands which might be of interest:
396 409
397* `Rust Analyzer: Status` shows some memory-usage statistics. To take full 410* `Rust Analyzer: Status` shows some memory-usage statistics.
398 advantage of it, you need to compile rust-analyzer with jemalloc support:
399 ```
400 $ cargo install --path crates/rust-analyzer --force --features jemalloc
401 ```
402
403 There's an alias for this: `cargo xtask install --server --jemalloc`.
404 411
405* `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection. 412* `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection.
406 413
diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md
index cee916c09..d0c6eea61 100644
--- a/docs/dev/architecture.md
+++ b/docs/dev/architecture.md
@@ -170,8 +170,7 @@ The innermost and most elaborate boundary is `hir`. It has a much richer
170vocabulary of types than `ide`, but the basic testing setup is the same: we 170vocabulary of types than `ide`, but the basic testing setup is the same: we
171create a database, run some queries, assert result. 171create a database, run some queries, assert result.
172 172
173For comparisons, we use [insta](https://github.com/mitsuhiko/insta/) library for 173For comparisons, we use the `expect` crate for snapshot testing.
174snapshot testing.
175 174
176To test various analysis corner cases and avoid forgetting about old tests, we 175To test various analysis corner cases and avoid forgetting about old tests, we
177use so-called marks. See the `marks` module in the `test_utils` crate for more. 176use so-called marks. See the `marks` module in the `test_utils` crate for more.
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index a0847dad3..1be01fd88 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -11,11 +11,13 @@ If you want to be notified about the changes to this document, subscribe to [#46
11 11
12## `initializationOptions` 12## `initializationOptions`
13 13
14As `initializationOptions`, `rust-analyzer` expects `"rust-analyzer"` section of the configuration. 14For `initializationOptions`, `rust-analyzer` expects `"rust-analyzer"` section of the configuration.
15That is, `rust-analyzer` usually sends `"workspace/configuration"` request with `{ "items": ["rust-analyzer"] }` payload. 15That is, `rust-analyzer` usually sends `"workspace/configuration"` request with `{ "items": ["rust-analyzer"] }` payload.
16`initializationOptions` should contain the same data that would be in the first item of the result. 16`initializationOptions` should contain the same data that would be in the first item of the result.
17It's OK to not send anything, then all the settings would take their default values. 17If a language client does not know about `rust-analyzer`'s configuration options it can get sensible defaults by doing any of the following:
18However, some settings can not be changed after startup at the moment. 18 * Not sending `initializationOptions`
19 * Send `"initializationOptions": null`
20 * Send `"initializationOptions": {}`
19 21
20## Snippet `TextEdit` 22## Snippet `TextEdit`
21 23
@@ -272,6 +274,11 @@ interface SsrParams {
272 query: string, 274 query: string,
273 /// If true, only check the syntax of the query and don't compute the actual edit. 275 /// If true, only check the syntax of the query and don't compute the actual edit.
274 parseOnly: bool, 276 parseOnly: bool,
277 /// The current text document. This and `position` will be used to determine in what scope
278 /// paths in `query` should be resolved.
279 textDocument: lc.TextDocumentIdentifier;
280 /// Position where SSR was invoked.
281 position: lc.Position;
275} 282}
276``` 283```
277 284
@@ -283,7 +290,7 @@ WorkspaceEdit
283 290
284### Example 291### Example
285 292
286SSR with query `foo($a:expr, $b:expr) ==>> ($a).foo($b)` will transform, eg `foo(y + 5, z)` into `(y + 5).foo(z)`. 293SSR with query `foo($a, $b) ==>> ($a).foo($b)` will transform, eg `foo(y + 5, z)` into `(y + 5).foo(z)`.
287 294
288### Unresolved Question 295### Unresolved Question
289 296
@@ -389,15 +396,27 @@ rust-analyzer supports only one `kind`, `"cargo"`. The `args` for `"cargo"` look
389 396
390Returns internal status message, mostly for debugging purposes. 397Returns internal status message, mostly for debugging purposes.
391 398
392## Collect Garbage 399## Reload Workspace
393 400
394**Method:** `rust-analyzer/collectGarbage` 401**Method:** `rust-analyzer/reloadWorkspace`
395 402
396**Request:** `null` 403**Request:** `null`
397 404
398**Response:** `null` 405**Response:** `null`
399 406
400Frees some caches. For internal use, and is mostly broken at the moment. 407Reloads project information (that is, re-executes `cargo metadata`).
408
409## Status Notification
410
411**Client Capability:** `{ "statusNotification": boolean }`
412
413**Method:** `rust-analyzer/status`
414
415**Notification:** `"loading" | "ready" | "invalid" | "needsReload"`
416
417This notification is sent from server to client.
418The client can use it to display persistent status to the user (in modline).
419For `needsReload` state, the client can provide a context-menu action to run `rust-analyzer/reloadWorkspace` request.
401 420
402## Syntax Tree 421## Syntax Tree
403 422
@@ -504,4 +523,4 @@ Such actions on the client side are appended to a hover bottom as command links:
504 | TITLE _Action1_ | _Action2_ | <- second group 523 | TITLE _Action1_ | _Action2_ | <- second group
505 +-----------------------------+ 524 +-----------------------------+
506 ... 525 ...
507``` \ No newline at end of file 526```
diff --git a/docs/dev/syntax.md b/docs/dev/syntax.md
index c2864bbbc..d4bc4b07c 100644
--- a/docs/dev/syntax.md
+++ b/docs/dev/syntax.md
@@ -82,7 +82,7 @@ Points of note:
82An input like `fn f() { 90 + 2 }` might be parsed as 82An input like `fn f() { 90 + 2 }` might be parsed as
83 83
84``` 84```
85FN_DEF@0..17 85[email protected]
86 [email protected] "fn" 86 [email protected] "fn"
87 [email protected] " " 87 [email protected] " "
88 [email protected] 88 [email protected]
@@ -342,7 +342,7 @@ pub struct FnDef {
342impl AstNode for FnDef { 342impl AstNode for FnDef {
343 fn cast(syntax: SyntaxNode) -> Option<Self> { 343 fn cast(syntax: SyntaxNode) -> Option<Self> {
344 match kind { 344 match kind {
345 FN_DEF => Some(FnDef { syntax }), 345 FN => Some(FnDef { syntax }),
346 _ => None, 346 _ => None,
347 } 347 }
348 } 348 }
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc
index b763958fe..cfc0ad81c 100644
--- a/docs/user/manual.adoc
+++ b/docs/user/manual.adoc
@@ -13,8 +13,12 @@ This manual focuses on a specific usage of the library -- running it as part of
13https://microsoft.github.io/language-server-protocol/[Language Server Protocol] (LSP). 13https://microsoft.github.io/language-server-protocol/[Language Server Protocol] (LSP).
14The LSP allows various code editors, like VS Code, Emacs or Vim, to implement semantic features like completion or goto definition by talking to an external language server process. 14The LSP allows various code editors, like VS Code, Emacs or Vim, to implement semantic features like completion or goto definition by talking to an external language server process.
15 15
16To improve this document, send a pull request against 16[TIP]
17https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/manual.adoc[this file]. 17====
18[.lead]
19To improve this document, send a pull request: +
20https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/manual.adoc[https://github.com/rust-analyzer/.../manual.adoc]
21====
18 22
19If you have questions about using rust-analyzer, please ask them in the https://users.rust-lang.org/c/ide/14["`IDEs and Editors`"] topic of Rust users forum. 23If you have questions about using rust-analyzer, please ask them in the https://users.rust-lang.org/c/ide/14["`IDEs and Editors`"] topic of Rust users forum.
20 24
@@ -106,20 +110,8 @@ Here are some useful self-diagnostic commands:
106* **Rust Analyzer: Show RA Version** shows the version of `rust-analyzer` binary 110* **Rust Analyzer: Show RA Version** shows the version of `rust-analyzer` binary
107* **Rust Analyzer: Status** prints some statistics about the server, like the few latest LSP requests 111* **Rust Analyzer: Status** prints some statistics about the server, like the few latest LSP requests
108* To enable server-side logging, run with `env RA_LOG=info` and see `Output > Rust Analyzer Language Server` in VS Code's panel. 112* To enable server-side logging, run with `env RA_LOG=info` and see `Output > Rust Analyzer Language Server` in VS Code's panel.
109* To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Server Trace` in the panel. 113* To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Rust Analyzer Language Server Trace` in the panel.
110* To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open the `Console` tab of VS Code developer tools. 114* To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open `Output > Rust Analyzer Client` in the panel.
111
112==== Special `when` clause context for keybindings.
113You may use `inRustProject` context to configure keybindings for rust projects only. For example:
114[source,json]
115----
116{
117 "key": "ctrl+i",
118 "command": "rust-analyzer.toggleInlayHints",
119 "when": "inRustProject"
120}
121----
122More about `when` clause contexts https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts[here].
123 115
124=== rust-analyzer Language Server Binary 116=== rust-analyzer Language Server Binary
125 117
@@ -281,9 +273,6 @@ However, if you use some other build system, you'll have to describe the structu
281[source,TypeScript] 273[source,TypeScript]
282---- 274----
283interface JsonProject { 275interface JsonProject {
284 /// The set of paths containing the crates for this project.
285 /// Any `Crate` must be nested inside some `root`.
286 roots: string[];
287 /// The set of crates comprising the current project. 276 /// The set of crates comprising the current project.
288 /// Must include all transitive dependencies as well as sysroot crate (libstd, libcore and such). 277 /// Must include all transitive dependencies as well as sysroot crate (libstd, libcore and such).
289 crates: Crate[]; 278 crates: Crate[];
@@ -296,11 +285,37 @@ interface Crate {
296 edition: "2015" | "2018"; 285 edition: "2015" | "2018";
297 /// Dependencies 286 /// Dependencies
298 deps: Dep[]; 287 deps: Dep[];
288 /// Should this crate be treated as a member of current "workspace".
289 ///
290 /// By default, inferred from the `root_module` (members are the crates which reside
291 /// inside the directory opened in the editor).
292 ///
293 /// Set this to `false` for things like standard library and 3rd party crates to
294 /// enable performance optimizations (rust-analyzer assumes that non-member crates
295 /// don't change).
296 is_workspace_member?: boolean;
297 /// Optionally specify the (super)set of `.rs` files comprising this crate.
298 ///
299 /// By default, rust-analyzer assumes that only files under `root_module.parent` can belong to a crate.
300 /// `include_dirs` are included recursively, unless a subdirectory is in `exclude_dirs`.
301 ///
302 /// Different crates can share the same `source`.
303 ///
304 /// If two crates share an `.rs` file in common, they *must* have the same `source`.
305 /// rust-analyzer assumes that files from one source can't refer to files in another source.
306 source?: {
307 include_dirs: string[],
308 exclude_dirs: string[],
309 },
299 /// The set of cfgs activated for a given crate, like `["unix", "feature=foo", "feature=bar"]`. 310 /// The set of cfgs activated for a given crate, like `["unix", "feature=foo", "feature=bar"]`.
300 cfg: string[]; 311 cfg: string[];
312 /// Target triple for this Crate.
313 ///
314 /// Used when running `rustc --print cfg` to get target-specific cfgs.
315 target?: string;
316 /// Environment variables, used for the `env!` macro
317 env: : { [key: string]: string; },
301 318
302 /// value of the OUT_DIR env variable.
303 out_dir?: string;
304 /// For proc-macro crates, path to compiles proc-macro (.so file). 319 /// For proc-macro crates, path to compiles proc-macro (.so file).
305 proc_macro_dylib_path?: string; 320 proc_macro_dylib_path?: string;
306} 321}
@@ -337,3 +352,66 @@ They are usually triggered by a shortcut or by clicking a light bulb icon in the
337Cursor position or selection is signified by `┃` character. 352Cursor position or selection is signified by `┃` character.
338 353
339include::./generated_assists.adoc[] 354include::./generated_assists.adoc[]
355
356== Editor Features
357=== VS Code
358==== Special `when` clause context for keybindings.
359You may use `inRustProject` context to configure keybindings for rust projects only. For example:
360[source,json]
361----
362{
363 "key": "ctrl+i",
364 "command": "rust-analyzer.toggleInlayHints",
365 "when": "inRustProject"
366}
367----
368More about `when` clause contexts https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts[here].
369
370==== Setting runnable environment variables
371You can use "rust-analyzer.runnableEnv" setting to define runnable environment-specific substitution variables.
372The simplest way for all runnables in a bunch:
373```jsonc
374"rust-analyzer.runnableEnv": {
375 "RUN_SLOW_TESTS": "1"
376}
377```
378
379Or it is possible to specify vars more granularly:
380```jsonc
381"rust-analyzer.runnableEnv": [
382 {
383 // "mask": null, // null mask means that this rule will be applied for all runnables
384 env: {
385 "APP_ID": "1",
386 "APP_DATA": "asdf"
387 }
388 },
389 {
390 "mask": "test_name",
391 "env": {
392 "APP_ID": "2", // overwrites only APP_ID
393 }
394 }
395]
396```
397
398You can use any valid RegExp as a mask. Also note that a full runnable name is something like *run bin_or_example_name*, *test some::mod::test_name* or *test-mod some::mod*, so it is possible to distinguish binaries, single tests, and test modules with this masks: `"^run"`, `"^test "` (the trailing space matters!), and `"^test-mod"` respectively.
399
400==== Compiler feedback from external commands
401
402Instead of relying on the built-in `cargo check`, you can configure Code to run a command in the background and use the `$rustc-watch` problem matcher to generate inline error markers from its output.
403
404To do this you need to create a new https://code.visualstudio.com/docs/editor/tasks[VS Code Task] and set `rust-analyzer.checkOnSave.enable: false` in preferences.
405
406For example, if you want to run https://crates.io/crates/cargo-watch[`cargo watch`] instead, you might add the following to `.vscode/tasks.json`:
407
408```json
409{
410 "label": "Watch",
411 "group": "build",
412 "type": "shell",
413 "command": "cargo watch",
414 "problemMatcher": "$rustc-watch",
415 "isBackground": true
416}
417```