diff options
author | Galilée 'Bill' Enguehard <[email protected]> | 2020-05-21 22:27:38 +0100 |
---|---|---|
committer | Galilée 'Bill' Enguehard <[email protected]> | 2020-05-21 22:27:38 +0100 |
commit | 7fece3bdd2450c0807f7dd742239cae95f0cc65e (patch) | |
tree | 866c4db826c959e79c63a6727bdb9f2c61e6fc4f /docs/dev/lsp-extensions.md | |
parent | db926218b2082077750291f8426ddd28b284cd08 (diff) | |
parent | 59732df8d40dfadc6dcf5951265416576399712a (diff) |
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer into modname_spacing
Diffstat (limited to 'docs/dev/lsp-extensions.md')
-rw-r--r-- | docs/dev/lsp-extensions.md | 86 |
1 files changed, 86 insertions, 0 deletions
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 | |||
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 | ## `SnippetTextEdit` | ||
9 | |||
10 | **Client Capability:** `{ "snippetTextEdit": boolean }` | ||
11 | |||
12 | If this capability is set, `WorkspaceEdit`s returned from `codeAction` requests might contain `SnippetTextEdit`s instead of usual `TextEdit`s: | ||
13 | |||
14 | ```typescript | ||
15 | interface SnippetTextEdit extends TextEdit { | ||
16 | insertTextFormat?: InsertTextFormat; | ||
17 | } | ||
18 | ``` | ||
19 | |||
20 | ```typescript | ||
21 | export interface TextDocumentEdit { | ||
22 | textDocument: VersionedTextDocumentIdentifier; | ||
23 | edits: (TextEdit | SnippetTextEdit)[]; | ||
24 | } | ||
25 | ``` | ||
26 | |||
27 | When applying such code action, the editor should insert snippet, with tab stops and placeholder. | ||
28 | At 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 | |||
43 | This request is send from client to server to handle "Join Lines" editor action. | ||
44 | |||
45 | **Method:** `experimental/JoinLines` | ||
46 | |||
47 | **Request:** | ||
48 | |||
49 | ```typescript | ||
50 | interface 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 | ||
61 | TextEdit[] | ||
62 | ``` | ||
63 | |||
64 | ### Example | ||
65 | |||
66 | ```rust | ||
67 | fn main() { | ||
68 | /*cursor here*/let x = { | ||
69 | 92 | ||
70 | }; | ||
71 | } | ||
72 | ``` | ||
73 | |||
74 | `experimental/joinLines` yields (curly braces are automagiacally removed) | ||
75 | |||
76 | ```rust | ||
77 | fn 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. | ||