diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-22 17:09:37 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-22 17:09:37 +0100 |
commit | a95bb1355dd5fb95f6d66e6cd6b14b6ae8051f77 (patch) | |
tree | d4b33d1360afd4dbcbd479f0691bed7c98de2895 /crates/ra_ide_db | |
parent | 2a36a2a3cc016de61a5df3165037ed689f36c423 (diff) | |
parent | 2c04aad2d2a52ce52d6ea6452faf8d1788f0c83f (diff) |
Merge #4571
4571: KISS SourceChange r=matklad a=matklad
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.
bors r+
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_db')
-rw-r--r-- | crates/ra_ide_db/src/source_change.rs | 79 |
1 files changed, 20 insertions, 59 deletions
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; | |||
8 | 8 | ||
9 | #[derive(Debug, Clone)] | 9 | #[derive(Debug, Clone)] |
10 | pub struct SourceChange { | 10 | pub struct SourceChange { |
11 | /// For display in the undo log in the editor | ||
12 | pub label: String, | ||
13 | pub source_file_edits: Vec<SourceFileEdit>, | 11 | pub source_file_edits: Vec<SourceFileEdit>, |
14 | pub file_system_edits: Vec<FileSystemEdit>, | 12 | pub file_system_edits: Vec<FileSystemEdit>, |
15 | pub is_snippet: bool, | 13 | pub is_snippet: bool, |
@@ -18,63 +16,22 @@ pub struct SourceChange { | |||
18 | impl SourceChange { | 16 | impl SourceChange { |
19 | /// Creates a new SourceChange with the given label | 17 | /// Creates a new SourceChange with the given label |
20 | /// from the edits. | 18 | /// from the edits. |
21 | pub fn from_edits<L: Into<String>>( | 19 | pub fn from_edits( |
22 | label: L, | ||
23 | source_file_edits: Vec<SourceFileEdit>, | 20 | source_file_edits: Vec<SourceFileEdit>, |
24 | file_system_edits: Vec<FileSystemEdit>, | 21 | file_system_edits: Vec<FileSystemEdit>, |
25 | ) -> Self { | 22 | ) -> Self { |
26 | SourceChange { | 23 | SourceChange { source_file_edits, file_system_edits, is_snippet: false } |
27 | label: label.into(), | ||
28 | source_file_edits, | ||
29 | file_system_edits, | ||
30 | is_snippet: false, | ||
31 | } | ||
32 | } | 24 | } |
33 | 25 | ||
34 | /// Creates a new SourceChange with the given label, | 26 | /// Creates a new SourceChange with the given label, |
35 | /// containing only the given `SourceFileEdits`. | 27 | /// containing only the given `SourceFileEdits`. |
36 | pub fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self { | 28 | pub fn source_file_edits(edits: Vec<SourceFileEdit>) -> Self { |
37 | let label = label.into(); | 29 | SourceChange { source_file_edits: edits, file_system_edits: vec![], is_snippet: false } |
38 | assert!(label.starts_with(char::is_uppercase)); | ||
39 | SourceChange { | ||
40 | label: label, | ||
41 | source_file_edits: edits, | ||
42 | file_system_edits: vec![], | ||
43 | is_snippet: false, | ||
44 | } | ||
45 | } | ||
46 | |||
47 | /// Creates a new SourceChange with the given label, | ||
48 | /// containing only the given `FileSystemEdits`. | ||
49 | pub(crate) fn file_system_edits<L: Into<String>>(label: L, edits: Vec<FileSystemEdit>) -> Self { | ||
50 | SourceChange { | ||
51 | label: label.into(), | ||
52 | source_file_edits: vec![], | ||
53 | file_system_edits: edits, | ||
54 | is_snippet: false, | ||
55 | } | ||
56 | } | ||
57 | |||
58 | /// Creates a new SourceChange with the given label, | ||
59 | /// containing only a single `SourceFileEdit`. | ||
60 | pub fn source_file_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self { | ||
61 | SourceChange::source_file_edits(label, vec![edit]) | ||
62 | } | ||
63 | |||
64 | /// Creates a new SourceChange with the given label | ||
65 | /// from the given `FileId` and `TextEdit` | ||
66 | pub fn source_file_edit_from<L: Into<String>>( | ||
67 | label: L, | ||
68 | file_id: FileId, | ||
69 | edit: TextEdit, | ||
70 | ) -> Self { | ||
71 | SourceChange::source_file_edit(label, SourceFileEdit { file_id, edit }) | ||
72 | } | 30 | } |
73 | |||
74 | /// Creates a new SourceChange with the given label | 31 | /// Creates a new SourceChange with the given label |
75 | /// from the given `FileId` and `TextEdit` | 32 | /// from the given `FileId` and `TextEdit` |
76 | pub fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self { | 33 | pub fn source_file_edit_from(file_id: FileId, edit: TextEdit) -> Self { |
77 | SourceChange::file_system_edits(label, vec![edit]) | 34 | SourceFileEdit { file_id, edit }.into() |
78 | } | 35 | } |
79 | } | 36 | } |
80 | 37 | ||
@@ -84,23 +41,27 @@ pub struct SourceFileEdit { | |||
84 | pub edit: TextEdit, | 41 | pub edit: TextEdit, |
85 | } | 42 | } |
86 | 43 | ||
44 | impl From<SourceFileEdit> for SourceChange { | ||
45 | fn from(edit: SourceFileEdit) -> SourceChange { | ||
46 | SourceChange { | ||
47 | source_file_edits: vec![edit], | ||
48 | file_system_edits: Vec::new(), | ||
49 | is_snippet: false, | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
87 | #[derive(Debug, Clone)] | 54 | #[derive(Debug, Clone)] |
88 | pub enum FileSystemEdit { | 55 | pub enum FileSystemEdit { |
89 | CreateFile { source_root: SourceRootId, path: RelativePathBuf }, | 56 | CreateFile { source_root: SourceRootId, path: RelativePathBuf }, |
90 | MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf }, | 57 | MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf }, |
91 | } | 58 | } |
92 | 59 | ||
93 | pub struct SingleFileChange { | 60 | impl From<FileSystemEdit> for SourceChange { |
94 | pub label: String, | 61 | fn from(edit: FileSystemEdit) -> SourceChange { |
95 | pub edit: TextEdit, | ||
96 | } | ||
97 | |||
98 | impl SingleFileChange { | ||
99 | pub fn into_source_change(self, file_id: FileId) -> SourceChange { | ||
100 | SourceChange { | 62 | SourceChange { |
101 | label: self.label, | 63 | source_file_edits: Vec::new(), |
102 | source_file_edits: vec![SourceFileEdit { file_id, edit: self.edit }], | 64 | file_system_edits: vec![edit], |
103 | file_system_edits: Vec::new(), | ||
104 | is_snippet: false, | 65 | is_snippet: false, |
105 | } | 66 | } |
106 | } | 67 | } |