aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/dev/README.md6
-rw-r--r--docs/dev/debugging.md6
-rw-r--r--docs/dev/lsp-extensions.md172
-rw-r--r--docs/user/assists.md66
-rw-r--r--docs/user/features.md14
-rw-r--r--docs/user/readme.adoc6
6 files changed, 246 insertions, 24 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 1aa392935..59a83f7d7 100644
--- a/docs/dev/debugging.md
+++ b/docs/dev/debugging.md
@@ -22,8 +22,8 @@ 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]`
@@ -47,7 +47,7 @@ To apply changes to an already running debug process, press <kbd>Ctrl+Shift+P</k
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
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
new file mode 100644
index 000000000..158d3c599
--- /dev/null
+++ b/docs/dev/lsp-extensions.md
@@ -0,0 +1,172 @@
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## Snippet `TextEdit`
9
10**Issue:** https://github.com/microsoft/language-server-protocol/issues/724
11
12**Client Capability:** `{ "snippetTextEdit": boolean }`
13
14If this capability is set, `WorkspaceEdit`s returned from `codeAction` requests might contain `SnippetTextEdit`s instead of usual `TextEdit`s:
15
16```typescript
17interface SnippetTextEdit extends TextEdit {
18 insertTextFormat?: InsertTextFormat;
19}
20```
21
22```typescript
23export interface TextDocumentEdit {
24 textDocument: VersionedTextDocumentIdentifier;
25 edits: (TextEdit | SnippetTextEdit)[];
26}
27```
28
29When applying such code action, the editor should insert snippet, with tab stops and placeholder.
30At the moment, rust-analyzer guarantees that only a single edit will have `InsertTextFormat.Snippet`.
31
32### Example
33
34"Add `derive`" code action transforms `struct S;` into `#[derive($0)] struct S;`
35
36### Unresolved Questions
37
38* Where exactly are `SnippetTextEdit`s allowed (only in code actions at the moment)?
39* Can snippets span multiple files (so far, no)?
40
41## Join Lines
42
43**Issue:** https://github.com/microsoft/language-server-protocol/issues/992
44
45**Server Capability:** `{ "joinLines": boolean }`
46
47This request is send from client to server to handle "Join Lines" editor action.
48
49**Method:** `experimental/JoinLines`
50
51**Request:**
52
53```typescript
54interface JoinLinesParams {
55 textDocument: TextDocumentIdentifier,
56 /// Currently active selections/cursor offsets.
57 /// This is an array to support multiple cursors.
58 ranges: Range[],
59}
60```
61
62**Response:**
63
64```typescript
65TextEdit[]
66```
67
68### Example
69
70```rust
71fn main() {
72 /*cursor here*/let x = {
73 92
74 };
75}
76```
77
78`experimental/joinLines` yields (curly braces are automagiacally removed)
79
80```rust
81fn main() {
82 let x = 92;
83}
84```
85
86### Unresolved Question
87
88* What is the position of the cursor after `joinLines`?
89 Currently this is left to editor's discretion, but it might be useful to specify on the server via snippets.
90 However, it then becomes unclear how it works with multi cursor.
91
92## Structural Search Replace (SSR)
93
94**Server Capability:** `{ "ssr": boolean }`
95
96This request is send from client to server to handle structural search replace -- automated syntax tree based transformation of the source.
97
98**Method:** `experimental/ssr`
99
100**Request:**
101
102```typescript
103interface SsrParams {
104 /// Search query.
105 /// The specific syntax is specified outside of the protocol.
106 query: string,
107 /// If true, only check the syntax of the query and don't compute the actual edit.
108 parseOnly: bool,
109}
110```
111
112**Response:**
113
114```typescript
115WorkspaceEdit
116```
117
118### Example
119
120SSR with query `foo($a:expr, $b:expr) ==>> ($a).foo($b)` will transform, eg `foo(y + 5, z)` into `(y + 5).foo(z)`.
121
122### Unresolved Question
123
124* Probably needs search without replace mode
125* Needs a way to limit the scope to certain files.
126
127## `CodeAction` Groups
128
129**Issue:** https://github.com/microsoft/language-server-protocol/issues/994
130
131**Client Capability:** `{ "codeActionGroup": boolean }`
132
133If this capability is set, `CodeAction` returned from the server contain an additional field, `group`:
134
135```typescript
136interface CodeAction {
137 title: string;
138 group?: string;
139 ...
140}
141```
142
143All code-actions with the same `group` should be grouped under single (extendable) entry in lightbulb menu.
144The set of actions `[ { title: "foo" }, { group: "frobnicate", title: "bar" }, { group: "frobnicate", title: "baz" }]` should be rendered as
145
146```
147💡
148 +-------------+
149 | foo |
150 +-------------+-----+
151 | frobnicate >| bar |
152 +-------------+-----+
153 | baz |
154 +-----+
155```
156
157Alternatively, selecting `frobnicate` could present a user with an additional menu to choose between `bar` and `baz`.
158
159### Example
160
161```rust
162fn main() {
163 let x: Entry/*cursor here*/ = todo!();
164}
165```
166
167Invoking code action at this position will yield two code actions for importing `Entry` from either `collections::HashMap` or `collection::BTreeMap`, grouped under a single "import" group.
168
169### Unresolved Questions
170
171* Is a fixed two-level structure enough?
172* Should we devise a general way to encode custom interaction protocols for GUI refactorings?
diff --git a/docs/user/assists.md b/docs/user/assists.md
index 692fd4f52..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```
@@ -176,7 +176,7 @@ trait Trait<T> {
176 176
177impl Trait<u32> for () { 177impl Trait<u32> for () {
178 fn foo(&self) -> u32 { 178 fn foo(&self) -> u32 {
179 todo!() 179 ${0:todo!()}
180 } 180 }
181 181
182} 182}
@@ -198,11 +198,29 @@ struct Ctx<T: Clone> {
198} 198}
199 199
200impl<T: Clone> Ctx<T> { 200impl<T: Clone> Ctx<T> {
201 fn new(data: T) -> Self { Self { data } } 201 fn $0new(data: T) -> Self { Self { data } }
202} 202}
203 203
204``` 204```
205 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
206## `apply_demorgan` 224## `apply_demorgan`
207 225
208Apply [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).
@@ -250,7 +268,7 @@ Change the function's return type to Result.
250fn foo() -> i32┃ { 42i32 } 268fn foo() -> i32┃ { 42i32 }
251 269
252// AFTER 270// AFTER
253fn foo() -> Result<i32, > { Ok(42i32) } 271fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }
254``` 272```
255 273
256## `change_visibility` 274## `change_visibility`
@@ -307,12 +325,34 @@ enum Action { Move { distance: u32 }, Stop }
307 325
308fn handle(action: Action) { 326fn handle(action: Action) {
309 match action { 327 match action {
310 Action::Move { distance } => {} 328 $0Action::Move { distance } => {}
311 Action::Stop => {} 329 Action::Stop => {}
312 } 330 }
313} 331}
314``` 332```
315 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
316## `flip_binexpr` 356## `flip_binexpr`
317 357
318Flips operands of a binary expression. 358Flips operands of a binary expression.
@@ -386,7 +426,7 @@ fn main() {
386 426
387// AFTER 427// AFTER
388fn main() { 428fn main() {
389 let var_name = (1 + 2); 429 let $0var_name = (1 + 2);
390 var_name * 4; 430 var_name * 4;
391} 431}
392``` 432```
@@ -693,7 +733,7 @@ fn main() {
693 let x: Result<i32, i32> = Result::Ok(92); 733 let x: Result<i32, i32> = Result::Ok(92);
694 let y = match x { 734 let y = match x {
695 Ok(a) => a, 735 Ok(a) => a,
696 _ => unreachable!(), 736 $0_ => unreachable!(),
697 }; 737 };
698} 738}
699``` 739```
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 f6ce0accf..40ed54809 100644
--- a/docs/user/readme.adoc
+++ b/docs/user/readme.adoc
@@ -63,7 +63,7 @@ The server binary is stored in:
63* macOS: `~/Library/Application Support/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` 64* Windows: `%APPDATA%\Code\User\globalStorage\matklad.rust-analyzer`
65 65
66Note that we only support the latest version of VS Code. 66Note that we only support two most recent versions of VS Code.
67 67
68==== Updates 68==== Updates
69 69
@@ -108,7 +108,7 @@ Here are some useful self-diagnostic commands:
108 108
109* **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
110* **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
111* 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.
112* 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.
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. 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.
114 114
@@ -249,7 +249,7 @@ If it worked, you should see "rust-analyzer, Line X, Column Y" on the left side
249 249
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. 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.
251 251
252=== Gnome Builder 252=== GNOME Builder
253 253
254Prerequisites: 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>>.
255 255