aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-10-25 09:26:53 +0100
committerAleksey Kladov <[email protected]>2019-10-25 09:30:50 +0100
commitb112430ca73f646b6cb779ab09a3f691aad22442 (patch)
tree903489a6b436f8bd1589195a56b3b18f949eb738
parent8d2fd59cfb00211573419b0a59cf91d92d636f5a (diff)
move source change to a dedicated file
-rw-r--r--crates/ra_ide_api/src/lib.rs97
-rw-r--r--crates/ra_ide_api/src/source_change.rs102
2 files changed, 104 insertions, 95 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index b2a1d185b..6b8aa7a8e 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -14,6 +14,7 @@ mod db;
14pub mod mock_analysis; 14pub mod mock_analysis;
15mod symbol_index; 15mod symbol_index;
16mod change; 16mod change;
17mod source_change;
17mod feature_flags; 18mod feature_flags;
18 19
19mod status; 20mod status;
@@ -54,8 +55,6 @@ use ra_db::{
54 CheckCanceled, FileLoader, SourceDatabase, 55 CheckCanceled, FileLoader, SourceDatabase,
55}; 56};
56use ra_syntax::{SourceFile, TextRange, TextUnit}; 57use ra_syntax::{SourceFile, TextRange, TextUnit};
57use ra_text_edit::TextEdit;
58use relative_path::RelativePathBuf;
59 58
60use crate::{db::LineIndexDatabase, symbol_index::FileSymbol}; 59use crate::{db::LineIndexDatabase, symbol_index::FileSymbol};
61 60
@@ -73,6 +72,7 @@ pub use crate::{
73 line_index_utils::translate_offset_with_edit, 72 line_index_utils::translate_offset_with_edit,
74 references::{ReferenceSearchResult, SearchScope}, 73 references::{ReferenceSearchResult, SearchScope},
75 runnables::{Runnable, RunnableKind}, 74 runnables::{Runnable, RunnableKind},
75 source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
76 syntax_highlighting::HighlightedRange, 76 syntax_highlighting::HighlightedRange,
77}; 77};
78 78
@@ -84,99 +84,6 @@ pub use ra_db::{
84pub type Cancelable<T> = Result<T, Canceled>; 84pub type Cancelable<T> = Result<T, Canceled>;
85 85
86#[derive(Debug)] 86#[derive(Debug)]
87pub struct SourceChange {
88 pub label: String,
89 pub source_file_edits: Vec<SourceFileEdit>,
90 pub file_system_edits: Vec<FileSystemEdit>,
91 pub cursor_position: Option<FilePosition>,
92}
93
94impl SourceChange {
95 /// Creates a new SourceChange with the given label
96 /// from the edits.
97 pub(crate) fn from_edits<L: Into<String>>(
98 label: L,
99 source_file_edits: Vec<SourceFileEdit>,
100 file_system_edits: Vec<FileSystemEdit>,
101 ) -> Self {
102 SourceChange {
103 label: label.into(),
104 source_file_edits,
105 file_system_edits,
106 cursor_position: None,
107 }
108 }
109
110 /// Creates a new SourceChange with the given label,
111 /// containing only the given `SourceFileEdits`.
112 pub(crate) fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self {
113 SourceChange {
114 label: label.into(),
115 source_file_edits: edits,
116 file_system_edits: vec![],
117 cursor_position: None,
118 }
119 }
120
121 /// Creates a new SourceChange with the given label,
122 /// containing only the given `FileSystemEdits`.
123 pub(crate) fn file_system_edits<L: Into<String>>(label: L, edits: Vec<FileSystemEdit>) -> Self {
124 SourceChange {
125 label: label.into(),
126 source_file_edits: vec![],
127 file_system_edits: edits,
128 cursor_position: None,
129 }
130 }
131
132 /// Creates a new SourceChange with the given label,
133 /// containing only a single `SourceFileEdit`.
134 pub(crate) fn source_file_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self {
135 SourceChange::source_file_edits(label, vec![edit])
136 }
137
138 /// Creates a new SourceChange with the given label
139 /// from the given `FileId` and `TextEdit`
140 pub(crate) fn source_file_edit_from<L: Into<String>>(
141 label: L,
142 file_id: FileId,
143 edit: TextEdit,
144 ) -> Self {
145 SourceChange::source_file_edit(label, SourceFileEdit { file_id, edit })
146 }
147
148 /// Creates a new SourceChange with the given label
149 /// from the given `FileId` and `TextEdit`
150 pub(crate) fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self {
151 SourceChange::file_system_edits(label, vec![edit])
152 }
153
154 /// Sets the cursor position to the given `FilePosition`
155 pub(crate) fn with_cursor(mut self, cursor_position: FilePosition) -> Self {
156 self.cursor_position = Some(cursor_position);
157 self
158 }
159
160 /// Sets the cursor position to the given `FilePosition`
161 pub(crate) fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self {
162 self.cursor_position = cursor_position;
163 self
164 }
165}
166
167#[derive(Debug)]
168pub struct SourceFileEdit {
169 pub file_id: FileId,
170 pub edit: TextEdit,
171}
172
173#[derive(Debug)]
174pub enum FileSystemEdit {
175 CreateFile { source_root: SourceRootId, path: RelativePathBuf },
176 MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf },
177}
178
179#[derive(Debug)]
180pub struct Diagnostic { 87pub struct Diagnostic {
181 pub message: String, 88 pub message: String,
182 pub range: TextRange, 89 pub range: TextRange,
diff --git a/crates/ra_ide_api/src/source_change.rs b/crates/ra_ide_api/src/source_change.rs
new file mode 100644
index 000000000..80e8821b0
--- /dev/null
+++ b/crates/ra_ide_api/src/source_change.rs
@@ -0,0 +1,102 @@
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 ra_text_edit::TextEdit;
7use relative_path::RelativePathBuf;
8
9use crate::{FileId, FilePosition, SourceRootId};
10
11#[derive(Debug)]
12pub 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
19impl 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 SourceChange {
39 label: label.into(),
40 source_file_edits: edits,
41 file_system_edits: vec![],
42 cursor_position: None,
43 }
44 }
45
46 /// Creates a new SourceChange with the given label,
47 /// containing only the given `FileSystemEdits`.
48 pub(crate) fn file_system_edits<L: Into<String>>(label: L, edits: Vec<FileSystemEdit>) -> Self {
49 SourceChange {
50 label: label.into(),
51 source_file_edits: vec![],
52 file_system_edits: edits,
53 cursor_position: None,
54 }
55 }
56
57 /// Creates a new SourceChange with the given label,
58 /// containing only a single `SourceFileEdit`.
59 pub(crate) fn source_file_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self {
60 SourceChange::source_file_edits(label, vec![edit])
61 }
62
63 /// Creates a new SourceChange with the given label
64 /// from the given `FileId` and `TextEdit`
65 pub(crate) fn source_file_edit_from<L: Into<String>>(
66 label: L,
67 file_id: FileId,
68 edit: TextEdit,
69 ) -> Self {
70 SourceChange::source_file_edit(label, SourceFileEdit { file_id, edit })
71 }
72
73 /// Creates a new SourceChange with the given label
74 /// from the given `FileId` and `TextEdit`
75 pub(crate) fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self {
76 SourceChange::file_system_edits(label, vec![edit])
77 }
78
79 /// Sets the cursor position to the given `FilePosition`
80 pub(crate) fn with_cursor(mut self, cursor_position: FilePosition) -> Self {
81 self.cursor_position = Some(cursor_position);
82 self
83 }
84
85 /// Sets the cursor position to the given `FilePosition`
86 pub(crate) fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self {
87 self.cursor_position = cursor_position;
88 self
89 }
90}
91
92#[derive(Debug)]
93pub struct SourceFileEdit {
94 pub file_id: FileId,
95 pub edit: TextEdit,
96}
97
98#[derive(Debug)]
99pub enum FileSystemEdit {
100 CreateFile { source_root: SourceRootId, path: RelativePathBuf },
101 MoveFile { src: FileId, dst_source_root: SourceRootId, dst_path: RelativePathBuf },
102}