aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src/source_change.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_db/src/source_change.rs')
-rw-r--r--crates/ide_db/src/source_change.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/crates/ide_db/src/source_change.rs b/crates/ide_db/src/source_change.rs
new file mode 100644
index 000000000..f1590ec66
--- /dev/null
+++ b/crates/ide_db/src/source_change.rs
@@ -0,0 +1,59 @@
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
6use base_db::FileId;
7use text_edit::TextEdit;
8
9#[derive(Default, Debug, Clone)]
10pub struct SourceChange {
11 pub source_file_edits: Vec<SourceFileEdit>,
12 pub file_system_edits: Vec<FileSystemEdit>,
13 pub is_snippet: bool,
14}
15
16impl SourceChange {
17 /// Creates a new SourceChange with the given label
18 /// from the edits.
19 pub fn from_edits(
20 source_file_edits: Vec<SourceFileEdit>,
21 file_system_edits: Vec<FileSystemEdit>,
22 ) -> Self {
23 SourceChange { source_file_edits, file_system_edits, is_snippet: false }
24 }
25}
26
27#[derive(Debug, Clone)]
28pub struct SourceFileEdit {
29 pub file_id: FileId,
30 pub edit: TextEdit,
31}
32
33impl From<SourceFileEdit> for SourceChange {
34 fn from(edit: SourceFileEdit) -> SourceChange {
35 vec![edit].into()
36 }
37}
38
39impl 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 }
42 }
43}
44
45#[derive(Debug, Clone)]
46pub enum FileSystemEdit {
47 CreateFile { anchor: FileId, dst: String },
48 MoveFile { src: FileId, anchor: FileId, dst: String },
49}
50
51impl From<FileSystemEdit> for SourceChange {
52 fn from(edit: FileSystemEdit) -> SourceChange {
53 SourceChange {
54 source_file_edits: Vec::new(),
55 file_system_edits: vec![edit],
56 is_snippet: false,
57 }
58 }
59}