From 2a42904680041664621034c22c3f600a47107a5a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 8 Jun 2020 21:44:42 +0200 Subject: [PATCH] Simplify --- crates/ra_ide/src/diagnostics.rs | 4 ++-- crates/ra_ide/src/lib.rs | 2 +- crates/ra_ide/src/references/rename.rs | 6 +++--- crates/ra_ide/src/typing.rs | 6 +++--- 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 15dc50cf14..bf14a467f8 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs @@ -21,7 +21,7 @@ use ra_syntax::{ }; use ra_text_edit::{TextEdit, TextEditBuilder}; -use crate::{Diagnostic, FileId, FileSystemEdit, Fix, SourceChange, SourceFileEdit}; +use crate::{Diagnostic, FileId, FileSystemEdit, Fix, SourceFileEdit}; #[derive(Debug, Copy, Clone)] pub enum Severity { @@ -115,7 +115,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec let node = d.ast(db); let replacement = format!("Ok({})", node.syntax()); let edit = TextEdit::replace(node.syntax().text_range(), replacement); - let source_change = SourceChange::source_file_edit_from(file_id, edit); + let source_change = SourceFileEdit { file_id, edit }.into(); let fix = Fix::new("Wrap with ok", source_change); res.borrow_mut().push(Diagnostic { range: sema.diagnostics_range(d).range, diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index a56718d3f5..28f6867672 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -503,7 +503,7 @@ impl Analysis { ) -> Cancelable> { self.with_db(|db| { let edits = ssr::parse_search_replace(query, parse_only, db)?; - Ok(SourceChange::source_file_edits(edits)) + Ok(SourceChange::from(edits)) }) } diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 28c6349b1b..915d4f4d3b 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 Option { diff --git a/crates/ra_ide_db/src/source_change.rs b/crates/ra_ide_db/src/source_change.rs index e713f4b7e8..f40ae8304a 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 { ) -> Self { SourceChange { source_file_edits, file_system_edits, is_snippet: false } } - - /// Creates a new SourceChange with the given label, - /// containing only the given `SourceFileEdits`. - pub fn source_file_edits(edits: Vec) -> Self { - SourceChange { source_file_edits: edits, file_system_edits: vec![], is_snippet: false } - } - /// Creates a new SourceChange with the given label - /// from the given `FileId` and `TextEdit` - pub fn source_file_edit_from(file_id: FileId, edit: TextEdit) -> Self { - SourceFileEdit { file_id, edit }.into() - } } #[derive(Debug, Clone)] @@ -43,11 +32,13 @@ pub struct SourceFileEdit { impl From for SourceChange { fn from(edit: SourceFileEdit) -> SourceChange { - SourceChange { - source_file_edits: vec![edit], - file_system_edits: Vec::new(), - is_snippet: false, - } + vec![edit].into() + } +} + +impl From> for SourceChange { + fn from(source_file_edits: Vec) -> SourceChange { + SourceChange { source_file_edits, file_system_edits: Vec::new(), is_snippet: false } } }