From 2c04aad2d2a52ce52d6ea6452faf8d1788f0c83f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 May 2020 18:03:08 +0200 Subject: KISS SourceChange The idea behind requiring the label is a noble one, but we are not really using it consistently anyway, and it should be easy to retrofit later, should we need it. --- crates/ra_ide_db/src/source_change.rs | 79 +++++++++-------------------------- 1 file changed, 20 insertions(+), 59 deletions(-) (limited to 'crates/ra_ide_db') diff --git a/crates/ra_ide_db/src/source_change.rs b/crates/ra_ide_db/src/source_change.rs index 3484f5588..e713f4b7e 100644 --- a/crates/ra_ide_db/src/source_change.rs +++ b/crates/ra_ide_db/src/source_change.rs @@ -8,8 +8,6 @@ use ra_text_edit::TextEdit; #[derive(Debug, Clone)] pub struct SourceChange { - /// For display in the undo log in the editor - pub label: String, pub source_file_edits: Vec, pub file_system_edits: Vec, pub is_snippet: bool, @@ -18,63 +16,22 @@ pub struct SourceChange { impl SourceChange { /// Creates a new SourceChange with the given label /// from the edits. - pub fn from_edits>( - label: L, + pub fn from_edits( source_file_edits: Vec, file_system_edits: Vec, ) -> Self { - SourceChange { - label: label.into(), - source_file_edits, - file_system_edits, - is_snippet: false, - } + 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>(label: L, edits: Vec) -> Self { - let label = label.into(); - assert!(label.starts_with(char::is_uppercase)); - SourceChange { - label: label, - source_file_edits: edits, - file_system_edits: vec![], - is_snippet: false, - } - } - - /// Creates a new SourceChange with the given label, - /// containing only the given `FileSystemEdits`. - pub(crate) fn file_system_edits>(label: L, edits: Vec) -> Self { - SourceChange { - label: label.into(), - source_file_edits: vec![], - file_system_edits: edits, - is_snippet: false, - } - } - - /// Creates a new SourceChange with the given label, - /// containing only a single `SourceFileEdit`. - pub fn source_file_edit>(label: L, edit: SourceFileEdit) -> Self { - SourceChange::source_file_edits(label, vec![edit]) - } - - /// Creates a new SourceChange with the given label - /// from the given `FileId` and `TextEdit` - pub fn source_file_edit_from>( - label: L, - file_id: FileId, - edit: TextEdit, - ) -> Self { - SourceChange::source_file_edit(label, SourceFileEdit { file_id, edit }) + 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 file_system_edit>(label: L, edit: FileSystemEdit) -> Self { - SourceChange::file_system_edits(label, vec![edit]) + pub fn source_file_edit_from(file_id: FileId, edit: TextEdit) -> Self { + SourceFileEdit { file_id, edit }.into() } } @@ -84,23 +41,27 @@ pub struct SourceFileEdit { pub edit: TextEdit, } +impl From for SourceChange { + fn from(edit: SourceFileEdit) -> SourceChange { + SourceChange { + source_file_edits: vec![edit], + file_system_edits: Vec::new(), + is_snippet: false, + } + } +} + #[derive(Debug, Clone)] pub enum FileSystemEdit { CreateFile { source_root: SourceRootId, path: RelativePathBuf }, MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf }, } -pub struct SingleFileChange { - pub label: String, - pub edit: TextEdit, -} - -impl SingleFileChange { - pub fn into_source_change(self, file_id: FileId) -> SourceChange { +impl From for SourceChange { + fn from(edit: FileSystemEdit) -> SourceChange { SourceChange { - label: self.label, - source_file_edits: vec![SourceFileEdit { file_id, edit: self.edit }], - file_system_edits: Vec::new(), + source_file_edits: Vec::new(), + file_system_edits: vec![edit], is_snippet: false, } } -- cgit v1.2.3