diff options
Diffstat (limited to 'docs/dev')
-rw-r--r-- | docs/dev/README.md | 2 | ||||
-rw-r--r-- | docs/dev/architecture.md | 11 | ||||
-rw-r--r-- | docs/dev/guide.md | 10 | ||||
-rw-r--r-- | docs/dev/lsp-extensions.md | 20 | ||||
-rw-r--r-- | docs/dev/style.md | 10 |
5 files changed, 28 insertions, 25 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md index d6fae5295..b91013f13 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md | |||
@@ -58,8 +58,6 @@ Use `env RUN_SLOW_TESTS=1 cargo test` to run the full suite. | |||
58 | 58 | ||
59 | We use bors-ng to enforce the [not rocket science](https://graydon2.dreamwidth.org/1597.html) rule. | 59 | We use bors-ng to enforce the [not rocket science](https://graydon2.dreamwidth.org/1597.html) rule. |
60 | 60 | ||
61 | You can run `cargo xtask install-pre-commit-hook` to install git-hook to run rustfmt on commit. | ||
62 | |||
63 | # Launching rust-analyzer | 61 | # Launching rust-analyzer |
64 | 62 | ||
65 | Debugging the language server can be tricky. | 63 | Debugging the language server can be tricky. |
diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md index ead12616e..fb991133a 100644 --- a/docs/dev/architecture.md +++ b/docs/dev/architecture.md | |||
@@ -46,7 +46,7 @@ This is *the* entry point, but it front-loads a lot of complexity, so its fine t | |||
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 | ||
49 | `Analysis` and `AnalysisHost` types define the main API. | 49 | `Analysis` and `AnalysisHost` types define the main API for consumers of IDE services. |
50 | 50 | ||
51 | ## Code Map | 51 | ## Code Map |
52 | 52 | ||
@@ -97,13 +97,13 @@ See [RFC](https://github.com/rust-lang/rfcs/pull/2256) and [./syntax.md](./synta | |||
97 | 97 | ||
98 | - [rowan](https://github.com/rust-analyzer/rowan) library is used for constructing syntax trees. | 98 | - [rowan](https://github.com/rust-analyzer/rowan) library is used for constructing syntax trees. |
99 | - `ast` provides a type safe API on top of the raw `rowan` tree. | 99 | - `ast` provides a type safe API on top of the raw `rowan` tree. |
100 | - `ungrammar` description of the grammar, which is used to generate `syntax_kinds` and `ast` modules, using `cargo xtask codegen` command. | 100 | - `ungrammar` description of the grammar, which is used to generate `syntax_kinds` and `ast` modules, using `cargo test -p xtask` command. |
101 | 101 | ||
102 | Tests for ra_syntax are mostly data-driven. | 102 | Tests for ra_syntax are mostly data-driven. |
103 | `test_data/parser` contains subdirectories with a bunch of `.rs` (test vectors) and `.txt` files with corresponding syntax trees. | 103 | `test_data/parser` contains subdirectories with a bunch of `.rs` (test vectors) and `.txt` files with corresponding syntax trees. |
104 | During testing, we check `.rs` against `.txt`. | 104 | During testing, we check `.rs` against `.txt`. |
105 | If the `.txt` file is missing, it is created (this is how you update tests). | 105 | If the `.txt` file is missing, it is created (this is how you update tests). |
106 | Additionally, running `cargo xtask codegen` will walk the grammar module and collect all `// test test_name` comments into files inside `test_data/parser/inline` directory. | 106 | Additionally, running the xtask test suite with `cargo test -p xtask` will walk the grammar module and collect all `// test test_name` comments into files inside `test_data/parser/inline` directory. |
107 | 107 | ||
108 | To update test data, run with `UPDATE_EXPECT` variable: | 108 | To update test data, run with `UPDATE_EXPECT` variable: |
109 | 109 | ||
@@ -111,7 +111,7 @@ To update test data, run with `UPDATE_EXPECT` variable: | |||
111 | env UPDATE_EXPECT=1 cargo qt | 111 | env UPDATE_EXPECT=1 cargo qt |
112 | ``` | 112 | ``` |
113 | 113 | ||
114 | After adding a new inline test you need to run `cargo xtest codegen` and also update the test data as described above. | 114 | After adding a new inline test you need to run `cargo test -p xtask` and also update the test data as described above. |
115 | 115 | ||
116 | Note [`api_walkthrough`](https://github.com/rust-analyzer/rust-analyzer/blob/2fb6af89eb794f775de60b82afe56b6f986c2a40/crates/ra_syntax/src/lib.rs#L190-L348) | 116 | Note [`api_walkthrough`](https://github.com/rust-analyzer/rust-analyzer/blob/2fb6af89eb794f775de60b82afe56b6f986c2a40/crates/ra_syntax/src/lib.rs#L190-L348) |
117 | in particular: it shows off various methods of working with syntax tree. | 117 | in particular: it shows off various methods of working with syntax tree. |
@@ -308,9 +308,8 @@ This sections talks about the things which are everywhere and nowhere in particu | |||
308 | ### Code generation | 308 | ### Code generation |
309 | 309 | ||
310 | Some of the components of this repository are generated through automatic processes. | 310 | Some of the components of this repository are generated through automatic processes. |
311 | `cargo xtask codegen` runs all generation tasks. | 311 | Generated code is updated automatically on `cargo test`. |
312 | Generated code is generally committed to the git repository. | 312 | Generated code is generally committed to the git repository. |
313 | There are tests to check that the generated code is fresh. | ||
314 | 313 | ||
315 | In particular, we generate: | 314 | In particular, we generate: |
316 | 315 | ||
diff --git a/docs/dev/guide.md b/docs/dev/guide.md index b5a5d7c93..c1a55c56c 100644 --- a/docs/dev/guide.md +++ b/docs/dev/guide.md | |||
@@ -65,11 +65,11 @@ Next, let's talk about what the inputs to the `Analysis` are, precisely. | |||
65 | 65 | ||
66 | Rust Analyzer never does any I/O itself, all inputs get passed explicitly via | 66 | Rust Analyzer never does any I/O itself, all inputs get passed explicitly via |
67 | the `AnalysisHost::apply_change` method, which accepts a single argument, a | 67 | the `AnalysisHost::apply_change` method, which accepts a single argument, a |
68 | `AnalysisChange`. [`AnalysisChange`] is a builder for a single change | 68 | `Change`. [`Change`] is a builder for a single change |
69 | "transaction", so it suffices to study its methods to understand all of the | 69 | "transaction", so it suffices to study its methods to understand all of the |
70 | input data. | 70 | input data. |
71 | 71 | ||
72 | [`AnalysisChange`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/lib.rs#L119-L167 | 72 | [`Change`]: https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/base_db/src/change.rs#L14-L89 |
73 | 73 | ||
74 | The `(add|change|remove)_file` methods control the set of the input files, where | 74 | The `(add|change|remove)_file` methods control the set of the input files, where |
75 | each file has an integer id (`FileId`, picked by the client), text (`String`) | 75 | each file has an integer id (`FileId`, picked by the client), text (`String`) |
@@ -158,7 +158,7 @@ it should be possible to dynamically reconfigure it later without restart. | |||
158 | [main_loop.rs#L62-L70](https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/main_loop.rs#L62-L70) | 158 | [main_loop.rs#L62-L70](https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/main_loop.rs#L62-L70) |
159 | 159 | ||
160 | The [`ProjectModel`] we get after this step is very Cargo and sysroot specific, | 160 | The [`ProjectModel`] we get after this step is very Cargo and sysroot specific, |
161 | it needs to be lowered to get the input in the form of `AnalysisChange`. This | 161 | it needs to be lowered to get the input in the form of `Change`. This |
162 | happens in [`ServerWorldState::new`] method. Specifically | 162 | happens in [`ServerWorldState::new`] method. Specifically |
163 | 163 | ||
164 | * Create a `SourceRoot` for each Cargo package and sysroot. | 164 | * Create a `SourceRoot` for each Cargo package and sysroot. |
@@ -175,7 +175,7 @@ of the main loop, just like any other change. Here's where we handle: | |||
175 | * [File system changes](https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/main_loop.rs#L194) | 175 | * [File system changes](https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/main_loop.rs#L194) |
176 | * [Changes from the editor](https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/main_loop.rs#L377) | 176 | * [Changes from the editor](https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/main_loop.rs#L377) |
177 | 177 | ||
178 | After a single loop's turn, we group the changes into one `AnalysisChange` and | 178 | After a single loop's turn, we group the changes into one `Change` and |
179 | [apply] it. This always happens on the main thread and blocks the loop. | 179 | [apply] it. This always happens on the main thread and blocks the loop. |
180 | 180 | ||
181 | [apply]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/server_world.rs#L216 | 181 | [apply]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/server_world.rs#L216 |
@@ -256,7 +256,7 @@ database. | |||
256 | [`RootDatabase`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/db.rs#L88-L134 | 256 | [`RootDatabase`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/db.rs#L88-L134 |
257 | 257 | ||
258 | Salsa input queries are defined in [`FilesDatabase`] (which is a part of | 258 | Salsa input queries are defined in [`FilesDatabase`] (which is a part of |
259 | `RootDatabase`). They closely mirror the familiar `AnalysisChange` structure: | 259 | `RootDatabase`). They closely mirror the familiar `Change` structure: |
260 | indeed, what `apply_change` does is it sets the values of input queries. | 260 | indeed, what `apply_change` does is it sets the values of input queries. |
261 | 261 | ||
262 | [`FilesDatabase`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/base_db/src/input.rs#L150-L174 | 262 | [`FilesDatabase`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/base_db/src/input.rs#L150-L174 |
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md index 6c34c4021..694fafcd5 100644 --- a/docs/dev/lsp-extensions.md +++ b/docs/dev/lsp-extensions.md | |||
@@ -39,7 +39,7 @@ If a language client does not know about `rust-analyzer`'s configuration options | |||
39 | 39 | ||
40 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/724 | 40 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/724 |
41 | 41 | ||
42 | **Client Capability:** `{ "snippetTextEdit": boolean }` | 42 | **Experimental Client Capability:** `{ "snippetTextEdit": boolean }` |
43 | 43 | ||
44 | If this capability is set, `WorkspaceEdit`s returned from `codeAction` requests might contain `SnippetTextEdit`s instead of usual `TextEdit`s: | 44 | If this capability is set, `WorkspaceEdit`s returned from `codeAction` requests might contain `SnippetTextEdit`s instead of usual `TextEdit`s: |
45 | 45 | ||
@@ -72,7 +72,7 @@ At the moment, rust-analyzer guarantees that only a single edit will have `Inser | |||
72 | 72 | ||
73 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/994 | 73 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/994 |
74 | 74 | ||
75 | **Client Capability:** `{ "codeActionGroup": boolean }` | 75 | **Experimental Client Capability:** `{ "codeActionGroup": boolean }` |
76 | 76 | ||
77 | If this capability is set, `CodeAction` returned from the server contain an additional field, `group`: | 77 | If this capability is set, `CodeAction` returned from the server contain an additional field, `group`: |
78 | 78 | ||
@@ -119,7 +119,7 @@ Invoking code action at this position will yield two code actions for importing | |||
119 | 119 | ||
120 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/1002 | 120 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/1002 |
121 | 121 | ||
122 | **Server Capability:** `{ "parentModule": boolean }` | 122 | **Experimental Server Capability:** `{ "parentModule": boolean }` |
123 | 123 | ||
124 | This request is sent from client to server to handle "Goto Parent Module" editor action. | 124 | This request is sent from client to server to handle "Goto Parent Module" editor action. |
125 | 125 | ||
@@ -153,7 +153,7 @@ mod foo; | |||
153 | 153 | ||
154 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/992 | 154 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/992 |
155 | 155 | ||
156 | **Server Capability:** `{ "joinLines": boolean }` | 156 | **Experimental Server Capability:** `{ "joinLines": boolean }` |
157 | 157 | ||
158 | This request is sent from client to server to handle "Join Lines" editor action. | 158 | This request is sent from client to server to handle "Join Lines" editor action. |
159 | 159 | ||
@@ -200,7 +200,7 @@ fn main() { | |||
200 | 200 | ||
201 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/1001 | 201 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/1001 |
202 | 202 | ||
203 | **Server Capability:** `{ "onEnter": boolean }` | 203 | **Experimental Server Capability:** `{ "onEnter": boolean }` |
204 | 204 | ||
205 | This request is sent from client to server to handle <kbd>Enter</kbd> keypress. | 205 | This request is sent from client to server to handle <kbd>Enter</kbd> keypress. |
206 | 206 | ||
@@ -251,7 +251,7 @@ As proper cursor positioning is raison-d'etat for `onEnter`, it uses `SnippetTex | |||
251 | 251 | ||
252 | ## Structural Search Replace (SSR) | 252 | ## Structural Search Replace (SSR) |
253 | 253 | ||
254 | **Server Capability:** `{ "ssr": boolean }` | 254 | **Experimental Server Capability:** `{ "ssr": boolean }` |
255 | 255 | ||
256 | This request is sent from client to server to handle structural search replace -- automated syntax tree based transformation of the source. | 256 | This request is sent from client to server to handle structural search replace -- automated syntax tree based transformation of the source. |
257 | 257 | ||
@@ -293,7 +293,7 @@ SSR with query `foo($a, $b) ==>> ($a).foo($b)` will transform, eg `foo(y + 5, z) | |||
293 | 293 | ||
294 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/999 | 294 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/999 |
295 | 295 | ||
296 | **Server Capability:** `{ "matchingBrace": boolean }` | 296 | **Experimental Server Capability:** `{ "matchingBrace": boolean }` |
297 | 297 | ||
298 | This request is sent from client to server to handle "Matching Brace" editor action. | 298 | This request is sent from client to server to handle "Matching Brace" editor action. |
299 | 299 | ||
@@ -338,7 +338,7 @@ Moreover, it would be cool if editors didn't need to implement even basic langua | |||
338 | 338 | ||
339 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/944 | 339 | **Issue:** https://github.com/microsoft/language-server-protocol/issues/944 |
340 | 340 | ||
341 | **Server Capability:** `{ "runnables": { "kinds": string[] } }` | 341 | **Experimental Server Capability:** `{ "runnables": { "kinds": string[] } }` |
342 | 342 | ||
343 | This request is sent from client to server to get the list of things that can be run (tests, binaries, `cargo check -p`). | 343 | This request is sent from client to server to get the list of things that can be run (tests, binaries, `cargo check -p`). |
344 | 344 | ||
@@ -421,7 +421,7 @@ Reloads project information (that is, re-executes `cargo metadata`). | |||
421 | 421 | ||
422 | ## Status Notification | 422 | ## Status Notification |
423 | 423 | ||
424 | **Client Capability:** `{ "statusNotification": boolean }` | 424 | **Experimental Client Capability:** `{ "statusNotification": boolean }` |
425 | 425 | ||
426 | **Method:** `rust-analyzer/status` | 426 | **Method:** `rust-analyzer/status` |
427 | 427 | ||
@@ -519,7 +519,7 @@ interface InlayHint { | |||
519 | 519 | ||
520 | ## Hover Actions | 520 | ## Hover Actions |
521 | 521 | ||
522 | **Client Capability:** `{ "hoverActions": boolean }` | 522 | **Experimental Client Capability:** `{ "hoverActions": boolean }` |
523 | 523 | ||
524 | If this capability is set, `Hover` request returned from the server might contain an additional field, `actions`: | 524 | If this capability is set, `Hover` request returned from the server might contain an additional field, `actions`: |
525 | 525 | ||
diff --git a/docs/dev/style.md b/docs/dev/style.md index dd71e3932..46bd8b9b2 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md | |||
@@ -145,7 +145,7 @@ Formatting ensures that you can use your editor's "number of selected characters | |||
145 | ## Marked Tests | 145 | ## Marked Tests |
146 | 146 | ||
147 | Use | 147 | Use |
148 | [`mark::hit! / mark::check!`](https://github.com/rust-analyzer/rust-analyzer/blob/71fe719dd5247ed8615641d9303d7ca1aa201c2f/crates/test_utils/src/mark.rs) | 148 | [`cov_mark::hit! / cov_mark::check!`](https://github.com/matklad/cov-mark) |
149 | when testing specific conditions. | 149 | when testing specific conditions. |
150 | Do not place several marks into a single test or condition. | 150 | Do not place several marks into a single test or condition. |
151 | Do not reuse marks between several tests. | 151 | Do not reuse marks between several tests. |
@@ -769,14 +769,20 @@ fn foo() -> Option<Bar> { | |||
769 | 769 | ||
770 | ## Comparisons | 770 | ## Comparisons |
771 | 771 | ||
772 | Use `<`/`<=`, avoid `>`/`>=`. | 772 | When doing multiple comparisons use `<`/`<=`, avoid `>`/`>=`. |
773 | 773 | ||
774 | ```rust | 774 | ```rust |
775 | // GOOD | 775 | // GOOD |
776 | assert!(lo <= x && x <= hi); | 776 | assert!(lo <= x && x <= hi); |
777 | assert!(r1 < l2 || r2 < l1); | ||
778 | assert!(x < y); | ||
779 | assert!(x > 0); | ||
777 | 780 | ||
778 | // BAD | 781 | // BAD |
779 | assert!(x >= lo && x <= hi>); | 782 | assert!(x >= lo && x <= hi>); |
783 | assert!(r1 < l2 || l1 > r2); | ||
784 | assert!(y > x); | ||
785 | assert!(0 > x); | ||
780 | ``` | 786 | ``` |
781 | 787 | ||
782 | **Rationale:** Less-then comparisons are more intuitive, they correspond spatially to [real line](https://en.wikipedia.org/wiki/Real_line). | 788 | **Rationale:** Less-then comparisons are more intuitive, they correspond spatially to [real line](https://en.wikipedia.org/wiki/Real_line). |