diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-06 10:34:24 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-06 10:34:24 +0100 |
commit | ede8906844e206f252810d58533538cf1fb326d4 (patch) | |
tree | fd9a78d80ae77f1fb706ba48bff0195be24bf5d6 /crates/ra_ide/src/source_change.rs | |
parent | 18907e6cc52d53b8385a26f3080cd21a6167022b (diff) | |
parent | 3850b1c0860a075f1fd569577c2a2fecd1fc2f0c (diff) |
Merge #4340
4340: Lift SourceChange to the ra_ide_db r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/source_change.rs')
-rw-r--r-- | crates/ra_ide/src/source_change.rs | 121 |
1 files changed, 0 insertions, 121 deletions
diff --git a/crates/ra_ide/src/source_change.rs b/crates/ra_ide/src/source_change.rs deleted file mode 100644 index 10afd7825..000000000 --- a/crates/ra_ide/src/source_change.rs +++ /dev/null | |||
@@ -1,121 +0,0 @@ | |||
1 | //! This modules defines type to represent changes to the source code, that flow | ||
2 | //! from the server to the client. | ||
3 | //! | ||
4 | //! It can be viewed as a dual for `AnalysisChange`. | ||
5 | |||
6 | use ra_db::RelativePathBuf; | ||
7 | use ra_text_edit::TextEdit; | ||
8 | |||
9 | use crate::{FileId, FilePosition, SourceRootId, TextSize}; | ||
10 | |||
11 | #[derive(Debug)] | ||
12 | pub struct SourceChange { | ||
13 | pub label: String, | ||
14 | pub source_file_edits: Vec<SourceFileEdit>, | ||
15 | pub file_system_edits: Vec<FileSystemEdit>, | ||
16 | pub cursor_position: Option<FilePosition>, | ||
17 | } | ||
18 | |||
19 | impl SourceChange { | ||
20 | /// Creates a new SourceChange with the given label | ||
21 | /// from the edits. | ||
22 | pub(crate) fn from_edits<L: Into<String>>( | ||
23 | label: L, | ||
24 | source_file_edits: Vec<SourceFileEdit>, | ||
25 | file_system_edits: Vec<FileSystemEdit>, | ||
26 | ) -> Self { | ||
27 | SourceChange { | ||
28 | label: label.into(), | ||
29 | source_file_edits, | ||
30 | file_system_edits, | ||
31 | cursor_position: None, | ||
32 | } | ||
33 | } | ||
34 | |||
35 | /// Creates a new SourceChange with the given label, | ||
36 | /// containing only the given `SourceFileEdits`. | ||
37 | pub(crate) fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self { | ||
38 | let label = label.into(); | ||
39 | assert!(label.starts_with(char::is_uppercase)); | ||
40 | SourceChange { | ||
41 | label: label, | ||
42 | source_file_edits: edits, | ||
43 | file_system_edits: vec![], | ||
44 | cursor_position: None, | ||
45 | } | ||
46 | } | ||
47 | |||
48 | /// Creates a new SourceChange with the given label, | ||
49 | /// containing only the given `FileSystemEdits`. | ||
50 | pub(crate) fn file_system_edits<L: Into<String>>(label: L, edits: Vec<FileSystemEdit>) -> Self { | ||
51 | SourceChange { | ||
52 | label: label.into(), | ||
53 | source_file_edits: vec![], | ||
54 | file_system_edits: edits, | ||
55 | cursor_position: None, | ||
56 | } | ||
57 | } | ||
58 | |||
59 | /// Creates a new SourceChange with the given label, | ||
60 | /// containing only a single `SourceFileEdit`. | ||
61 | pub(crate) fn source_file_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self { | ||
62 | SourceChange::source_file_edits(label, vec![edit]) | ||
63 | } | ||
64 | |||
65 | /// Creates a new SourceChange with the given label | ||
66 | /// from the given `FileId` and `TextEdit` | ||
67 | pub(crate) fn source_file_edit_from<L: Into<String>>( | ||
68 | label: L, | ||
69 | file_id: FileId, | ||
70 | edit: TextEdit, | ||
71 | ) -> Self { | ||
72 | SourceChange::source_file_edit(label, SourceFileEdit { file_id, edit }) | ||
73 | } | ||
74 | |||
75 | /// Creates a new SourceChange with the given label | ||
76 | /// from the given `FileId` and `TextEdit` | ||
77 | pub(crate) fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self { | ||
78 | SourceChange::file_system_edits(label, vec![edit]) | ||
79 | } | ||
80 | |||
81 | /// Sets the cursor position to the given `FilePosition` | ||
82 | pub(crate) fn with_cursor(mut self, cursor_position: FilePosition) -> Self { | ||
83 | self.cursor_position = Some(cursor_position); | ||
84 | self | ||
85 | } | ||
86 | |||
87 | /// Sets the cursor position to the given `FilePosition` | ||
88 | pub(crate) fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self { | ||
89 | self.cursor_position = cursor_position; | ||
90 | self | ||
91 | } | ||
92 | } | ||
93 | |||
94 | #[derive(Debug)] | ||
95 | pub struct SourceFileEdit { | ||
96 | pub file_id: FileId, | ||
97 | pub edit: TextEdit, | ||
98 | } | ||
99 | |||
100 | #[derive(Debug)] | ||
101 | pub enum FileSystemEdit { | ||
102 | CreateFile { source_root: SourceRootId, path: RelativePathBuf }, | ||
103 | MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf }, | ||
104 | } | ||
105 | |||
106 | pub(crate) struct SingleFileChange { | ||
107 | pub label: String, | ||
108 | pub edit: TextEdit, | ||
109 | pub cursor_position: Option<TextSize>, | ||
110 | } | ||
111 | |||
112 | impl SingleFileChange { | ||
113 | pub(crate) fn into_source_change(self, file_id: FileId) -> SourceChange { | ||
114 | SourceChange { | ||
115 | label: self.label, | ||
116 | source_file_edits: vec![SourceFileEdit { file_id, edit: self.edit }], | ||
117 | file_system_edits: Vec::new(), | ||
118 | cursor_position: self.cursor_position.map(|offset| FilePosition { file_id, offset }), | ||
119 | } | ||
120 | } | ||
121 | } | ||