aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-18 09:26:24 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-18 09:26:24 +0000
commit16c7ebbb27dc81b4640b5694f36b381cae706c8d (patch)
treea6f9a860d59e24b0c9141ad8d73e980cfb9ed748 /crates/ra_lsp_server
parent564ab84b787cca0f5994451eb2ce9e1ba8c9d974 (diff)
parenta92db7c84829becdf95e0a5ef6e27cdf833518b8 (diff)
Merge #854
854: more compact edits in insta r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/conv.rs32
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 };