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`.
10 **Issue:** https://github.com/microsoft/language-server-protocol/issues/724
12 **Client Capability:** `{ "snippetTextEdit": boolean }`
14 If this capability is set, `WorkspaceEdit`s returned from `codeAction` requests might contain `SnippetTextEdit`s instead of usual `TextEdit`s:
17 interface SnippetTextEdit extends TextEdit {
18 insertTextFormat?: InsertTextFormat;
23 export interface TextDocumentEdit {
24 textDocument: VersionedTextDocumentIdentifier;
25 edits: (TextEdit | SnippetTextEdit)[];
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`.
34 "Add `derive`" code action transforms `struct S;` into `#[derive($0)] struct S;`
36 ### Unresolved Questions
38 * Where exactly are `SnippetTextEdit`s allowed (only in code actions at the moment)?
39 * Can snippets span multiple files (so far, no)?
43 **Issue:** https://github.com/microsoft/language-server-protocol/issues/992
45 **Server Capability:** `{ "joinLines": boolean }`
47 This request is send from client to server to handle "Join Lines" editor action.
49 **Method:** `experimental/JoinLines`
54 interface JoinLinesParams {
55 textDocument: TextDocumentIdentifier,
56 /// Currently active selections/cursor offsets.
57 /// This is an array to support multiple cursors.
72 /*cursor here*/let x = {
78 `experimental/joinLines` yields (curly braces are automagiacally removed)
86 ### Unresolved Question
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.
92 ## Structural Search Replace (SSR)
94 **Server Capability:** `{ "ssr": boolean }`
96 This request is send from client to server to handle structural search replace -- automated syntax tree based transformation of the source.
98 **Method:** `experimental/ssr`
103 interface SsrParams {
105 /// The specific syntax is specified outside of the protocol.
107 /// If true, only check the syntax of the query and don't compute the actual edit.
120 SSR with query `foo($a:expr, $b:expr) ==>> ($a).foo($b)` will transform, eg `foo(y + 5, z)` into `(y + 5).foo(z)`.
122 ### Unresolved Question
124 * Probably needs search without replace mode
125 * Needs a way to limit the scope to certain files.
127 ## `CodeAction` Groups
129 **Issue:** https://github.com/microsoft/language-server-protocol/issues/994
131 **Client Capability:** `{ "codeActionGroup": boolean }`
133 If this capability is set, `CodeAction` returned from the server contain an additional field, `group`:
136 interface CodeAction {
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
150 +-------------+-----+
151 | frobnicate >| bar |
152 +-------------+-----+
157 Alternatively, selecting `frobnicate` could present a user with an additional menu to choose between `bar` and `baz`.
163 let x: Entry/*cursor here*/ = todo!();
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.
169 ### Unresolved Questions
171 * Is a fixed two-level structure enough?
172 * Should we devise a general way to encode custom interaction protocols for GUI refactorings?