aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/conv.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 76215a975..54a977b7a 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -13,6 +13,7 @@ use ra_syntax::{SyntaxKind, TextRange, TextUnit};
13use ra_text_edit::{AtomTextEdit, TextEdit}; 13use ra_text_edit::{AtomTextEdit, TextEdit};
14 14
15use crate::{req, server_world::ServerWorld, Result}; 15use crate::{req, server_world::ServerWorld, Result};
16use ra_text_edit::TextEditBuilder;
16 17
17pub trait Conv { 18pub trait Conv {
18 type Output; 19 type Output;
@@ -78,19 +79,24 @@ impl ConvWith for CompletionItem {
78 type Ctx = LineIndex; 79 type Ctx = LineIndex;
79 type Output = ::lsp_types::CompletionItem; 80 type Output = ::lsp_types::CompletionItem;
80 81
81 fn conv_with(mut self, ctx: &LineIndex) -> ::lsp_types::CompletionItem { 82 fn conv_with(self, ctx: &LineIndex) -> ::lsp_types::CompletionItem {
82 let text_edit = self.text_edit().map(|t| t.conv_with(ctx)); 83 let atom_text_edit = AtomTextEdit::replace(self.replace_range(), self.insert_text());
83 let additonal_text_edit = self 84 let text_edit = (&atom_text_edit).conv_with(ctx);
84 .take_additional_text_edits() 85 let additional_text_edits = if let Some(delete_range) = self.delete_range() {
85 .map(|it| it.conv_with(ctx)); 86 let mut builder = TextEditBuilder::default();
87 builder.delete(delete_range);
88 Some(builder.finish().conv_with(ctx))
89 } else {
90 None
91 };
86 92
87 let mut res = lsp_types::CompletionItem { 93 let mut res = lsp_types::CompletionItem {
88 label: self.label().to_string(), 94 label: self.label().to_string(),
89 detail: self.detail().map(|it| it.to_string()), 95 detail: self.detail().map(|it| it.to_string()),
90 filter_text: Some(self.lookup().to_string()), 96 filter_text: Some(self.lookup().to_string()),
91 kind: self.kind().map(|it| it.conv()), 97 kind: self.kind().map(|it| it.conv()),
92 text_edit, 98 text_edit: Some(text_edit),
93 additional_text_edits: additonal_text_edit, 99 additional_text_edits,
94 ..Default::default() 100 ..Default::default()
95 }; 101 };
96 res.insert_text_format = Some(match self.insert_text_format() { 102 res.insert_text_format = Some(match self.insert_text_format() {