aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/dev/README.md37
-rw-r--r--docs/dev/architecture.md13
-rw-r--r--docs/dev/lsp-extensions.md57
-rw-r--r--docs/dev/style.md52
-rw-r--r--docs/dev/syntax.md8
-rw-r--r--docs/user/generated_config.adoc12
-rw-r--r--docs/user/manual.adoc76
7 files changed, 183 insertions, 72 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md
index eab21a765..16b23adc6 100644
--- a/docs/dev/README.md
+++ b/docs/dev/README.md
@@ -24,7 +24,7 @@ Rust Analyzer is a part of [RLS-2.0 working
24group](https://github.com/rust-lang/compiler-team/tree/6a769c13656c0a6959ebc09e7b1f7c09b86fb9c0/working-groups/rls-2.0). 24group](https://github.com/rust-lang/compiler-team/tree/6a769c13656c0a6959ebc09e7b1f7c09b86fb9c0/working-groups/rls-2.0).
25Discussion happens in this Zulip stream: 25Discussion happens in this Zulip stream:
26 26
27https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0 27https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer
28 28
29# Issue Labels 29# Issue Labels
30 30
@@ -32,6 +32,8 @@ https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0
32 are good issues to get into the project. 32 are good issues to get into the project.
33* [E-has-instructions](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-has-instructions) 33* [E-has-instructions](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-has-instructions)
34 issues have links to the code in question and tests. 34 issues have links to the code in question and tests.
35* [Broken Window](https://github.com/rust-analyzer/rust-analyzer/issues?q=is:issue+is:open+label:%22Broken+Window%22)
36 are issues which are not critical by themselves, but which should be fixed ASAP regardless, to avoid accumulation of technical debt.
35* [E-easy](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy), 37* [E-easy](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy),
36 [E-medium](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-medium), 38 [E-medium](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-medium),
37 [E-hard](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-hard), 39 [E-hard](https://github.com/rust-analyzer/rust-analyzer/issues?q=is%3Aopen+is%3Aissue+label%3AE-hard),
@@ -206,20 +208,26 @@ Release process is handled by `release`, `dist` and `promote` xtasks, `release`
206 208
207Additionally, it assumes that remote for `rust-analyzer` is called `upstream` (I use `origin` to point to my fork). 209Additionally, it assumes that remote for `rust-analyzer` is called `upstream` (I use `origin` to point to my fork).
208 210
211`release` calls the GitHub API calls to scrape pull request comments and categorize them in the changelog.
212This step uses the `curl` and `jq` applications, which need to be available in `PATH`.
213Finally, you need to obtain a GitHub personal access token and set the `GITHUB_TOKEN` environment variable.
214
209Release steps: 215Release steps:
210 216
2111. Inside rust-analyzer, run `cargo xtask release`. This will: 2171. Set the `GITHUB_TOKEN` environment variable.
2182. Inside rust-analyzer, run `cargo xtask release`. This will:
212 * checkout the `release` branch 219 * checkout the `release` branch
213 * reset it to `upstream/nightly` 220 * reset it to `upstream/nightly`
214 * push it to `upstream`. This triggers GitHub Actions which: 221 * push it to `upstream`. This triggers GitHub Actions which:
215 * runs `cargo xtask dist` to package binaries and VS Code extension 222 * runs `cargo xtask dist` to package binaries and VS Code extension
216 * makes a GitHub release 223 * makes a GitHub release
217 * pushes VS Code extension to the marketplace 224 * pushes VS Code extension to the marketplace
218 * create new changelog in `rust-analyzer.github.io` 225 * call the GitHub API for PR details
2192. While the release is in progress, fill in the changelog 226 * create a new changelog in `rust-analyzer.github.io`
2203. Commit & push the changelog 2273. While the release is in progress, fill in the changelog
2214. Tweet 2284. Commit & push the changelog
2225. Inside `rust-analyzer`, run `cargo xtask promote` -- this will create a PR to rust-lang/rust updating rust-analyzer's submodule. 2295. Tweet
2306. Inside `rust-analyzer`, run `cargo xtask promote` -- this will create a PR to rust-lang/rust updating rust-analyzer's submodule.
223 Self-approve the PR. 231 Self-approve the PR.
224 232
225If the GitHub Actions release fails because of a transient problem like a timeout, you can re-run the job from the Actions console. 233If the GitHub Actions release fails because of a transient problem like a timeout, you can re-run the job from the Actions console.
@@ -227,18 +235,27 @@ If it fails because of something that needs to be fixed, remove the release tag
227Make sure to remove the new changelog post created when running `cargo xtask release` a second time. 235Make sure to remove the new changelog post created when running `cargo xtask release` a second time.
228 236
229We release "nightly" every night automatically and promote the latest nightly to "stable" manually, every week. 237We release "nightly" every night automatically and promote the latest nightly to "stable" manually, every week.
238
230We don't do "patch" releases, unless something truly egregious comes up. 239We don't do "patch" releases, unless something truly egregious comes up.
240To do a patch release, cherry-pick the fix on top of the current `release` branch and push the branch.
241There's no need to write a changelog for a patch release, it's OK to include the notes about the fix into the next weekly one.
242Note: we tag releases by dates, releasing a patch release on the same day should work (by overwriting a tag), but I am not 100% sure.
231 243
232## Permissions 244## Permissions
233 245
234There are three sets of people with extra permissions: 246There are three sets of people with extra permissions:
235 247
236* rust-analyzer GitHub organization **admins** (which include current t-compiler leads). 248* rust-analyzer GitHub organization [**admins**](https://github.com/orgs/rust-analyzer/people?query=role:owner) (which include current t-compiler leads).
237 Admins have full access to the org. 249 Admins have full access to the org.
238* **review** team in the organization. 250* [**review**](https://github.com/orgs/rust-analyzer/teams/review) team in the organization.
239 Reviewers have `r+` access to all of organization's repositories and publish rights on crates.io. 251 Reviewers have `r+` access to all of organization's repositories and publish rights on crates.io.
240 They also have direct commit access, but all changes should via bors queue. 252 They also have direct commit access, but all changes should via bors queue.
241 It's ok to self-approve if you think you know what you are doing! 253 It's ok to self-approve if you think you know what you are doing!
242 bors should automatically sync the permissions. 254 bors should automatically sync the permissions.
243* **triage** team in the organization. 255 Feel free to request a review or assign any PR to a reviewer with the relevant expertise to bring the work to their attention.
256 Don't feel pressured to review assigned PRs though.
257 If you don't feel like reviewing for whatever reason, someone else will pick the review up!
258* [**triage**](https://github.com/orgs/rust-analyzer/teams/triage) team in the organization.
244 This team can label and close issues. 259 This team can label and close issues.
260
261Note that at the time being you need to be a member of the org yourself to view the links.
diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md
index fb991133a..39edf9e19 100644
--- a/docs/dev/architecture.md
+++ b/docs/dev/architecture.md
@@ -42,7 +42,7 @@ The underlying engine makes sure that model is computed lazily (on-demand) and c
42## Entry Points 42## Entry Points
43 43
44`crates/rust-analyzer/src/bin/main.rs` contains the main function which spawns LSP. 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. 45This is *the* entry point, but it front-loads a lot of complexity, so it's fine to just skim through it.
46 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. 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 48
@@ -67,7 +67,7 @@ They are handled by Rust code in the xtask directory.
67 67
68VS Code plugin. 68VS Code plugin.
69 69
70### `libs/` 70### `lib/`
71 71
72rust-analyzer independent libraries which we publish to crates.io. 72rust-analyzer independent libraries which we publish to crates.io.
73It's not heavily utilized at the moment. 73It's not heavily utilized at the moment.
@@ -139,7 +139,8 @@ If an AST method returns an `Option`, it *can* be `None` at runtime, even if thi
139### `crates/base_db` 139### `crates/base_db`
140 140
141We use the [salsa](https://github.com/salsa-rs/salsa) crate for incremental and on-demand computation. 141We use the [salsa](https://github.com/salsa-rs/salsa) crate for incremental and on-demand computation.
142Roughly, you can think of salsa as a key-value store, but it can also compute derived values using specified functions. The `base_db` crate provides basic infrastructure for interacting with salsa. 142Roughly, you can think of salsa as a key-value store, but it can also compute derived values using specified functions.
143The `base_db` crate provides basic infrastructure for interacting with salsa.
143Crucially, it defines most of the "input" queries: facts supplied by the client of the analyzer. 144Crucially, it defines most of the "input" queries: facts supplied by the client of the analyzer.
144Reading the docs of the `base_db::input` module should be useful: everything else is strictly derived from those inputs. 145Reading the docs of the `base_db::input` module should be useful: everything else is strictly derived from those inputs.
145 146
@@ -221,7 +222,7 @@ Internally, `ide` is split across several crates. `ide_assists`, `ide_completion
221The `ide` contains a public API/façade, as well as implementation for a plethora of smaller features. 222The `ide` contains a public API/façade, as well as implementation for a plethora of smaller features.
222 223
223**Architecture Invariant:** `ide` crate strives to provide a _perfect_ API. 224**Architecture Invariant:** `ide` crate strives to provide a _perfect_ API.
224Although at the moment it has only one consumer, the LSP server, LSP *does not* influence it's API design. 225Although at the moment it has only one consumer, the LSP server, LSP *does not* influence its API design.
225Instead, we keep in mind a hypothetical _ideal_ client -- an IDE tailored specifically for rust, every nook and cranny of which is packed with Rust-specific goodies. 226Instead, we keep in mind a hypothetical _ideal_ client -- an IDE tailored specifically for rust, every nook and cranny of which is packed with Rust-specific goodies.
226 227
227### `crates/rust-analyzer` 228### `crates/rust-analyzer`
@@ -307,7 +308,7 @@ This sections talks about the things which are everywhere and nowhere in particu
307 308
308### Code generation 309### Code generation
309 310
310Some of the components of this repository are generated through automatic processes. 311Some components in this repository are generated through automatic processes.
311Generated code is updated automatically on `cargo test`. 312Generated code is updated automatically on `cargo test`.
312Generated code is generally committed to the git repository. 313Generated code is generally committed to the git repository.
313 314
@@ -389,7 +390,7 @@ fn spam() {
389``` 390```
390 391
391To specify input data, we use a single string literal in a special format, which can describe a set of rust files. 392To specify input data, we use a single string literal in a special format, which can describe a set of rust files.
392See the `Fixture` type. 393See the `Fixture` its module for fixture examples and documentation.
393 394
394**Architecture Invariant:** all code invariants are tested by `#[test]` tests. 395**Architecture Invariant:** all code invariants are tested by `#[test]` tests.
395There's no additional checks in CI, formatting and tidy tests are run with `cargo test`. 396There's no additional checks in CI, formatting and tidy tests are run with `cargo test`.
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index 8a6f9f06e..f0f981802 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -1,8 +1,8 @@
1<!--- 1<!---
2lsp_ext.rs hash: e8a7502bd2b2c2f5 2lsp_ext.rs hash: 28a9d5a24b7ca396
3 3
4If you need to change the above hash to make the test pass, please check if you 4If you need to change the above hash to make the test pass, please check if you
5need to adjust this doc as well and ping this issue: 5need to adjust this doc as well and ping this issue:
6 6
7 https://github.com/rust-analyzer/rust-analyzer/issues/4604 7 https://github.com/rust-analyzer/rust-analyzer/issues/4604
8 8
@@ -46,13 +46,14 @@ If this capability is set, `WorkspaceEdit`s returned from `codeAction` requests
46```typescript 46```typescript
47interface SnippetTextEdit extends TextEdit { 47interface SnippetTextEdit extends TextEdit {
48 insertTextFormat?: InsertTextFormat; 48 insertTextFormat?: InsertTextFormat;
49 annotationId?: ChangeAnnotationIdentifier;
49} 50}
50``` 51```
51 52
52```typescript 53```typescript
53export interface TextDocumentEdit { 54export interface TextDocumentEdit {
54 textDocument: OptionalVersionedTextDocumentIdentifier; 55 textDocument: OptionalVersionedTextDocumentIdentifier;
55 edits: (TextEdit | SnippetTextEdit)[]; 56 edits: (TextEdit | SnippetTextEdit)[];
56} 57}
57``` 58```
58 59
@@ -145,9 +146,9 @@ mod foo;
145### Unresolved Question 146### Unresolved Question
146 147
147* An alternative would be to use a more general "gotoSuper" request, which would work for super methods, super classes and super modules. 148* An alternative would be to use a more general "gotoSuper" request, which would work for super methods, super classes and super modules.
148 This is the approach IntelliJ Rust is takeing. 149 This is the approach IntelliJ Rust is taking.
149 However, experience shows that super module (which generally has a feeling of navigation between files) should be separate. 150 However, experience shows that super module (which generally has a feeling of navigation between files) should be separate.
150 If you want super module, but the cursor happens to be inside an overriden function, the behavior with single "gotoSuper" request is surprising. 151 If you want super module, but the cursor happens to be inside an overridden function, the behavior with single "gotoSuper" request is surprising.
151 152
152## Join Lines 153## Join Lines
153 154
@@ -193,7 +194,7 @@ fn main() {
193### Unresolved Question 194### Unresolved Question
194 195
195* What is the position of the cursor after `joinLines`? 196* What is the position of the cursor after `joinLines`?
196 Currently this is left to editor's discretion, but it might be useful to specify on the server via snippets. 197 Currently, this is left to editor's discretion, but it might be useful to specify on the server via snippets.
197 However, it then becomes unclear how it works with multi cursor. 198 However, it then becomes unclear how it works with multi cursor.
198 199
199## On Enter 200## On Enter
@@ -330,7 +331,7 @@ Moreover, it would be cool if editors didn't need to implement even basic langua
330 331
331### Unresolved Question 332### Unresolved Question
332 333
333* Should we return a a nested brace structure, to allow paredit-like actions of jump *out* of the current brace pair? 334* Should we return a nested brace structure, to allow paredit-like actions of jump *out* of the current brace pair?
334 This is how `SelectionRange` request works. 335 This is how `SelectionRange` request works.
335* Alternatively, should we perhaps flag certain `SelectionRange`s as being brace pairs? 336* Alternatively, should we perhaps flag certain `SelectionRange`s as being brace pairs?
336 337
@@ -419,23 +420,42 @@ Returns internal status message, mostly for debugging purposes.
419 420
420Reloads project information (that is, re-executes `cargo metadata`). 421Reloads project information (that is, re-executes `cargo metadata`).
421 422
422## Status Notification 423## Server Status
423 424
424**Experimental Client Capability:** `{ "statusNotification": boolean }` 425**Experimental Client Capability:** `{ "serverStatusNotification": boolean }`
425 426
426**Method:** `rust-analyzer/status` 427**Method:** `experimental/serverStatus`
427 428
428**Notification:** 429**Notification:**
429 430
430```typescript 431```typescript
431interface StatusParams { 432interface ServerStatusParams {
432 status: "loading" | "readyPartial" | "ready" | "invalid" | "needsReload", 433 /// `ok` means that the server is completely functional.
434 ///
435 /// `warning` means that the server is partially functional.
436 /// It can answer correctly to most requests, but some results
437 /// might be wrong due to, for example, some missing dependencies.
438 ///
439 /// `error` means that the server is not functional. For example,
440 /// there's a fatal build configuration problem. The server might
441 /// still give correct answers to simple requests, but most results
442 /// will be incomplete or wrong.
443 health: "ok" | "warning" | "error",
444 /// Is there any pending background work which might change the status?
445 /// For example, are dependencies being downloaded?
446 quiescent: bool,
447 /// Explanatory message to show on hover.
448 message?: string,
433} 449}
434``` 450```
435 451
436This notification is sent from server to client. 452This notification is sent from server to client.
437The client can use it to display persistent status to the user (in modline). 453The client can use it to display *persistent* status to the user (in modline).
438For `needsReload` state, the client can provide a context-menu action to run `rust-analyzer/reloadWorkspace` request. 454It is similar to the `showMessage`, but is intended for stares rather than point-in-time events.
455
456Note that this functionality is intended primarily to inform the end user about the state of the server.
457In particular, it's valid for the client to completely ignore this extension.
458Clients are discouraged from but are allowed to use the `health` status to decide if it's worth sending a request to the server.
439 459
440## Syntax Tree 460## Syntax Tree
441 461
@@ -497,7 +517,7 @@ Expands macro call at a given position.
497This request is sent from client to server to render "inlay hints" -- virtual text inserted into editor to show things like inferred types. 517This request is sent from client to server to render "inlay hints" -- virtual text inserted into editor to show things like inferred types.
498Generally, the client should re-query inlay hints after every modification. 518Generally, the client should re-query inlay hints after every modification.
499Note that we plan to move this request to `experimental/inlayHints`, as it is not really Rust-specific, but the current API is not necessary the right one. 519Note that we plan to move this request to `experimental/inlayHints`, as it is not really Rust-specific, but the current API is not necessary the right one.
500Upstream issue: https://github.com/microsoft/language-server-protocol/issues/956 520Upstream issues: https://github.com/microsoft/language-server-protocol/issues/956 , https://github.com/rust-analyzer/rust-analyzer/issues/2797
501 521
502**Request:** 522**Request:**
503 523
@@ -602,12 +622,11 @@ interface TestInfo {
602 622
603This request is sent from client to server to move item under cursor or selection in some direction. 623This request is sent from client to server to move item under cursor or selection in some direction.
604 624
605**Method:** `experimental/moveItemUp` 625**Method:** `experimental/moveItem`
606**Method:** `experimental/moveItemDown`
607 626
608**Request:** `MoveItemParams` 627**Request:** `MoveItemParams`
609 628
610**Response:** `TextDocumentEdit | null` 629**Response:** `SnippetTextEdit[]`
611 630
612```typescript 631```typescript
613export interface MoveItemParams { 632export interface MoveItemParams {
diff --git a/docs/dev/style.md b/docs/dev/style.md
index c594946be..6ab60b50e 100644
--- a/docs/dev/style.md
+++ b/docs/dev/style.md
@@ -53,9 +53,9 @@ https://www.tedinski.com/2018/02/06/system-boundaries.html
53## Crates.io Dependencies 53## Crates.io Dependencies
54 54
55We try to be very conservative with usage of crates.io dependencies. 55We try to be very conservative with usage of crates.io dependencies.
56Don't use small "helper" crates (exception: `itertools` is allowed). 56Don't use small "helper" crates (exception: `itertools` and `either` are allowed).
57If there's some general reusable bit of code you need, consider adding it to the `stdx` crate. 57If there's some general reusable bit of code you need, consider adding it to the `stdx` crate.
58A useful exercise is to read Cargo.lock and see if some of the *transitive* dependencies do not make sense for rust-analyzer. 58A useful exercise is to read Cargo.lock and see if some *transitive* dependencies do not make sense for rust-analyzer.
59 59
60**Rationale:** keep compile times low, create ecosystem pressure for faster compiles, reduce the number of things which might break. 60**Rationale:** keep compile times low, create ecosystem pressure for faster compiles, reduce the number of things which might break.
61 61
@@ -83,8 +83,19 @@ This makes it easier to prepare a changelog.
83 83
84If the change adds a new user-visible functionality, consider recording a GIF with [peek](https://github.com/phw/peek) and pasting it into the PR description. 84If the change adds a new user-visible functionality, consider recording a GIF with [peek](https://github.com/phw/peek) and pasting it into the PR description.
85 85
86To make writing the release notes easier, you can mark a pull request as a feature, fix, internal change, or minor.
87Minor changes are excluded from the release notes, while the other types are distributed in their corresponding sections.
88There are two ways to mark this:
89
90* use a `feat: `, `feature: `, `fix: `, `internal: ` or `minor: ` prefix in the PR title
91* write `changelog [feature|fix|internal|skip] [description]` in a comment or in the PR description; the description is optional, and will replace the title if included.
92
93These comments don't have to be added by the PR author.
94Editing a comment or the PR description or title is also fine, as long as it happens before the release.
95
86**Rationale:** clean history is potentially useful, but rarely used. 96**Rationale:** clean history is potentially useful, but rarely used.
87But many users read changelogs. 97But many users read changelogs.
98Including a description and GIF suitable for the changelog means less work for the maintainers on the release day.
88 99
89## Clippy 100## Clippy
90 101
@@ -152,6 +163,16 @@ Do not reuse marks between several tests.
152 163
153**Rationale:** marks provide an easy way to find the canonical test for each bit of code. 164**Rationale:** marks provide an easy way to find the canonical test for each bit of code.
154This makes it much easier to understand. 165This makes it much easier to understand.
166More than one mark per test / code branch doesn't add significantly to understanding.
167
168## `#[should_panic]`
169
170Do not use `#[should_panic]` tests.
171Instead, explicitly check for `None`, `Err`, etc.
172
173**Rationale:** `#[should_panic]` is a tool for library authors, to makes sure that API does not fail silently, when misused.
174`rust-analyzer` is not a library, we don't need to test for API misuse, and we have to handle any user input without panics.
175Panic messages in the logs from the `#[should_panic]` tests are confusing.
155 176
156## Function Preconditions 177## Function Preconditions
157 178
@@ -330,7 +351,7 @@ When implementing `do_thing`, it might be very useful to create a context object
330 351
331```rust 352```rust
332pub fn do_thing(arg1: Arg1, arg2: Arg2) -> Res { 353pub fn do_thing(arg1: Arg1, arg2: Arg2) -> Res {
333 let mut ctx = Ctx { arg1, arg2 } 354 let mut ctx = Ctx { arg1, arg2 };
334 ctx.run() 355 ctx.run()
335} 356}
336 357
@@ -586,7 +607,7 @@ use super::{}
586 607
587**Rationale:** consistency. 608**Rationale:** consistency.
588Reading order is important for new contributors. 609Reading order is important for new contributors.
589Grouping by crate allows to spot unwanted dependencies easier. 610Grouping by crate allows spotting unwanted dependencies easier.
590 611
591## Import Style 612## Import Style
592 613
@@ -779,7 +800,7 @@ assert!(x < y);
779assert!(x > 0); 800assert!(x > 0);
780 801
781// BAD 802// BAD
782assert!(x >= lo && x <= hi>); 803assert!(x >= lo && x <= hi);
783assert!(r1 < l2 || l1 > r2); 804assert!(r1 < l2 || l1 > r2);
784assert!(y > x); 805assert!(y > x);
785assert!(0 > x); 806assert!(0 > x);
@@ -842,7 +863,26 @@ Re-using originally single-purpose function often leads to bad coupling.
842 863
843## Helper Variables 864## Helper Variables
844 865
845Introduce helper variables freely, especially for multiline conditions. 866Introduce helper variables freely, especially for multiline conditions:
867
868```rust
869// GOOD
870let rustfmt_not_installed =
871 captured_stderr.contains("not installed") || captured_stderr.contains("not available");
872
873match output.status.code() {
874 Some(1) if !rustfmt_not_installed => Ok(None),
875 _ => Err(format_err!("rustfmt failed:\n{}", captured_stderr)),
876};
877
878// BAD
879match output.status.code() {
880 Some(1)
881 if !captured_stderr.contains("not installed")
882 && !captured_stderr.contains("not available") => Ok(None),
883 _ => Err(format_err!("rustfmt failed:\n{}", captured_stderr)),
884};
885```
846 886
847**Rationale:** like blocks, single-use variables are a cognitively cheap abstraction, as they have access to all the context. 887**Rationale:** like blocks, single-use variables are a cognitively cheap abstraction, as they have access to all the context.
848Extra variables help during debugging, they make it easy to print/view important intermediate results. 888Extra variables help during debugging, they make it easy to print/view important intermediate results.
diff --git a/docs/dev/syntax.md b/docs/dev/syntax.md
index 737cc7a72..f7a0c09fc 100644
--- a/docs/dev/syntax.md
+++ b/docs/dev/syntax.md
@@ -145,7 +145,7 @@ Another alternative (used by swift and roslyn) is to explicitly divide the set o
145 145
146```rust 146```rust
147struct Token { 147struct Token {
148 kind: NonTriviaTokenKind 148 kind: NonTriviaTokenKind,
149 text: String, 149 text: String,
150 leading_trivia: Vec<TriviaToken>, 150 leading_trivia: Vec<TriviaToken>,
151 trailing_trivia: Vec<TriviaToken>, 151 trailing_trivia: Vec<TriviaToken>,
@@ -240,7 +240,7 @@ impl SyntaxNode {
240 let child_offset = offset; 240 let child_offset = offset;
241 offset += green_child.text_len; 241 offset += green_child.text_len;
242 Arc::new(SyntaxData { 242 Arc::new(SyntaxData {
243 offset: child_offset; 243 offset: child_offset,
244 parent: Some(Arc::clone(self)), 244 parent: Some(Arc::clone(self)),
245 green: Arc::clone(green_child), 245 green: Arc::clone(green_child),
246 }) 246 })
@@ -249,7 +249,7 @@ impl SyntaxNode {
249} 249}
250 250
251impl PartialEq for SyntaxNode { 251impl PartialEq for SyntaxNode {
252 fn eq(&self, other: &SyntaxNode) { 252 fn eq(&self, other: &SyntaxNode) -> bool {
253 self.offset == other.offset 253 self.offset == other.offset
254 && Arc::ptr_eq(&self.green, &other.green) 254 && Arc::ptr_eq(&self.green, &other.green)
255 } 255 }
@@ -273,7 +273,7 @@ This is OK because trees traversals mostly (always, in case of rust-analyzer) ru
273The other thread can restore the `SyntaxNode` by traversing from the root green node and looking for a node with specified range. 273The other thread can restore the `SyntaxNode` by traversing from the root green node and looking for a node with specified range.
274You can also use the similar trick to store a `SyntaxNode`. 274You can also use the similar trick to store a `SyntaxNode`.
275That is, a data structure that holds a `(GreenNode, Range<usize>)` will be `Sync`. 275That is, a data structure that holds a `(GreenNode, Range<usize>)` will be `Sync`.
276However rust-analyzer goes even further. 276However, rust-analyzer goes even further.
277It treats trees as semi-transient and instead of storing a `GreenNode`, it generally stores just the id of the file from which the tree originated: `(FileId, Range<usize>)`. 277It treats trees as semi-transient and instead of storing a `GreenNode`, it generally stores just the id of the file from which the tree originated: `(FileId, Range<usize>)`.
278The `SyntaxNode` is the restored by reparsing the file and traversing it from root. 278The `SyntaxNode` is the restored by reparsing the file and traversing it from root.
279With this trick, rust-analyzer holds only a small amount of trees in memory at the same time, which reduces memory usage. 279With this trick, rust-analyzer holds only a small amount of trees in memory at the same time, which reduces memory usage.
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index 871c65add..e28423e99 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -39,6 +39,12 @@ List of features to activate.
39-- 39--
40Run build scripts (`build.rs`) for more precise code analysis. 40Run build scripts (`build.rs`) for more precise code analysis.
41-- 41--
42[[rust-analyzer.cargo.useRustcWrapperForBuildScripts]]rust-analyzer.cargo.useRustcWrapperForBuildScripts (default: `true`)::
43+
44--
45Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
46avoid compiling unnecessary things.
47--
42[[rust-analyzer.cargo.noDefaultFeatures]]rust-analyzer.cargo.noDefaultFeatures (default: `false`):: 48[[rust-analyzer.cargo.noDefaultFeatures]]rust-analyzer.cargo.noDefaultFeatures (default: `false`)::
43+ 49+
44-- 50--
@@ -141,6 +147,12 @@ have more false positives than usual.
141-- 147--
142List of rust-analyzer diagnostics to disable. 148List of rust-analyzer diagnostics to disable.
143-- 149--
150[[rust-analyzer.diagnostics.remapPrefix]]rust-analyzer.diagnostics.remapPrefix (default: `{}`)::
151+
152--
153Map of prefixes to be substituted when parsing diagnostic file paths.
154This should be the reverse mapping of what is passed to `rustc` as `--remap-path-prefix`.
155--
144[[rust-analyzer.diagnostics.warningsAsHint]]rust-analyzer.diagnostics.warningsAsHint (default: `[]`):: 156[[rust-analyzer.diagnostics.warningsAsHint]]rust-analyzer.diagnostics.warningsAsHint (default: `[]`)::
145+ 157+
146-- 158--
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc
index e74b287fb..54195adb7 100644
--- a/docs/user/manual.adoc
+++ b/docs/user/manual.adoc
@@ -429,24 +429,32 @@ However, if you use some other build system, you'll have to describe the structu
429[source,TypeScript] 429[source,TypeScript]
430---- 430----
431interface JsonProject { 431interface JsonProject {
432 /// Path to the directory with *source code* of sysroot crates. 432 /// Path to the directory with *source code* of
433 /// sysroot crates.
434 ///
435 /// It should point to the directory where std,
436 /// core, and friends can be found:
433 /// 437 ///
434 /// It should point to the directory where std, core, and friends can be found:
435 /// https://github.com/rust-lang/rust/tree/master/library. 438 /// https://github.com/rust-lang/rust/tree/master/library.
436 /// 439 ///
437 /// If provided, rust-analyzer automatically adds dependencies on sysroot 440 /// If provided, rust-analyzer automatically adds
438 /// crates. Conversely, if you omit this path, you can specify sysroot 441 /// dependencies on sysroot crates. Conversely,
439 /// dependencies yourself and, for example, have several different "sysroots" in 442 /// if you omit this path, you can specify sysroot
440 /// one graph of crates. 443 /// dependencies yourself and, for example, have
444 /// several different "sysroots" in one graph of
445 /// crates.
441 sysroot_src?: string; 446 sysroot_src?: string;
442 /// The set of crates comprising the current project. 447 /// The set of crates comprising the current
443 /// Must include all transitive dependencies as well as sysroot crate (libstd, libcore and such). 448 /// project. Must include all transitive
449 /// dependencies as well as sysroot crate (libstd,
450 /// libcore and such).
444 crates: Crate[]; 451 crates: Crate[];
445} 452}
446 453
447interface Crate { 454interface Crate {
448 /// Optional crate name used for display purposes, without affecting semantics. 455 /// Optional crate name used for display purposes,
449 /// See the `deps` key for semantically-significant crate names. 456 /// without affecting semantics. See the `deps`
457 /// key for semantically-significant crate names.
450 display_name?: string; 458 display_name?: string;
451 /// Path to the root module of the crate. 459 /// Path to the root module of the crate.
452 root_module: string; 460 root_module: string;
@@ -454,45 +462,59 @@ interface Crate {
454 edition: "2015" | "2018" | "2021"; 462 edition: "2015" | "2018" | "2021";
455 /// Dependencies 463 /// Dependencies
456 deps: Dep[]; 464 deps: Dep[];
457 /// Should this crate be treated as a member of current "workspace". 465 /// Should this crate be treated as a member of
466 /// current "workspace".
458 /// 467 ///
459 /// By default, inferred from the `root_module` (members are the crates which reside 468 /// By default, inferred from the `root_module`
460 /// inside the directory opened in the editor). 469 /// (members are the crates which reside inside
470 /// the directory opened in the editor).
461 /// 471 ///
462 /// Set this to `false` for things like standard library and 3rd party crates to 472 /// Set this to `false` for things like standard
463 /// enable performance optimizations (rust-analyzer assumes that non-member crates 473 /// library and 3rd party crates to enable
464 /// don't change). 474 /// performance optimizations (rust-analyzer
475 /// assumes that non-member crates don't change).
465 is_workspace_member?: boolean; 476 is_workspace_member?: boolean;
466 /// Optionally specify the (super)set of `.rs` files comprising this crate. 477 /// Optionally specify the (super)set of `.rs`
478 /// files comprising this crate.
467 /// 479 ///
468 /// By default, rust-analyzer assumes that only files under `root_module.parent` can belong to a crate. 480 /// By default, rust-analyzer assumes that only
469 /// `include_dirs` are included recursively, unless a subdirectory is in `exclude_dirs`. 481 /// files under `root_module.parent` can belong
482 /// to a crate. `include_dirs` are included
483 /// recursively, unless a subdirectory is in
484 /// `exclude_dirs`.
470 /// 485 ///
471 /// Different crates can share the same `source`. 486 /// Different crates can share the same `source`.
472 /// 487 ///
473 /// If two crates share an `.rs` file in common, they *must* have the same `source`. 488 /// If two crates share an `.rs` file in common,
474 /// rust-analyzer assumes that files from one source can't refer to files in another source. 489 /// they *must* have the same `source`.
490 /// rust-analyzer assumes that files from one
491 /// source can't refer to files in another source.
475 source?: { 492 source?: {
476 include_dirs: string[], 493 include_dirs: string[],
477 exclude_dirs: string[], 494 exclude_dirs: string[],
478 }, 495 },
479 /// The set of cfgs activated for a given crate, like `["unix", "feature=\"foo\"", "feature=\"bar\""]`. 496 /// The set of cfgs activated for a given crate, like
497 /// `["unix", "feature=\"foo\"", "feature=\"bar\""]`.
480 cfg: string[]; 498 cfg: string[];
481 /// Target triple for this Crate. 499 /// Target triple for this Crate.
482 /// 500 ///
483 /// Used when running `rustc --print cfg` to get target-specific cfgs. 501 /// Used when running `rustc --print cfg`
502 /// to get target-specific cfgs.
484 target?: string; 503 target?: string;
485 /// Environment variables, used for the `env!` macro 504 /// Environment variables, used for
505 /// the `env!` macro
486 env: : { [key: string]: string; }, 506 env: : { [key: string]: string; },
487 507
488 /// For proc-macro crates, path to compiles proc-macro (.so file). 508 /// For proc-macro crates, path to compiled
509 /// proc-macro (.so file).
489 proc_macro_dylib_path?: string; 510 proc_macro_dylib_path?: string;
490} 511}
491 512
492interface Dep { 513interface Dep {
493 /// Index of a crate in the `crates` array. 514 /// Index of a crate in the `crates` array.
494 crate: number, 515 crate: number,
495 /// Name as should appear in the (implicit) `extern crate name` declaration. 516 /// Name as should appear in the (implicit)
517 /// `extern crate name` declaration.
496 name: string, 518 name: string,
497} 519}
498---- 520----
@@ -541,7 +563,7 @@ include::./generated_assists.adoc[]
541== Diagnostics 563== Diagnostics
542 564
543While most errors and warnings provided by rust-analyzer come from the `cargo check` integration, there's a growing number of diagnostics implemented using rust-analyzer's own analysis. 565While most errors and warnings provided by rust-analyzer come from the `cargo check` integration, there's a growing number of diagnostics implemented using rust-analyzer's own analysis.
544These diagnostics don't respect `#[allow]` or `#[deny]` attributes yet, but can be turned off using the `rust-analyzer.diagnostics.enable`, `rust-analyzer.diagnostics.enableExperimental` or `rust-analyzer.diagnostics.disabled` settings. 566Some of these diagnostics don't respect `\#[allow]` or `\#[deny]` attributes yet, but can be turned off using the `rust-analyzer.diagnostics.enable`, `rust-analyzer.diagnostics.enableExperimental` or `rust-analyzer.diagnostics.disabled` settings.
545 567
546include::./generated_diagnostic.adoc[] 568include::./generated_diagnostic.adoc[]
547 569