diff options
author | Aleksey Kladov <[email protected]> | 2019-02-18 09:05:16 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-18 09:24:20 +0000 |
commit | 92aa0f9c871a9308ea3db1b1c4b7e42d88348e30 (patch) | |
tree | ce785e530a547e3aede708b7725b4a95e666f45f /crates/ra_lsp_server/src | |
parent | 79f35cc6992d18e97b0bb9e309a2dc37f6f286e8 (diff) |
Don't use additional_text_edits API internally
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index c3192a1e5..f0f67b663 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -79,11 +79,31 @@ impl ConvWith for CompletionItem { | |||
79 | type Ctx = LineIndex; | 79 | type Ctx = LineIndex; |
80 | type Output = ::lsp_types::CompletionItem; | 80 | type Output = ::lsp_types::CompletionItem; |
81 | 81 | ||
82 | fn conv_with(mut self, ctx: &LineIndex) -> ::lsp_types::CompletionItem { | 82 | fn conv_with(self, ctx: &LineIndex) -> ::lsp_types::CompletionItem { |
83 | let atom_text_edit = AtomTextEdit::replace(self.source_range(), self.insert_text()); | 83 | let mut additional_text_edits = Vec::new(); |
84 | let text_edit = (&atom_text_edit).conv_with(ctx); | 84 | let mut text_edit = None; |
85 | let additional_text_edits = | 85 | // LSP does not allow arbitrary edits in completion, so we have to do a |
86 | if let Some(edit) = self.take_text_edit() { Some(edit.conv_with(ctx)) } else { None }; | 86 | // non-trivial mapping here. |
87 | for atom_edit in self.text_edit().as_atoms() { | ||
88 | if self.source_range().is_subrange(&atom_edit.delete) { | ||
89 | text_edit = Some(if atom_edit.delete == self.source_range() { | ||
90 | atom_edit.conv_with(ctx) | ||
91 | } else { | ||
92 | assert!(self.source_range().end() == atom_edit.delete.end()); | ||
93 | let range1 = | ||
94 | TextRange::from_to(atom_edit.delete.start(), self.source_range().start()); | ||
95 | let range2 = self.source_range(); | ||
96 | let edit1 = AtomTextEdit::replace(range1, String::new()); | ||
97 | let edit2 = AtomTextEdit::replace(range2, atom_edit.insert.clone()); | ||
98 | additional_text_edits.push(edit1.conv_with(ctx)); | ||
99 | edit2.conv_with(ctx) | ||
100 | }) | ||
101 | } else { | ||
102 | assert!(self.source_range().intersection(&atom_edit.delete).is_none()); | ||
103 | additional_text_edits.push(atom_edit.conv_with(ctx)); | ||
104 | } | ||
105 | } | ||
106 | let text_edit = text_edit.unwrap(); | ||
87 | 107 | ||
88 | let mut res = lsp_types::CompletionItem { | 108 | let mut res = lsp_types::CompletionItem { |
89 | label: self.label().to_string(), | 109 | label: self.label().to_string(), |
@@ -91,7 +111,7 @@ impl ConvWith for CompletionItem { | |||
91 | filter_text: Some(self.lookup().to_string()), | 111 | filter_text: Some(self.lookup().to_string()), |
92 | kind: self.kind().map(|it| it.conv()), | 112 | kind: self.kind().map(|it| it.conv()), |
93 | text_edit: Some(text_edit), | 113 | text_edit: Some(text_edit), |
94 | additional_text_edits, | 114 | additional_text_edits: Some(additional_text_edits), |
95 | documentation: self.documentation().map(|it| it.conv()), | 115 | documentation: self.documentation().map(|it| it.conv()), |
96 | ..Default::default() | 116 | ..Default::default() |
97 | }; | 117 | }; |