diff options
-rw-r--r-- | crates/ra_ide/src/diagnostics.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/references/rename.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide/src/typing.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_db/src/source_change.rs | 23 |
5 files changed, 16 insertions, 25 deletions
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index 15dc50cf1..bf14a467f 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs | |||
@@ -21,7 +21,7 @@ use ra_syntax::{ | |||
21 | }; | 21 | }; |
22 | use ra_text_edit::{TextEdit, TextEditBuilder}; | 22 | use ra_text_edit::{TextEdit, TextEditBuilder}; |
23 | 23 | ||
24 | use crate::{Diagnostic, FileId, FileSystemEdit, Fix, SourceChange, SourceFileEdit}; | 24 | use crate::{Diagnostic, FileId, FileSystemEdit, Fix, SourceFileEdit}; |
25 | 25 | ||
26 | #[derive(Debug, Copy, Clone)] | 26 | #[derive(Debug, Copy, Clone)] |
27 | pub enum Severity { | 27 | pub enum Severity { |
@@ -115,7 +115,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> | |||
115 | let node = d.ast(db); | 115 | let node = d.ast(db); |
116 | let replacement = format!("Ok({})", node.syntax()); | 116 | let replacement = format!("Ok({})", node.syntax()); |
117 | let edit = TextEdit::replace(node.syntax().text_range(), replacement); | 117 | let edit = TextEdit::replace(node.syntax().text_range(), replacement); |
118 | let source_change = SourceChange::source_file_edit_from(file_id, edit); | 118 | let source_change = SourceFileEdit { file_id, edit }.into(); |
119 | let fix = Fix::new("Wrap with ok", source_change); | 119 | let fix = Fix::new("Wrap with ok", source_change); |
120 | res.borrow_mut().push(Diagnostic { | 120 | res.borrow_mut().push(Diagnostic { |
121 | range: sema.diagnostics_range(d).range, | 121 | range: sema.diagnostics_range(d).range, |
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index a56718d3f..28f686767 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -503,7 +503,7 @@ impl Analysis { | |||
503 | ) -> Cancelable<Result<SourceChange, SsrError>> { | 503 | ) -> Cancelable<Result<SourceChange, SsrError>> { |
504 | self.with_db(|db| { | 504 | self.with_db(|db| { |
505 | let edits = ssr::parse_search_replace(query, parse_only, db)?; | 505 | let edits = ssr::parse_search_replace(query, parse_only, db)?; |
506 | Ok(SourceChange::source_file_edits(edits)) | 506 | Ok(SourceChange::from(edits)) |
507 | }) | 507 | }) |
508 | } | 508 | } |
509 | 509 | ||
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 28c6349b1..915d4f4d3 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs | |||
@@ -171,7 +171,7 @@ fn rename_to_self(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo | |||
171 | ), | 171 | ), |
172 | }); | 172 | }); |
173 | 173 | ||
174 | Some(RangeInfo::new(range, SourceChange::source_file_edits(edits))) | 174 | Some(RangeInfo::new(range, SourceChange::from(edits))) |
175 | } | 175 | } |
176 | 176 | ||
177 | fn text_edit_from_self_param( | 177 | fn text_edit_from_self_param( |
@@ -234,7 +234,7 @@ fn rename_self_to_param( | |||
234 | let range = ast::SelfParam::cast(self_token.parent()) | 234 | let range = ast::SelfParam::cast(self_token.parent()) |
235 | .map_or(self_token.text_range(), |p| p.syntax().text_range()); | 235 | .map_or(self_token.text_range(), |p| p.syntax().text_range()); |
236 | 236 | ||
237 | Some(RangeInfo::new(range, SourceChange::source_file_edits(edits))) | 237 | Some(RangeInfo::new(range, SourceChange::from(edits))) |
238 | } | 238 | } |
239 | 239 | ||
240 | fn rename_reference( | 240 | fn rename_reference( |
@@ -253,7 +253,7 @@ fn rename_reference( | |||
253 | return None; | 253 | return None; |
254 | } | 254 | } |
255 | 255 | ||
256 | Some(RangeInfo::new(range, SourceChange::source_file_edits(edit))) | 256 | Some(RangeInfo::new(range, SourceChange::from(edit))) |
257 | } | 257 | } |
258 | 258 | ||
259 | #[cfg(test)] | 259 | #[cfg(test)] |
diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index 67e2c33a0..533306e2e 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs | |||
@@ -17,7 +17,7 @@ mod on_enter; | |||
17 | 17 | ||
18 | use ra_db::{FilePosition, SourceDatabase}; | 18 | use ra_db::{FilePosition, SourceDatabase}; |
19 | use ra_fmt::leading_indent; | 19 | use ra_fmt::leading_indent; |
20 | use ra_ide_db::RootDatabase; | 20 | use ra_ide_db::{source_change::SourceFileEdit, RootDatabase}; |
21 | use ra_syntax::{ | 21 | use ra_syntax::{ |
22 | algo::find_node_at_offset, | 22 | algo::find_node_at_offset, |
23 | ast::{self, AstToken}, | 23 | ast::{self, AstToken}, |
@@ -47,8 +47,8 @@ pub(crate) fn on_char_typed( | |||
47 | assert!(TRIGGER_CHARS.contains(char_typed)); | 47 | assert!(TRIGGER_CHARS.contains(char_typed)); |
48 | let file = &db.parse(position.file_id).tree(); | 48 | let file = &db.parse(position.file_id).tree(); |
49 | assert_eq!(file.syntax().text().char_at(position.offset), Some(char_typed)); | 49 | assert_eq!(file.syntax().text().char_at(position.offset), Some(char_typed)); |
50 | let text_edit = on_char_typed_inner(file, position.offset, char_typed)?; | 50 | let edit = on_char_typed_inner(file, position.offset, char_typed)?; |
51 | Some(SourceChange::source_file_edit_from(position.file_id, text_edit)) | 51 | Some(SourceFileEdit { file_id: position.file_id, edit }.into()) |
52 | } | 52 | } |
53 | 53 | ||
54 | fn on_char_typed_inner(file: &SourceFile, offset: TextSize, char_typed: char) -> Option<TextEdit> { | 54 | fn on_char_typed_inner(file: &SourceFile, offset: TextSize, char_typed: char) -> Option<TextEdit> { |
diff --git a/crates/ra_ide_db/src/source_change.rs b/crates/ra_ide_db/src/source_change.rs index e713f4b7e..f40ae8304 100644 --- a/crates/ra_ide_db/src/source_change.rs +++ b/crates/ra_ide_db/src/source_change.rs | |||
@@ -22,17 +22,6 @@ impl SourceChange { | |||
22 | ) -> Self { | 22 | ) -> Self { |
23 | SourceChange { source_file_edits, file_system_edits, is_snippet: false } | 23 | SourceChange { source_file_edits, file_system_edits, is_snippet: false } |
24 | } | 24 | } |
25 | |||
26 | /// Creates a new SourceChange with the given label, | ||
27 | /// containing only the given `SourceFileEdits`. | ||
28 | pub fn source_file_edits(edits: Vec<SourceFileEdit>) -> Self { | ||
29 | SourceChange { source_file_edits: edits, file_system_edits: vec![], is_snippet: false } | ||
30 | } | ||
31 | /// Creates a new SourceChange with the given label | ||
32 | /// from the given `FileId` and `TextEdit` | ||
33 | pub fn source_file_edit_from(file_id: FileId, edit: TextEdit) -> Self { | ||
34 | SourceFileEdit { file_id, edit }.into() | ||
35 | } | ||
36 | } | 25 | } |
37 | 26 | ||
38 | #[derive(Debug, Clone)] | 27 | #[derive(Debug, Clone)] |
@@ -43,11 +32,13 @@ pub struct SourceFileEdit { | |||
43 | 32 | ||
44 | impl From<SourceFileEdit> for SourceChange { | 33 | impl From<SourceFileEdit> for SourceChange { |
45 | fn from(edit: SourceFileEdit) -> SourceChange { | 34 | fn from(edit: SourceFileEdit) -> SourceChange { |
46 | SourceChange { | 35 | vec![edit].into() |
47 | source_file_edits: vec![edit], | 36 | } |
48 | file_system_edits: Vec::new(), | 37 | } |
49 | is_snippet: false, | 38 | |
50 | } | 39 | impl From<Vec<SourceFileEdit>> for SourceChange { |
40 | fn from(source_file_edits: Vec<SourceFileEdit>) -> SourceChange { | ||
41 | SourceChange { source_file_edits, file_system_edits: Vec::new(), is_snippet: false } | ||
51 | } | 42 | } |
52 | } | 43 | } |
53 | 44 | ||