aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/conv.rs13
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs7
2 files changed, 12 insertions, 8 deletions
diff --git a/crates/rust-analyzer/src/conv.rs b/crates/rust-analyzer/src/conv.rs
index b2b1cb625..79bc1fa41 100644
--- a/crates/rust-analyzer/src/conv.rs
+++ b/crates/rust-analyzer/src/conv.rs
@@ -112,10 +112,10 @@ impl Conv for Severity {
112 } 112 }
113} 113}
114 114
115impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem { 115impl ConvWith<(&LineIndex, LineEndings, usize)> for CompletionItem {
116 type Output = ::lsp_types::CompletionItem; 116 type Output = ::lsp_types::CompletionItem;
117 117
118 fn conv_with(self, ctx: (&LineIndex, LineEndings)) -> ::lsp_types::CompletionItem { 118 fn conv_with(self, ctx: (&LineIndex, LineEndings, usize)) -> ::lsp_types::CompletionItem {
119 let mut additional_text_edits = Vec::new(); 119 let mut additional_text_edits = Vec::new();
120 let mut text_edit = None; 120 let mut text_edit = None;
121 // LSP does not allow arbitrary edits in completion, so we have to do a 121 // LSP does not allow arbitrary edits in completion, so we have to do a
@@ -123,7 +123,7 @@ impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem {
123 for atom_edit in self.text_edit().as_atoms() { 123 for atom_edit in self.text_edit().as_atoms() {
124 if self.source_range().is_subrange(&atom_edit.delete) { 124 if self.source_range().is_subrange(&atom_edit.delete) {
125 text_edit = Some(if atom_edit.delete == self.source_range() { 125 text_edit = Some(if atom_edit.delete == self.source_range() {
126 atom_edit.conv_with(ctx) 126 atom_edit.conv_with((ctx.0, ctx.1))
127 } else { 127 } else {
128 assert!(self.source_range().end() == atom_edit.delete.end()); 128 assert!(self.source_range().end() == atom_edit.delete.end());
129 let range1 = 129 let range1 =
@@ -131,12 +131,12 @@ impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem {
131 let range2 = self.source_range(); 131 let range2 = self.source_range();
132 let edit1 = AtomTextEdit::replace(range1, String::new()); 132 let edit1 = AtomTextEdit::replace(range1, String::new());
133 let edit2 = AtomTextEdit::replace(range2, atom_edit.insert.clone()); 133 let edit2 = AtomTextEdit::replace(range2, atom_edit.insert.clone());
134 additional_text_edits.push(edit1.conv_with(ctx)); 134 additional_text_edits.push(edit1.conv_with((ctx.0, ctx.1)));
135 edit2.conv_with(ctx) 135 edit2.conv_with((ctx.0, ctx.1))
136 }) 136 })
137 } else { 137 } else {
138 assert!(self.source_range().intersection(&atom_edit.delete).is_none()); 138 assert!(self.source_range().intersection(&atom_edit.delete).is_none());
139 additional_text_edits.push(atom_edit.conv_with(ctx)); 139 additional_text_edits.push(atom_edit.conv_with((ctx.0, ctx.1)));
140 } 140 }
141 } 141 }
142 let text_edit = text_edit.unwrap(); 142 let text_edit = text_edit.unwrap();
@@ -147,6 +147,7 @@ impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem {
147 filter_text: Some(self.lookup().to_string()), 147 filter_text: Some(self.lookup().to_string()),
148 kind: self.kind().map(|it| it.conv()), 148 kind: self.kind().map(|it| it.conv()),
149 text_edit: Some(text_edit), 149 text_edit: Some(text_edit),
150 sort_text: Some(format!("{:02}", ctx.2)),
150 additional_text_edits: Some(additional_text_edits), 151 additional_text_edits: Some(additional_text_edits),
151 documentation: self.documentation().map(|it| it.conv()), 152 documentation: self.documentation().map(|it| it.conv()),
152 deprecated: Some(self.deprecated()), 153 deprecated: Some(self.deprecated()),
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index b207f0764..d18d2de34 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -423,8 +423,11 @@ pub fn handle_completion(
423 }; 423 };
424 let line_index = world.analysis().file_line_index(position.file_id)?; 424 let line_index = world.analysis().file_line_index(position.file_id)?;
425 let line_endings = world.file_line_endings(position.file_id); 425 let line_endings = world.file_line_endings(position.file_id);
426 let items: Vec<CompletionItem> = 426 let items: Vec<CompletionItem> = items
427 items.into_iter().map(|item| item.conv_with((&line_index, line_endings))).collect(); 427 .into_iter()
428 .enumerate()
429 .map(|(idx, item)| item.conv_with((&line_index, line_endings, idx)))
430 .collect();
428 431
429 Ok(Some(items.into())) 432 Ok(Some(items.into()))
430} 433}