diff options
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_postfix.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide_api/src/diagnostics.rs | 9 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/rename.rs | 24 | ||||
-rw-r--r-- | crates/ra_ide_api/src/typing.rs | 7 |
5 files changed, 21 insertions, 37 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_postfix.rs b/crates/ra_ide_api/src/completion/complete_postfix.rs index 555cecb73..60ed3518b 100644 --- a/crates/ra_ide_api/src/completion/complete_postfix.rs +++ b/crates/ra_ide_api/src/completion/complete_postfix.rs | |||
@@ -9,16 +9,14 @@ use crate::{ | |||
9 | }; | 9 | }; |
10 | use hir::{Ty, TypeCtor}; | 10 | use hir::{Ty, TypeCtor}; |
11 | use ra_syntax::{ast::AstNode, TextRange, TextUnit}; | 11 | use ra_syntax::{ast::AstNode, TextRange, TextUnit}; |
12 | use ra_text_edit::TextEditBuilder; | 12 | use ra_text_edit::TextEdit; |
13 | 13 | ||
14 | fn postfix_snippet(ctx: &CompletionContext, label: &str, detail: &str, snippet: &str) -> Builder { | 14 | fn postfix_snippet(ctx: &CompletionContext, label: &str, detail: &str, snippet: &str) -> Builder { |
15 | let edit = { | 15 | let edit = { |
16 | let receiver_range = | 16 | let receiver_range = |
17 | ctx.dot_receiver.as_ref().expect("no receiver available").syntax().text_range(); | 17 | ctx.dot_receiver.as_ref().expect("no receiver available").syntax().text_range(); |
18 | let delete_range = TextRange::from_to(receiver_range.start(), ctx.source_range().end()); | 18 | let delete_range = TextRange::from_to(receiver_range.start(), ctx.source_range().end()); |
19 | let mut builder = TextEditBuilder::default(); | 19 | TextEdit::replace(delete_range, snippet.to_string()) |
20 | builder.replace(delete_range, snippet.to_string()); | ||
21 | builder.finish() | ||
22 | }; | 20 | }; |
23 | CompletionItem::new(CompletionKind::Postfix, ctx.source_range(), label) | 21 | CompletionItem::new(CompletionKind::Postfix, ctx.source_range(), label) |
24 | .detail(detail) | 22 | .detail(detail) |
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 3e6933bc1..5c9c44704 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs | |||
@@ -4,7 +4,7 @@ use std::fmt; | |||
4 | 4 | ||
5 | use hir::Documentation; | 5 | use hir::Documentation; |
6 | use ra_syntax::TextRange; | 6 | use ra_syntax::TextRange; |
7 | use ra_text_edit::{TextEdit, TextEditBuilder}; | 7 | use ra_text_edit::TextEdit; |
8 | 8 | ||
9 | /// `CompletionItem` describes a single completion variant in the editor pop-up. | 9 | /// `CompletionItem` describes a single completion variant in the editor pop-up. |
10 | /// It is basically a POD with various properties. To construct a | 10 | /// It is basically a POD with various properties. To construct a |
@@ -192,12 +192,10 @@ impl Builder { | |||
192 | let label = self.label; | 192 | let label = self.label; |
193 | let text_edit = match self.text_edit { | 193 | let text_edit = match self.text_edit { |
194 | Some(it) => it, | 194 | Some(it) => it, |
195 | None => { | 195 | None => TextEdit::replace( |
196 | let mut builder = TextEditBuilder::default(); | 196 | self.source_range, |
197 | builder | 197 | self.insert_text.unwrap_or_else(|| label.clone()), |
198 | .replace(self.source_range, self.insert_text.unwrap_or_else(|| label.clone())); | 198 | ), |
199 | builder.finish() | ||
200 | } | ||
201 | }; | 199 | }; |
202 | 200 | ||
203 | CompletionItem { | 201 | CompletionItem { |
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index 8743a3a79..1f1f5cd74 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs | |||
@@ -85,10 +85,9 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> | |||
85 | }) | 85 | }) |
86 | .on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| { | 86 | .on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| { |
87 | let node = d.ast(db); | 87 | let node = d.ast(db); |
88 | let mut builder = TextEditBuilder::default(); | ||
89 | let replacement = format!("Ok({})", node.syntax()); | 88 | let replacement = format!("Ok({})", node.syntax()); |
90 | builder.replace(node.syntax().text_range(), replacement); | 89 | let edit = TextEdit::replace(node.syntax().text_range(), replacement); |
91 | let fix = SourceChange::source_file_edit_from("wrap with ok", file_id, builder.finish()); | 90 | let fix = SourceChange::source_file_edit_from("wrap with ok", file_id, edit); |
92 | res.borrow_mut().push(Diagnostic { | 91 | res.borrow_mut().push(Diagnostic { |
93 | range: d.highlight_range(), | 92 | range: d.highlight_range(), |
94 | message: d.message(), | 93 | message: d.message(), |
@@ -152,9 +151,7 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement( | |||
152 | let start = use_tree_list_node.prev_sibling_or_token()?.text_range().start(); | 151 | let start = use_tree_list_node.prev_sibling_or_token()?.text_range().start(); |
153 | let end = use_tree_list_node.text_range().end(); | 152 | let end = use_tree_list_node.text_range().end(); |
154 | let range = TextRange::from_to(start, end); | 153 | let range = TextRange::from_to(start, end); |
155 | let mut edit_builder = TextEditBuilder::default(); | 154 | return Some(TextEdit::delete(range)); |
156 | edit_builder.delete(range); | ||
157 | return Some(edit_builder.finish()); | ||
158 | } | 155 | } |
159 | None | 156 | None |
160 | } | 157 | } |
diff --git a/crates/ra_ide_api/src/references/rename.rs b/crates/ra_ide_api/src/references/rename.rs index ee6e73e1b..a8783d7a0 100644 --- a/crates/ra_ide_api/src/references/rename.rs +++ b/crates/ra_ide_api/src/references/rename.rs | |||
@@ -3,6 +3,7 @@ | |||
3 | use hir::ModuleSource; | 3 | use hir::ModuleSource; |
4 | use ra_db::{SourceDatabase, SourceDatabaseExt}; | 4 | use ra_db::{SourceDatabase, SourceDatabaseExt}; |
5 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SyntaxNode}; | 5 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SyntaxNode}; |
6 | use ra_text_edit::TextEdit; | ||
6 | use relative_path::{RelativePath, RelativePathBuf}; | 7 | use relative_path::{RelativePath, RelativePathBuf}; |
7 | 8 | ||
8 | use crate::{ | 9 | use crate::{ |
@@ -43,14 +44,7 @@ fn source_edit_from_file_id_range( | |||
43 | range: TextRange, | 44 | range: TextRange, |
44 | new_name: &str, | 45 | new_name: &str, |
45 | ) -> SourceFileEdit { | 46 | ) -> SourceFileEdit { |
46 | SourceFileEdit { | 47 | SourceFileEdit { file_id, edit: TextEdit::replace(range, new_name.into()) } |
47 | file_id, | ||
48 | edit: { | ||
49 | let mut builder = ra_text_edit::TextEditBuilder::default(); | ||
50 | builder.replace(range, new_name.into()); | ||
51 | builder.finish() | ||
52 | }, | ||
53 | } | ||
54 | } | 48 | } |
55 | 49 | ||
56 | fn rename_mod( | 50 | fn rename_mod( |
@@ -94,11 +88,7 @@ fn rename_mod( | |||
94 | 88 | ||
95 | let edit = SourceFileEdit { | 89 | let edit = SourceFileEdit { |
96 | file_id: position.file_id, | 90 | file_id: position.file_id, |
97 | edit: { | 91 | edit: TextEdit::replace(ast_name.syntax().text_range(), new_name.into()), |
98 | let mut builder = ra_text_edit::TextEditBuilder::default(); | ||
99 | builder.replace(ast_name.syntax().text_range(), new_name.into()); | ||
100 | builder.finish() | ||
101 | }, | ||
102 | }; | 92 | }; |
103 | source_file_edits.push(edit); | 93 | source_file_edits.push(edit); |
104 | 94 | ||
@@ -126,12 +116,14 @@ fn rename_reference( | |||
126 | 116 | ||
127 | #[cfg(test)] | 117 | #[cfg(test)] |
128 | mod tests { | 118 | mod tests { |
119 | use insta::assert_debug_snapshot; | ||
120 | use ra_text_edit::TextEditBuilder; | ||
121 | use test_utils::assert_eq_text; | ||
122 | |||
129 | use crate::{ | 123 | use crate::{ |
130 | mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, | 124 | mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, |
131 | ReferenceSearchResult, | 125 | ReferenceSearchResult, |
132 | }; | 126 | }; |
133 | use insta::assert_debug_snapshot; | ||
134 | use test_utils::assert_eq_text; | ||
135 | 127 | ||
136 | #[test] | 128 | #[test] |
137 | fn test_find_all_refs_for_local() { | 129 | fn test_find_all_refs_for_local() { |
@@ -452,7 +444,7 @@ mod tests { | |||
452 | fn test_rename(text: &str, new_name: &str, expected: &str) { | 444 | fn test_rename(text: &str, new_name: &str, expected: &str) { |
453 | let (analysis, position) = single_file_with_position(text); | 445 | let (analysis, position) = single_file_with_position(text); |
454 | let source_change = analysis.rename(position, new_name).unwrap(); | 446 | let source_change = analysis.rename(position, new_name).unwrap(); |
455 | let mut text_edit_builder = ra_text_edit::TextEditBuilder::default(); | 447 | let mut text_edit_builder = TextEditBuilder::default(); |
456 | let mut file_id: Option<FileId> = None; | 448 | let mut file_id: Option<FileId> = None; |
457 | if let Some(change) = source_change { | 449 | if let Some(change) = source_change { |
458 | for edit in change.info.source_file_edits { | 450 | for edit in change.info.source_file_edits { |
diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs index 26a3111fd..2dfbe6944 100644 --- a/crates/ra_ide_api/src/typing.rs +++ b/crates/ra_ide_api/src/typing.rs | |||
@@ -22,7 +22,7 @@ use ra_syntax::{ | |||
22 | SyntaxKind::*, | 22 | SyntaxKind::*, |
23 | SyntaxToken, TextRange, TextUnit, TokenAtOffset, | 23 | SyntaxToken, TextRange, TextUnit, TokenAtOffset, |
24 | }; | 24 | }; |
25 | use ra_text_edit::{TextEdit, TextEditBuilder}; | 25 | use ra_text_edit::TextEdit; |
26 | 26 | ||
27 | use crate::{db::RootDatabase, source_change::SingleFileChange, SourceChange, SourceFileEdit}; | 27 | use crate::{db::RootDatabase, source_change::SingleFileChange, SourceChange, SourceFileEdit}; |
28 | 28 | ||
@@ -49,13 +49,12 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour | |||
49 | let indent = node_indent(&file, comment.syntax())?; | 49 | let indent = node_indent(&file, comment.syntax())?; |
50 | let inserted = format!("\n{}{} ", indent, prefix); | 50 | let inserted = format!("\n{}{} ", indent, prefix); |
51 | let cursor_position = position.offset + TextUnit::of_str(&inserted); | 51 | let cursor_position = position.offset + TextUnit::of_str(&inserted); |
52 | let mut edit = TextEditBuilder::default(); | 52 | let edit = TextEdit::insert(position.offset, inserted); |
53 | edit.insert(position.offset, inserted); | ||
54 | 53 | ||
55 | Some( | 54 | Some( |
56 | SourceChange::source_file_edit( | 55 | SourceChange::source_file_edit( |
57 | "on enter", | 56 | "on enter", |
58 | SourceFileEdit { edit: edit.finish(), file_id: position.file_id }, | 57 | SourceFileEdit { edit, file_id: position.file_id }, |
59 | ) | 58 | ) |
60 | .with_cursor(FilePosition { offset: cursor_position, file_id: position.file_id }), | 59 | .with_cursor(FilePosition { offset: cursor_position, file_id: position.file_id }), |
61 | ) | 60 | ) |