aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/completion/completion_item.rs4
-rw-r--r--crates/ra_ide/src/references/rename.rs4
-rw-r--r--crates/ra_ide/src/test_utils.rs4
-rw-r--r--crates/ra_text_edit/src/lib.rs16
-rw-r--r--crates/rust-analyzer/src/to_proto.rs11
5 files changed, 21 insertions, 18 deletions
diff --git a/crates/ra_ide/src/completion/completion_item.rs b/crates/ra_ide/src/completion/completion_item.rs
index 6021f7279..cfb7c1e38 100644
--- a/crates/ra_ide/src/completion/completion_item.rs
+++ b/crates/ra_ide/src/completion/completion_item.rs
@@ -63,8 +63,8 @@ impl fmt::Debug for CompletionItem {
63 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 63 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
64 let mut s = f.debug_struct("CompletionItem"); 64 let mut s = f.debug_struct("CompletionItem");
65 s.field("label", &self.label()).field("source_range", &self.source_range()); 65 s.field("label", &self.label()).field("source_range", &self.source_range());
66 if self.text_edit().as_indels().len() == 1 { 66 if self.text_edit().len() == 1 {
67 let atom = &self.text_edit().as_indels()[0]; 67 let atom = &self.text_edit().iter().next().unwrap();
68 s.field("delete", &atom.delete); 68 s.field("delete", &atom.delete);
69 s.field("insert", &atom.insert); 69 s.field("insert", &atom.insert);
70 } else { 70 } else {
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index 55c3319cb..fd2163dad 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -983,8 +983,8 @@ mod tests {
983 if let Some(change) = source_change { 983 if let Some(change) = source_change {
984 for edit in change.info.source_file_edits { 984 for edit in change.info.source_file_edits {
985 file_id = Some(edit.file_id); 985 file_id = Some(edit.file_id);
986 for indel in edit.edit.as_indels() { 986 for indel in edit.edit.into_iter() {
987 text_edit_builder.replace(indel.delete, indel.insert.clone()); 987 text_edit_builder.replace(indel.delete, indel.insert);
988 } 988 }
989 } 989 }
990 } 990 }
diff --git a/crates/ra_ide/src/test_utils.rs b/crates/ra_ide/src/test_utils.rs
index 48c8fd1f4..b335582a3 100644
--- a/crates/ra_ide/src/test_utils.rs
+++ b/crates/ra_ide/src/test_utils.rs
@@ -3,9 +3,9 @@
3use ra_syntax::{SourceFile, TextSize}; 3use ra_syntax::{SourceFile, TextSize};
4use ra_text_edit::TextEdit; 4use ra_text_edit::TextEdit;
5 5
6pub use test_utils::*; 6pub(crate) use test_utils::*;
7 7
8pub fn check_action<F: Fn(&SourceFile, TextSize) -> Option<TextEdit>>( 8pub(crate) fn check_action<F: Fn(&SourceFile, TextSize) -> Option<TextEdit>>(
9 before: &str, 9 before: &str,
10 after: &str, 10 after: &str,
11 f: F, 11 f: F,
diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs
index c4f945101..199fd1096 100644
--- a/crates/ra_text_edit/src/lib.rs
+++ b/crates/ra_text_edit/src/lib.rs
@@ -3,6 +3,7 @@
3//! `rust-analyzer` never mutates text itself and only sends diffs to clients, 3//! `rust-analyzer` never mutates text itself and only sends diffs to clients,
4//! so `TextEdit` is the ultimate representation of the work done by 4//! so `TextEdit` is the ultimate representation of the work done by
5//! rust-analyzer. 5//! rust-analyzer.
6use std::{slice, vec};
6 7
7pub use text_size::{TextRange, TextSize}; 8pub use text_size::{TextRange, TextSize};
8 9
@@ -71,17 +72,24 @@ impl TextEdit {
71 TextEdit { indels } 72 TextEdit { indels }
72 } 73 }
73 74
75 pub fn len(&self) -> usize {
76 self.indels.len()
77 }
78
74 pub fn is_empty(&self) -> bool { 79 pub fn is_empty(&self) -> bool {
75 self.indels.is_empty() 80 self.indels.is_empty()
76 } 81 }
77 82
78 // FXME: impl IntoIter instead 83 pub fn iter(&self) -> slice::Iter<'_, Indel> {
79 pub fn as_indels(&self) -> &[Indel] { 84 self.indels.iter()
80 &self.indels 85 }
86
87 pub fn into_iter(self) -> vec::IntoIter<Indel> {
88 self.indels.into_iter()
81 } 89 }
82 90
83 pub fn apply(&self, text: &mut String) { 91 pub fn apply(&self, text: &mut String) {
84 match self.indels.len() { 92 match self.len() {
85 0 => return, 93 0 => return,
86 1 => { 94 1 => {
87 self.indels[0].apply(text); 95 self.indels[0].apply(text);
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 9a8e9e174..617197963 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -133,11 +133,7 @@ pub(crate) fn text_edit_vec(
133 line_endings: LineEndings, 133 line_endings: LineEndings,
134 text_edit: TextEdit, 134 text_edit: TextEdit,
135) -> Vec<lsp_types::TextEdit> { 135) -> Vec<lsp_types::TextEdit> {
136 text_edit 136 text_edit.into_iter().map(|indel| self::text_edit(line_index, line_endings, indel)).collect()
137 .as_indels()
138 .iter()
139 .map(|it| self::text_edit(line_index, line_endings, it.clone()))
140 .collect()
141} 137}
142 138
143pub(crate) fn completion_item( 139pub(crate) fn completion_item(
@@ -150,7 +146,7 @@ pub(crate) fn completion_item(
150 // LSP does not allow arbitrary edits in completion, so we have to do a 146 // LSP does not allow arbitrary edits in completion, so we have to do a
151 // non-trivial mapping here. 147 // non-trivial mapping here.
152 let source_range = completion_item.source_range(); 148 let source_range = completion_item.source_range();
153 for indel in completion_item.text_edit().as_indels() { 149 for indel in completion_item.text_edit().iter() {
154 if indel.delete.contains_range(source_range) { 150 if indel.delete.contains_range(source_range) {
155 text_edit = Some(if indel.delete == source_range { 151 text_edit = Some(if indel.delete == source_range {
156 self::text_edit(line_index, line_endings, indel.clone()) 152 self::text_edit(line_index, line_endings, indel.clone())
@@ -459,8 +455,7 @@ pub(crate) fn snippet_text_document_edit(
459 let line_endings = world.file_line_endings(source_file_edit.file_id); 455 let line_endings = world.file_line_endings(source_file_edit.file_id);
460 let edits = source_file_edit 456 let edits = source_file_edit
461 .edit 457 .edit
462 .as_indels() 458 .into_iter()
463 .iter()
464 .map(|it| snippet_text_edit(&line_index, line_endings, is_snippet, it.clone())) 459 .map(|it| snippet_text_edit(&line_index, line_endings, is_snippet, it.clone()))
465 .collect(); 460 .collect();
466 Ok(lsp_ext::SnippetTextDocumentEdit { text_document, edits }) 461 Ok(lsp_ext::SnippetTextDocumentEdit { text_document, edits })