diff options
Diffstat (limited to 'docs/dev')
-rw-r--r-- | docs/dev/README.md | 6 | ||||
-rw-r--r-- | docs/dev/debugging.md | 6 | ||||
-rw-r--r-- | docs/dev/lsp-extensions.md | 172 |
3 files changed, 178 insertions, 6 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 | |||
74 | test). | 74 | test). |
75 | 75 | ||
76 | However, launching a VS Code instance with locally build language server is | 76 | However, launching a VS Code instance with locally build language server is |
77 | possible. There's **"Run Extension (Dev Server)"** launch configuration for this. | 77 | possible. There's **"Run Extension (Debug Build)"** launch configuration for this. |
78 | 78 | ||
79 | In general, I use one of the following workflows for fixing bugs and | 79 | In general, I use one of the following workflows for fixing bugs and |
80 | implementing features. | 80 | implementing features. |
@@ -86,7 +86,7 @@ then just do printf-driven development/debugging. As a sanity check after I'm | |||
86 | done, I use `cargo xtask install --server` and **Reload Window** action in VS | 86 | done, I use `cargo xtask install --server` and **Reload Window** action in VS |
87 | Code to sanity check that the thing works as I expect. | 87 | Code to sanity check that the thing works as I expect. |
88 | 88 | ||
89 | If the problem concerns only the VS Code extension, I use **Run Extension** | 89 | If the problem concerns only the VS Code extension, I use **Run Installed Extension** |
90 | launch configuration from `launch.json`. Notably, this uses the usual | 90 | launch 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 |
92 | in `setting.json` file: | 92 | in `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 | ||
28 | TypeScript debugging is configured to watch your source edits and recompile. | 28 | TypeScript debugging is configured to watch your source edits and recompile. |
29 | To apply changes to an already running debug process, press <kbd>Ctrl+Shift+P</kbd> and run the following command in your `[Extension Development Host]` | 29 | To 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 | |||
3 | This document describes LSP extensions used by rust-analyzer. | ||
4 | It's a best effort document, when in doubt, consult the source (and send a PR with clarification ;-) ). | ||
5 | We aim to upstream all non Rust-specific extensions to the protocol, but this is not a top priority. | ||
6 | All 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 | |||
14 | If this capability is set, `WorkspaceEdit`s returned from `codeAction` requests might contain `SnippetTextEdit`s instead of usual `TextEdit`s: | ||
15 | |||
16 | ```typescript | ||
17 | interface SnippetTextEdit extends TextEdit { | ||
18 | insertTextFormat?: InsertTextFormat; | ||
19 | } | ||
20 | ``` | ||
21 | |||
22 | ```typescript | ||
23 | export interface TextDocumentEdit { | ||
24 | textDocument: VersionedTextDocumentIdentifier; | ||
25 | edits: (TextEdit | SnippetTextEdit)[]; | ||
26 | } | ||
27 | ``` | ||
28 | |||
29 | When applying such code action, the editor should insert snippet, with tab stops and placeholder. | ||
30 | At 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 | |||
47 | This request is send from client to server to handle "Join Lines" editor action. | ||
48 | |||
49 | **Method:** `experimental/JoinLines` | ||
50 | |||
51 | **Request:** | ||
52 | |||
53 | ```typescript | ||
54 | interface 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 | ||
65 | TextEdit[] | ||
66 | ``` | ||
67 | |||
68 | ### Example | ||
69 | |||
70 | ```rust | ||
71 | fn main() { | ||
72 | /*cursor here*/let x = { | ||
73 | 92 | ||
74 | }; | ||
75 | } | ||
76 | ``` | ||
77 | |||
78 | `experimental/joinLines` yields (curly braces are automagiacally removed) | ||
79 | |||
80 | ```rust | ||
81 | fn 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 | |||
96 | This 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 | ||
103 | interface 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 | ||
115 | WorkspaceEdit | ||
116 | ``` | ||
117 | |||
118 | ### Example | ||
119 | |||
120 | SSR 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 | |||
133 | If this capability is set, `CodeAction` returned from the server contain an additional field, `group`: | ||
134 | |||
135 | ```typescript | ||
136 | interface CodeAction { | ||
137 | title: string; | ||
138 | group?: string; | ||
139 | ... | ||
140 | } | ||
141 | ``` | ||
142 | |||
143 | All code-actions with the same `group` should be grouped under single (extendable) entry in lightbulb menu. | ||
144 | The 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 | |||
157 | Alternatively, selecting `frobnicate` could present a user with an additional menu to choose between `bar` and `baz`. | ||
158 | |||
159 | ### Example | ||
160 | |||
161 | ```rust | ||
162 | fn main() { | ||
163 | let x: Entry/*cursor here*/ = todo!(); | ||
164 | } | ||
165 | ``` | ||
166 | |||
167 | Invoking 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? | ||