aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorGalilée 'Bill' Enguehard <[email protected]>2020-05-21 22:27:38 +0100
committerGalilée 'Bill' Enguehard <[email protected]>2020-05-21 22:27:38 +0100
commit7fece3bdd2450c0807f7dd742239cae95f0cc65e (patch)
tree866c4db826c959e79c63a6727bdb9f2c61e6fc4f /docs
parentdb926218b2082077750291f8426ddd28b284cd08 (diff)
parent59732df8d40dfadc6dcf5951265416576399712a (diff)
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer into modname_spacing
Diffstat (limited to 'docs')
-rw-r--r--docs/dev/README.md6
-rw-r--r--docs/dev/debugging.md14
-rw-r--r--docs/dev/lsp-extensions.md86
-rw-r--r--docs/dev/syntax.md42
-rw-r--r--docs/user/assists.md96
-rw-r--r--docs/user/features.md14
-rw-r--r--docs/user/readme.adoc41
7 files changed, 232 insertions, 67 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md
index f230dc1db..65cc9fc12 100644
--- a/docs/dev/README.md
+++ b/docs/dev/README.md
@@ -74,7 +74,7 @@ relevant test and execute it (VS Code includes an action for running a single
74test). 74test).
75 75
76However, launching a VS Code instance with locally build language server is 76However, launching a VS Code instance with locally build language server is
77possible. There's **"Run Extension (Dev Server)"** launch configuration for this. 77possible. There's **"Run Extension (Debug Build)"** launch configuration for this.
78 78
79In general, I use one of the following workflows for fixing bugs and 79In general, I use one of the following workflows for fixing bugs and
80implementing features. 80implementing features.
@@ -86,7 +86,7 @@ then just do printf-driven development/debugging. As a sanity check after I'm
86done, I use `cargo xtask install --server` and **Reload Window** action in VS 86done, I use `cargo xtask install --server` and **Reload Window** action in VS
87Code to sanity check that the thing works as I expect. 87Code to sanity check that the thing works as I expect.
88 88
89If the problem concerns only the VS Code extension, I use **Run Extension** 89If the problem concerns only the VS Code extension, I use **Run Installed Extension**
90launch configuration from `launch.json`. Notably, this uses the usual 90launch configuration from `launch.json`. Notably, this uses the usual
91`rust-analyzer` binary from `PATH`. For this it is important to have the following 91`rust-analyzer` binary from `PATH`. For this it is important to have the following
92in `setting.json` file: 92in `setting.json` file:
@@ -134,7 +134,7 @@ To log all communication between the server and the client, there are two choice
134 134
135* you can log on the server side, by running something like 135* you can log on the server side, by running something like
136 ``` 136 ```
137 env RUST_LOG=gen_lsp_server=trace code . 137 env RA_LOG=gen_lsp_server=trace code .
138 ``` 138 ```
139 139
140* you can log on the client side, by enabling `"rust-analyzer.trace.server": 140* you can log on the client side, by enabling `"rust-analyzer.trace.server":
diff --git a/docs/dev/debugging.md b/docs/dev/debugging.md
index bece6a572..59a83f7d7 100644
--- a/docs/dev/debugging.md
+++ b/docs/dev/debugging.md
@@ -22,11 +22,11 @@ where **only** the `rust-analyzer` extension being debugged is enabled.
22 22
23## Debug TypeScript VSCode extension 23## Debug TypeScript VSCode extension
24 24
25- `Run Extension` - runs the extension with the globally installed `rust-analyzer` binary. 25- `Run Installed Extension` - runs the extension with the globally installed `rust-analyzer` binary.
26- `Run Extension (Dev Server)` - runs extension with the locally built LSP server (`target/debug/rust-analyzer`). 26- `Run Extension (Debug Build)` - runs extension with the locally built LSP server (`target/debug/rust-analyzer`).
27 27
28TypeScript debugging is configured to watch your source edits and recompile. 28TypeScript debugging is configured to watch your source edits and recompile.
29To apply changes to an already running debug process press <kbd>Ctrl+Shift+P</kbd> and run the following command in your `[Extension Development Host]` 29To apply changes to an already running debug process, press <kbd>Ctrl+Shift+P</kbd> and run the following command in your `[Extension Development Host]`
30 30
31``` 31```
32> Developer: Reload Window 32> Developer: Reload Window
@@ -47,7 +47,7 @@ To apply changes to an already running debug process press <kbd>Ctrl+Shift+P</kb
47 debug = 2 47 debug = 2
48 ``` 48 ```
49 49
50- Select `Run Extension (Dev Server)` to run your locally built `target/debug/rust-analyzer`. 50- Select `Run Extension (Debug Build)` to run your locally built `target/debug/rust-analyzer`.
51 51
52- In the original VSCode window once again select the `Attach To Server` debug configuration. 52- In the original VSCode window once again select the `Attach To Server` debug configuration.
53 53
@@ -76,11 +76,11 @@ Make sure you open a rust file in the `[Extension Development Host]` and try aga
76 76
77Make sure you have run `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`. 77Make sure you have run `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`.
78 78
79By default this should reset back to 1 everytime you log in. 79By default this should reset back to 1 every time you log in.
80 80
81### Breakpoints are never being hit 81### Breakpoints are never being hit
82 82
83Check your version of `lldb` if it's version 6 and lower use the `classic` adapter type. 83Check your version of `lldb`. If it's version 6 and lower, use the `classic` adapter type.
84It's `lldb.adapterType` in settings file. 84It's `lldb.adapterType` in settings file.
85 85
86If you're running `lldb` version 7 change the lldb adapter type to `bundled` or `native`. 86If you're running `lldb` version 7, change the lldb adapter type to `bundled` or `native`.
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
new file mode 100644
index 000000000..0e3a0af1c
--- /dev/null
+++ b/docs/dev/lsp-extensions.md
@@ -0,0 +1,86 @@
1# LSP Extensions
2
3This document describes LSP extensions used by rust-analyzer.
4It's a best effort document, when in doubt, consult the source (and send a PR with clarification ;-) ).
5We aim to upstream all non Rust-specific extensions to the protocol, but this is not a top priority.
6All capabilities are enabled via `experimental` field of `ClientCapabilities`.
7
8## `SnippetTextEdit`
9
10**Client Capability:** `{ "snippetTextEdit": boolean }`
11
12If this capability is set, `WorkspaceEdit`s returned from `codeAction` requests might contain `SnippetTextEdit`s instead of usual `TextEdit`s:
13
14```typescript
15interface SnippetTextEdit extends TextEdit {
16 insertTextFormat?: InsertTextFormat;
17}
18```
19
20```typescript
21export interface TextDocumentEdit {
22 textDocument: VersionedTextDocumentIdentifier;
23 edits: (TextEdit | SnippetTextEdit)[];
24}
25```
26
27When applying such code action, the editor should insert snippet, with tab stops and placeholder.
28At the moment, rust-analyzer guarantees that only a single edit will have `InsertTextFormat.Snippet`.
29
30### Example
31
32"Add `derive`" code action transforms `struct S;` into `#[derive($0)] struct S;`
33
34### Unresolved Questions
35
36* Where exactly are `SnippetTextEdit`s allowed (only in code actions at the moment)?
37* Can snippets span multiple files (so far, no)?
38
39## `joinLines`
40
41**Server Capability:** `{ "joinLines": boolean }`
42
43This request is send from client to server to handle "Join Lines" editor action.
44
45**Method:** `experimental/JoinLines`
46
47**Request:**
48
49```typescript
50interface JoinLinesParams {
51 textDocument: TextDocumentIdentifier,
52 /// Currently active selections/cursor offsets.
53 /// This is an array to support multiple cursors.
54 ranges: Range[],
55}
56```
57
58**Response:**
59
60```typescript
61TextEdit[]
62```
63
64### Example
65
66```rust
67fn main() {
68 /*cursor here*/let x = {
69 92
70 };
71}
72```
73
74`experimental/joinLines` yields (curly braces are automagiacally removed)
75
76```rust
77fn main() {
78 let x = 92;
79}
80```
81
82### Unresolved Question
83
84* What is the position of the cursor after `joinLines`?
85 Currently this is left to editor's discretion, but it might be useful to specify on the server via snippets.
86 However, it then becomes unclear how it works with multi cursor.
diff --git a/docs/dev/syntax.md b/docs/dev/syntax.md
index 33973ffec..c2864bbbc 100644
--- a/docs/dev/syntax.md
+++ b/docs/dev/syntax.md
@@ -64,7 +64,7 @@ struct Token {
64} 64}
65``` 65```
66 66
67All the difference bettwen the above sketch and the real implementation are strictly due to optimizations. 67All the difference between the above sketch and the real implementation are strictly due to optimizations.
68 68
69Points of note: 69Points of note:
70* The tree is untyped. Each node has a "type tag", `SyntaxKind`. 70* The tree is untyped. Each node has a "type tag", `SyntaxKind`.
@@ -72,7 +72,7 @@ Points of note:
72* Trivia and non-trivia tokens are not distinguished on the type level. 72* Trivia and non-trivia tokens are not distinguished on the type level.
73* Each token carries its full text. 73* Each token carries its full text.
74* The original text can be recovered by concatenating the texts of all tokens in order. 74* The original text can be recovered by concatenating the texts of all tokens in order.
75* Accessing a child of particular type (for example, parameter list of a function) generarly involves linerary traversing the children, looking for a specific `kind`. 75* Accessing a child of particular type (for example, parameter list of a function) generally involves linerary traversing the children, looking for a specific `kind`.
76* Modifying the tree is roughly `O(depth)`. 76* Modifying the tree is roughly `O(depth)`.
77 We don't make special efforts to guarantree that the depth is not liner, but, in practice, syntax trees are branchy and shallow. 77 We don't make special efforts to guarantree that the depth is not liner, but, in practice, syntax trees are branchy and shallow.
78* If mandatory (grammar wise) node is missing from the input, it's just missing from the tree. 78* If mandatory (grammar wise) node is missing from the input, it's just missing from the tree.
@@ -123,7 +123,7 @@ To more compactly store the children, we box *both* interior nodes and tokens, a
123`Either<Arc<Node>, Arc<Token>>` as a single pointer with a tag in the last bit. 123`Either<Arc<Node>, Arc<Token>>` as a single pointer with a tag in the last bit.
124 124
125To avoid allocating EVERY SINGLE TOKEN on the heap, syntax trees use interning. 125To avoid allocating EVERY SINGLE TOKEN on the heap, syntax trees use interning.
126Because the tree is fully imutable, it's valid to structuraly share subtrees. 126Because the tree is fully immutable, it's valid to structurally share subtrees.
127For example, in `1 + 1`, there will be a *single* token for `1` with ref count 2; the same goes for the ` ` whitespace token. 127For example, in `1 + 1`, there will be a *single* token for `1` with ref count 2; the same goes for the ` ` whitespace token.
128Interior nodes are shared as well (for example in `(1 + 1) * (1 + 1)`). 128Interior nodes are shared as well (for example in `(1 + 1) * (1 + 1)`).
129 129
@@ -134,8 +134,8 @@ Currently, the interner is created per-file, but it will be easy to use a per-th
134 134
135We use a `TextSize`, a newtyped `u32`, to store the length of the text. 135We use a `TextSize`, a newtyped `u32`, to store the length of the text.
136 136
137We currently use `SmolStr`, an small object optimized string to store text. 137We currently use `SmolStr`, a small object optimized string to store text.
138This was mostly relevant *before* we implmented tree interning, to avoid allocating common keywords and identifiers. We should switch to storing text data alongside the interned tokens. 138This was mostly relevant *before* we implemented tree interning, to avoid allocating common keywords and identifiers. We should switch to storing text data alongside the interned tokens.
139 139
140#### Alternative designs 140#### Alternative designs
141 141
@@ -162,12 +162,12 @@ Explicit trivia nodes, like in `rowan`, are used by IntelliJ.
162 162
163##### Accessing Children 163##### Accessing Children
164 164
165As noted before, accesing a specific child in the node requires a linear traversal of the children (though we can skip tokens, beacuse the tag is encoded in the pointer itself). 165As noted before, accessing a specific child in the node requires a linear traversal of the children (though we can skip tokens, because the tag is encoded in the pointer itself).
166It is possible to recover O(1) access with another representation. 166It is possible to recover O(1) access with another representation.
167We explicitly store optional and missing (required by the grammar, but not present) nodes. 167We explicitly store optional and missing (required by the grammar, but not present) nodes.
168That is, we use `Option<Node>` for children. 168That is, we use `Option<Node>` for children.
169We also remove trivia tokens from the tree. 169We also remove trivia tokens from the tree.
170This way, each child kind genrerally occupies a fixed position in a parent, and we can use index access to fetch it. 170This way, each child kind generally occupies a fixed position in a parent, and we can use index access to fetch it.
171The cost is that we now need to allocate space for all not-present optional nodes. 171The cost is that we now need to allocate space for all not-present optional nodes.
172So, `fn foo() {}` will have slots for visibility, unsafeness, attributes, abi and return type. 172So, `fn foo() {}` will have slots for visibility, unsafeness, attributes, abi and return type.
173 173
@@ -193,7 +193,7 @@ Modeling this with immutable trees is possible, but annoying.
193### Syntax Nodes 193### Syntax Nodes
194 194
195A function green tree is not super-convenient to use. 195A function green tree is not super-convenient to use.
196The biggest problem is acessing parents (there are no parent pointers!). 196The biggest problem is accessing parents (there are no parent pointers!).
197But there are also "identify" issues. 197But there are also "identify" issues.
198Let's say you want to write a code which builds a list of expressions in a file: `fn collect_exrepssions(file: GreenNode) -> HashSet<GreenNode>`. 198Let's say you want to write a code which builds a list of expressions in a file: `fn collect_exrepssions(file: GreenNode) -> HashSet<GreenNode>`.
199For the input like 199For the input like
@@ -207,7 +207,7 @@ fn main() {
207} 207}
208``` 208```
209 209
210both copies of the `x + 2` expression are representing by equal (and, with interning in mind, actualy the same) green nodes. 210both copies of the `x + 2` expression are representing by equal (and, with interning in mind, actually the same) green nodes.
211Green trees just can't differentiate between the two. 211Green trees just can't differentiate between the two.
212 212
213`SyntaxNode` adds parent pointers and identify semantics to green nodes. 213`SyntaxNode` adds parent pointers and identify semantics to green nodes.
@@ -285,9 +285,9 @@ They also point to the parent (and, consequently, to the root) with an owning `R
285In other words, one needs *one* arc bump when initiating a traversal. 285In other words, one needs *one* arc bump when initiating a traversal.
286 286
287To get rid of allocations, `rowan` takes advantage of `SyntaxNode: !Sync` and uses a thread-local free list of `SyntaxNode`s. 287To get rid of allocations, `rowan` takes advantage of `SyntaxNode: !Sync` and uses a thread-local free list of `SyntaxNode`s.
288In a typical traversal, you only directly hold a few `SyntaxNode`s at a time (and their ancesstors indirectly), so a free list proportional to the depth of the tree removes all allocations in a typical case. 288In a typical traversal, you only directly hold a few `SyntaxNode`s at a time (and their ancestors indirectly), so a free list proportional to the depth of the tree removes all allocations in a typical case.
289 289
290So, while traversal is not exactly incrementing a pointer, it's still prety cheep: tls + rc bump! 290So, while traversal is not exactly incrementing a pointer, it's still pretty cheap: TLS + rc bump!
291 291
292Traversal also yields (cheap) owned nodes, which improves ergonomics quite a bit. 292Traversal also yields (cheap) owned nodes, which improves ergonomics quite a bit.
293 293
@@ -308,15 +308,15 @@ struct SyntaxData {
308} 308}
309``` 309```
310 310
311This allows using true pointer equality for comparision of identities of `SyntaxNodes`. 311This allows using true pointer equality for comparison of identities of `SyntaxNodes`.
312rust-analyzer used to have this design as well, but since we've switch to cursors. 312rust-analyzer used to have this design as well, but we've since switched to cursors.
313The main problem with memoizing the red nodes is that it more than doubles the memory requirenments for fully realized syntax trees. 313The main problem with memoizing the red nodes is that it more than doubles the memory requirements for fully realized syntax trees.
314In contrast, cursors generally retain only a path to the root. 314In contrast, cursors generally retain only a path to the root.
315C# combats increased memory usage by using weak references. 315C# combats increased memory usage by using weak references.
316 316
317### AST 317### AST
318 318
319`GreenTree`s are untyped and homogeneous, because it makes accomodating error nodes, arbitrary whitespace and comments natural, and because it makes possible to write generic tree traversals. 319`GreenTree`s are untyped and homogeneous, because it makes accommodating error nodes, arbitrary whitespace and comments natural, and because it makes possible to write generic tree traversals.
320However, when working with a specific node, like a function definition, one would want a strongly typed API. 320However, when working with a specific node, like a function definition, one would want a strongly typed API.
321 321
322This is what is provided by the AST layer. AST nodes are transparent wrappers over untyped syntax nodes: 322This is what is provided by the AST layer. AST nodes are transparent wrappers over untyped syntax nodes:
@@ -397,7 +397,7 @@ impl HasVisbility for FnDef {
397Points of note: 397Points of note:
398 398
399* Like `SyntaxNode`s, AST nodes are cheap to clone pointer-sized owned values. 399* Like `SyntaxNode`s, AST nodes are cheap to clone pointer-sized owned values.
400* All "fields" are optional, to accomodate incomplete and/or erroneous source code. 400* All "fields" are optional, to accommodate incomplete and/or erroneous source code.
401* It's always possible to go from an ast node to an untyped `SyntaxNode`. 401* It's always possible to go from an ast node to an untyped `SyntaxNode`.
402* It's possible to go in the opposite direction with a checked cast. 402* It's possible to go in the opposite direction with a checked cast.
403* `enum`s allow modeling of arbitrary intersecting subsets of AST types. 403* `enum`s allow modeling of arbitrary intersecting subsets of AST types.
@@ -437,13 +437,13 @@ impl GreenNodeBuilder {
437} 437}
438``` 438```
439 439
440The parser, ultimatelly, needs to invoke the `GreenNodeBuilder`. 440The parser, ultimately, needs to invoke the `GreenNodeBuilder`.
441There are two principal sources of inputs for the parser: 441There are two principal sources of inputs for the parser:
442 * source text, which contains trivia tokens (whitespace and comments) 442 * source text, which contains trivia tokens (whitespace and comments)
443 * token trees from macros, which lack trivia 443 * token trees from macros, which lack trivia
444 444
445Additionaly, input tokens do not correspond 1-to-1 with output tokens. 445Additionally, input tokens do not correspond 1-to-1 with output tokens.
446For example, two consequtive `>` tokens might be glued, by the parser, into a single `>>`. 446For example, two consecutive `>` tokens might be glued, by the parser, into a single `>>`.
447 447
448For these reasons, the parser crate defines a callback interfaces for both input tokens and output trees. 448For these reasons, the parser crate defines a callback interfaces for both input tokens and output trees.
449The explicit glue layer then bridges various gaps. 449The explicit glue layer then bridges various gaps.
@@ -491,7 +491,7 @@ Syntax errors are not stored directly in the tree.
491The primary motivation for this is that syntax tree is not necessary produced by the parser, it may also be assembled manually from pieces (which happens all the time in refactorings). 491The primary motivation for this is that syntax tree is not necessary produced by the parser, it may also be assembled manually from pieces (which happens all the time in refactorings).
492Instead, parser reports errors to an error sink, which stores them in a `Vec`. 492Instead, parser reports errors to an error sink, which stores them in a `Vec`.
493If possible, errors are not reported during parsing and are postponed for a separate validation step. 493If possible, errors are not reported during parsing and are postponed for a separate validation step.
494For example, parser accepts visibility modifiers on trait methods, but then a separate tree traversal flags all such visibilites as erroneous. 494For example, parser accepts visibility modifiers on trait methods, but then a separate tree traversal flags all such visibilities as erroneous.
495 495
496### Macros 496### Macros
497 497
@@ -501,7 +501,7 @@ Specifically, `TreeSink` constructs the tree in lockstep with draining the origi
501In the process, it records which tokens of the tree correspond to which tokens of the input, by using text ranges to identify syntax tokens. 501In the process, it records which tokens of the tree correspond to which tokens of the input, by using text ranges to identify syntax tokens.
502The end result is that parsing an expanded code yields a syntax tree and a mapping of text-ranges of the tree to original tokens. 502The end result is that parsing an expanded code yields a syntax tree and a mapping of text-ranges of the tree to original tokens.
503 503
504To deal with precedence in cases like `$expr * 1`, we use special invisible parenthesis, which are explicitelly handled by the parser 504To deal with precedence in cases like `$expr * 1`, we use special invisible parenthesis, which are explicitly handled by the parser
505 505
506### Whitespace & Comments 506### Whitespace & Comments
507 507
diff --git a/docs/user/assists.md b/docs/user/assists.md
index 6c6943622..4ad7ea59d 100644
--- a/docs/user/assists.md
+++ b/docs/user/assists.md
@@ -17,7 +17,7 @@ struct S;
17struct S; 17struct S;
18 18
19impl Debug for S { 19impl Debug for S {
20 20 $0
21} 21}
22``` 22```
23 23
@@ -33,7 +33,7 @@ struct Point {
33} 33}
34 34
35// AFTER 35// AFTER
36#[derive()] 36#[derive($0)]
37struct Point { 37struct Point {
38 x: u32, 38 x: u32,
39 y: u32, 39 y: u32,
@@ -77,7 +77,7 @@ fn foo() {
77} 77}
78 78
79fn bar(arg: &str, baz: Baz) { 79fn bar(arg: &str, baz: Baz) {
80 todo!() 80 ${0:todo!()}
81} 81}
82 82
83``` 83```
@@ -105,16 +105,16 @@ Adds a new inherent impl for a type.
105```rust 105```rust
106// BEFORE 106// BEFORE
107struct Ctx<T: Clone> { 107struct Ctx<T: Clone> {
108 data: T,┃ 108 data: T,┃
109} 109}
110 110
111// AFTER 111// AFTER
112struct Ctx<T: Clone> { 112struct Ctx<T: Clone> {
113 data: T, 113 data: T,
114} 114}
115 115
116impl<T: Clone> Ctx<T> { 116impl<T: Clone> Ctx<T> {
117 117 $0
118} 118}
119``` 119```
120 120
@@ -146,7 +146,7 @@ trait Trait {
146impl Trait for () { 146impl Trait for () {
147 Type X = (); 147 Type X = ();
148 fn foo(&self) {} 148 fn foo(&self) {}
149 fn bar(&self) {} 149 $0fn bar(&self) {}
150 150
151} 151}
152``` 152```
@@ -175,7 +175,9 @@ trait Trait<T> {
175} 175}
176 176
177impl Trait<u32> for () { 177impl Trait<u32> for () {
178 fn foo(&self) -> u32 { todo!() } 178 fn foo(&self) -> u32 {
179 ${0:todo!()}
180 }
179 181
180} 182}
181``` 183```
@@ -196,11 +198,29 @@ struct Ctx<T: Clone> {
196} 198}
197 199
198impl<T: Clone> Ctx<T> { 200impl<T: Clone> Ctx<T> {
199 fn new(data: T) -> Self { Self { data } } 201 fn $0new(data: T) -> Self { Self { data } }
200} 202}
201 203
202``` 204```
203 205
206## `add_turbo_fish`
207
208Adds `::<_>` to a call of a generic method or function.
209
210```rust
211// BEFORE
212fn make<T>() -> T { todo!() }
213fn main() {
214 let x = make┃();
215}
216
217// AFTER
218fn make<T>() -> T { todo!() }
219fn main() {
220 let x = make::<${0:_}>();
221}
222```
223
204## `apply_demorgan` 224## `apply_demorgan`
205 225
206Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). 226Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws).
@@ -239,6 +259,18 @@ fn main() {
239} 259}
240``` 260```
241 261
262## `change_return_type_to_result`
263
264Change the function's return type to Result.
265
266```rust
267// BEFORE
268fn foo() -> i32┃ { 42i32 }
269
270// AFTER
271fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }
272```
273
242## `change_visibility` 274## `change_visibility`
243 275
244Adds or changes existing visibility specifier. 276Adds or changes existing visibility specifier.
@@ -293,12 +325,34 @@ enum Action { Move { distance: u32 }, Stop }
293 325
294fn handle(action: Action) { 326fn handle(action: Action) {
295 match action { 327 match action {
296 Action::Move { distance } => {} 328 $0Action::Move { distance } => {}
297 Action::Stop => {} 329 Action::Stop => {}
298 } 330 }
299} 331}
300``` 332```
301 333
334## `fix_visibility`
335
336Makes inaccessible item public.
337
338```rust
339// BEFORE
340mod m {
341 fn frobnicate() {}
342}
343fn main() {
344 m::frobnicate┃() {}
345}
346
347// AFTER
348mod m {
349 $0pub(crate) fn frobnicate() {}
350}
351fn main() {
352 m::frobnicate() {}
353}
354```
355
302## `flip_binexpr` 356## `flip_binexpr`
303 357
304Flips operands of a binary expression. 358Flips operands of a binary expression.
@@ -372,7 +426,7 @@ fn main() {
372 426
373// AFTER 427// AFTER
374fn main() { 428fn main() {
375 let var_name = (1 + 2); 429 let $0var_name = (1 + 2);
376 var_name * 4; 430 var_name * 4;
377} 431}
378``` 432```
@@ -679,7 +733,7 @@ fn main() {
679 let x: Result<i32, i32> = Result::Ok(92); 733 let x: Result<i32, i32> = Result::Ok(92);
680 let y = match x { 734 let y = match x {
681 Ok(a) => a, 735 Ok(a) => a,
682 _ => unreachable!(), 736 $0_ => unreachable!(),
683 }; 737 };
684} 738}
685``` 739```
@@ -695,3 +749,21 @@ use std::┃collections::HashMap;
695// AFTER 749// AFTER
696use std::{collections::HashMap}; 750use std::{collections::HashMap};
697``` 751```
752
753## `unwrap_block`
754
755This assist removes if...else, for, while and loop control statements to just keep the body.
756
757```rust
758// BEFORE
759fn foo() {
760 if true {┃
761 println!("foo");
762 }
763}
764
765// AFTER
766fn foo() {
767 println!("foo");
768}
769```
diff --git a/docs/user/features.md b/docs/user/features.md
index b9a365fc1..340bce835 100644
--- a/docs/user/features.md
+++ b/docs/user/features.md
@@ -143,9 +143,9 @@ takes arguments, the cursor is positioned inside the parenthesis.
143There are postfix completions, which can be triggered by typing something like 143There are postfix completions, which can be triggered by typing something like
144`foo().if`. The word after `.` determines postfix completion. Possible variants are: 144`foo().if`. The word after `.` determines postfix completion. Possible variants are:
145 145
146- `expr.if` -> `if expr {}` 146- `expr.if` -> `if expr {}` or `if let ... {}` for `Option` or `Result`
147- `expr.match` -> `match expr {}` 147- `expr.match` -> `match expr {}`
148- `expr.while` -> `while expr {}` 148- `expr.while` -> `while expr {}` or `while let ... {}` for `Option` or `Result`
149- `expr.ref` -> `&expr` 149- `expr.ref` -> `&expr`
150- `expr.refm` -> `&mut expr` 150- `expr.refm` -> `&mut expr`
151- `expr.not` -> `!expr` 151- `expr.not` -> `!expr`
@@ -161,6 +161,16 @@ There also snippet completions:
161#### Inside Modules 161#### Inside Modules
162 162
163- `tfn` -> `#[test] fn f(){}` 163- `tfn` -> `#[test] fn f(){}`
164- `tmod` ->
165```rust
166#[cfg(test)]
167mod tests {
168 use super::*;
169
170 #[test]
171 fn test_fn() {}
172}
173```
164 174
165### Code Highlighting 175### Code Highlighting
166 176
diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc
index b1af72ce6..40ed54809 100644
--- a/docs/user/readme.adoc
+++ b/docs/user/readme.adoc
@@ -57,9 +57,13 @@ To disable this notification put the following to `settings.json`
57---- 57----
58==== 58====
59 59
60The server binary is stored in `~/.config/Code/User/globalStorage/matklad.rust-analyzer` (Linux) or in `~/.Library/Application Support/Code/User/globalStorage/matklad.rust-analyzer` (macOS) or in `%APPDATA%\Code\User\globalStorage` (Windows). 60The server binary is stored in:
61 61
62Note that we only support the latest version of VS Code. 62* Linux: `~/.config/Code/User/globalStorage/matklad.rust-analyzer`
63* macOS: `~/Library/Application Support/Code/User/globalStorage/matklad.rust-analyzer`
64* Windows: `%APPDATA%\Code\User\globalStorage\matklad.rust-analyzer`
65
66Note that we only support two most recent versions of VS Code.
63 67
64==== Updates 68==== Updates
65 69
@@ -104,7 +108,7 @@ Here are some useful self-diagnostic commands:
104 108
105* **Rust Analyzer: Show RA Version** shows the version of `rust-analyzer` binary 109* **Rust Analyzer: Show RA Version** shows the version of `rust-analyzer` binary
106* **Rust Analyzer: Status** prints some statistics about the server, like the few latest LSP requests 110* **Rust Analyzer: Status** prints some statistics about the server, like the few latest LSP requests
107* To enable server-side logging, run with `env RUST_LOG=info` and see `Output > Rust Analyzer Language Server` in VS Code's panel. 111* To enable server-side logging, run with `env RA_LOG=info` and see `Output > Rust Analyzer Language Server` in VS Code's panel.
108* To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Server Trace` in the panel. 112* To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Server Trace` in the panel.
109* To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open the `Console` tab of VS Code developer tools. 113* To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open the `Console` tab of VS Code developer tools.
110 114
@@ -135,17 +139,16 @@ If your editor can't find the binary even though the binary is on your `$PATH`,
135 139
136==== Arch Linux 140==== Arch Linux
137 141
138The `rust-analyzer` binary can be installed from AUR (Arch User Repository): 142The `rust-analyzer` binary can be installed from the repos or AUR (Arch User Repository):
139 143
140- https://aur.archlinux.org/packages/rust-analyzer-bin[`rust-analyzer-bin`] (binary from GitHub releases) 144- https://www.archlinux.org/packages/community/x86_64/rust-analyzer/[`rust-analyzer`] (built from latest tagged source)
141- https://aur.archlinux.org/packages/rust-analyzer[`rust-analyzer`] (built from latest tagged source) 145- https://aur.archlinux.org/packages/rust-analyzer-git[`rust-analyzer-git`] (latest Git version)
142- https://aur.archlinux.org/packages/rust-analyzer-git[`rust-analyzer-git`] (latest git version)
143 146
144Install it with AUR helper of your choice, for example: 147Install it with pacman, for example:
145 148
146[source,bash] 149[source,bash]
147---- 150----
148$ yay -S rust-analyzer-bin 151$ pacman -S rust-analyzer
149---- 152----
150 153
151=== Emacs 154=== Emacs
@@ -159,11 +162,11 @@ Emacs support is maintained as part of the https://github.com/emacs-lsp/lsp-mode
1593. Run `lsp` in a Rust buffer. 1623. Run `lsp` in a Rust buffer.
1604. (Optionally) bind commands like `lsp-rust-analyzer-join-lines`, `lsp-extend-selection` and `lsp-rust-analyzer-expand-macro` to keys. 1634. (Optionally) bind commands like `lsp-rust-analyzer-join-lines`, `lsp-extend-selection` and `lsp-rust-analyzer-expand-macro` to keys.
161 164
162=== Vim 165=== Vim/NeoVim
163 166
164Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. 167Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. Not needed if the extension can install/update it on its own, coc-rust-analyzer is one example.
165 168
166The are several LSP client implementations for vim: 169The are several LSP client implementations for vim or neovim:
167 170
168==== coc-rust-analyzer 171==== coc-rust-analyzer
169 172
@@ -183,7 +186,7 @@ The are several LSP client implementations for vim:
183 186
1841. Install LanguageClient-neovim by following the instructions 1871. Install LanguageClient-neovim by following the instructions
185 https://github.com/autozimu/LanguageClient-neovim[here] 188 https://github.com/autozimu/LanguageClient-neovim[here]
186 * The github project wiki has extra tips on configuration 189 * The GitHub project wiki has extra tips on configuration
187 190
1882. Configure by adding this to your vim/neovim config file (replacing the existing Rust-specific line if it exists): 1912. Configure by adding this to your vim/neovim config file (replacing the existing Rust-specific line if it exists):
189+ 192+
@@ -216,17 +219,11 @@ let g:ycm_language_server =
216 219
217==== ALE 220==== ALE
218 221
219To add the LSP server to https://github.com/dense-analysis/ale[ale]: 222To use the LSP server in https://github.com/dense-analysis/ale[ale]:
220 223
221[source,vim] 224[source,vim]
222---- 225----
223call ale#linter#Define('rust', { 226let g:ale_linters = {'rust': ['analyzer']}
224\ 'name': 'rust-analyzer',
225\ 'lsp': 'stdio',
226\ 'executable': 'rust-analyzer',
227\ 'command': '%e',
228\ 'project_root': '.',
229\})
230---- 227----
231 228
232==== nvim-lsp 229==== nvim-lsp
@@ -252,7 +249,7 @@ If it worked, you should see "rust-analyzer, Line X, Column Y" on the left side
252 249
253If you get an error saying `No such file or directory: 'rust-analyzer'`, see the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>> section on installing the language server binary. 250If you get an error saying `No such file or directory: 'rust-analyzer'`, see the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>> section on installing the language server binary.
254 251
255=== Gnome Builder 252=== GNOME Builder
256 253
257Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. 254Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>.
258 255