diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide_api/src/diagnostics.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 49 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references.rs | 14 | ||||
-rw-r--r-- | crates/ra_ide_api/src/typing.rs | 12 |
4 files changed, 50 insertions, 27 deletions
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index b0f23773e..6559de29d 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs | |||
@@ -140,7 +140,7 @@ fn check_module( | |||
140 | Problem::UnresolvedModule { candidate } => { | 140 | Problem::UnresolvedModule { candidate } => { |
141 | let create_file = | 141 | let create_file = |
142 | FileSystemEdit::CreateFile { source_root, path: candidate.clone() }; | 142 | FileSystemEdit::CreateFile { source_root, path: candidate.clone() }; |
143 | let fix = SourceChange::system_edit("create module", create_file); | 143 | let fix = SourceChange::file_system_edit("create module", create_file); |
144 | Diagnostic { | 144 | Diagnostic { |
145 | range: name_node.range(), | 145 | range: name_node.range(), |
146 | message: "unresolved module".to_string(), | 146 | message: "unresolved module".to_string(), |
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 4e4001750..928f3d604 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -98,7 +98,24 @@ pub struct SourceChange { | |||
98 | } | 98 | } |
99 | 99 | ||
100 | impl SourceChange { | 100 | impl SourceChange { |
101 | pub fn source_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self { | 101 | /// Creates a new SourceChange with the given label |
102 | /// from the edits. | ||
103 | pub(crate) fn from_edits<L: Into<String>>( | ||
104 | label: L, | ||
105 | source_file_edits: Vec<SourceFileEdit>, | ||
106 | file_system_edits: Vec<FileSystemEdit>, | ||
107 | ) -> Self { | ||
108 | SourceChange { | ||
109 | label: label.into(), | ||
110 | source_file_edits, | ||
111 | file_system_edits, | ||
112 | cursor_position: None, | ||
113 | } | ||
114 | } | ||
115 | |||
116 | /// Creates a new SourceChange with the given label, | ||
117 | /// containing only the given `SourceFileEdits`. | ||
118 | pub(crate) fn source_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self { | ||
102 | SourceChange { | 119 | SourceChange { |
103 | label: label.into(), | 120 | label: label.into(), |
104 | source_file_edits: edits, | 121 | source_file_edits: edits, |
@@ -107,7 +124,9 @@ impl SourceChange { | |||
107 | } | 124 | } |
108 | } | 125 | } |
109 | 126 | ||
110 | pub fn system_edits<L: Into<String>>(label: L, edits: Vec<FileSystemEdit>) -> Self { | 127 | /// Creates a new SourceChange with the given label, |
128 | /// containing only the given `FileSystemEdits`. | ||
129 | pub(crate) fn file_system_edits<L: Into<String>>(label: L, edits: Vec<FileSystemEdit>) -> Self { | ||
111 | SourceChange { | 130 | SourceChange { |
112 | label: label.into(), | 131 | label: label.into(), |
113 | source_file_edits: vec![], | 132 | source_file_edits: vec![], |
@@ -116,20 +135,36 @@ impl SourceChange { | |||
116 | } | 135 | } |
117 | } | 136 | } |
118 | 137 | ||
119 | pub fn source_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self { | 138 | /// Creates a new SourceChange with the given label, |
139 | /// containing only a single `SourceFileEdit`. | ||
140 | pub(crate) fn source_edit<L: Into<String>>(label: L, edit: SourceFileEdit) -> Self { | ||
120 | SourceChange::source_edits(label, vec![edit]) | 141 | SourceChange::source_edits(label, vec![edit]) |
121 | } | 142 | } |
122 | 143 | ||
123 | pub fn system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self { | 144 | /// Creates a new SourceChange with the given label |
124 | SourceChange::system_edits(label, vec![edit]) | 145 | /// from the given `FileId` and `TextEdit` |
146 | pub(crate) fn source_file_edit_from<L: Into<String>>( | ||
147 | label: L, | ||
148 | file_id: FileId, | ||
149 | edit: TextEdit, | ||
150 | ) -> Self { | ||
151 | SourceChange::source_edit(label, SourceFileEdit { file_id, edit }) | ||
152 | } | ||
153 | |||
154 | /// Creates a new SourceChange with the given label | ||
155 | /// from the given `FileId` and `TextEdit` | ||
156 | pub(crate) fn file_system_edit<L: Into<String>>(label: L, edit: FileSystemEdit) -> Self { | ||
157 | SourceChange::file_system_edits(label, vec![edit]) | ||
125 | } | 158 | } |
126 | 159 | ||
127 | pub fn with_cursor(mut self, cursor_position: FilePosition) -> Self { | 160 | /// Sets the cursor position to the given `FilePosition` |
161 | pub(crate) fn with_cursor(mut self, cursor_position: FilePosition) -> Self { | ||
128 | self.cursor_position = Some(cursor_position); | 162 | self.cursor_position = Some(cursor_position); |
129 | self | 163 | self |
130 | } | 164 | } |
131 | 165 | ||
132 | pub fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self { | 166 | /// Sets the cursor position to the given `FilePosition` |
167 | pub(crate) fn with_cursor_opt(mut self, cursor_position: Option<FilePosition>) -> Self { | ||
133 | self.cursor_position = cursor_position; | 168 | self.cursor_position = cursor_position; |
134 | self | 169 | self |
135 | } | 170 | } |
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs index b7784e577..78f77e761 100644 --- a/crates/ra_ide_api/src/references.rs +++ b/crates/ra_ide_api/src/references.rs | |||
@@ -187,12 +187,7 @@ fn rename_mod( | |||
187 | }; | 187 | }; |
188 | source_file_edits.push(edit); | 188 | source_file_edits.push(edit); |
189 | 189 | ||
190 | Some(SourceChange { | 190 | Some(SourceChange::from_edits("rename", source_file_edits, file_system_edits)) |
191 | label: "rename".to_string(), | ||
192 | source_file_edits, | ||
193 | file_system_edits, | ||
194 | cursor_position: None, | ||
195 | }) | ||
196 | } | 191 | } |
197 | 192 | ||
198 | fn rename_reference( | 193 | fn rename_reference( |
@@ -211,12 +206,7 @@ fn rename_reference( | |||
211 | return None; | 206 | return None; |
212 | } | 207 | } |
213 | 208 | ||
214 | Some(SourceChange { | 209 | Some(SourceChange::source_edits("rename", edit)) |
215 | label: "rename".to_string(), | ||
216 | source_file_edits: edit, | ||
217 | file_system_edits: Vec::new(), | ||
218 | cursor_position: None, | ||
219 | }) | ||
220 | } | 210 | } |
221 | 211 | ||
222 | #[cfg(test)] | 212 | #[cfg(test)] |
diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs index 424084468..aa9971450 100644 --- a/crates/ra_ide_api/src/typing.rs +++ b/crates/ra_ide_api/src/typing.rs | |||
@@ -112,16 +112,14 @@ pub(crate) fn on_dot_typed(db: &RootDatabase, position: FilePosition) -> Option< | |||
112 | TextRange::from_to(position.offset - current_indent_len, position.offset), | 112 | TextRange::from_to(position.offset - current_indent_len, position.offset), |
113 | target_indent.into(), | 113 | target_indent.into(), |
114 | ); | 114 | ); |
115 | let res = SourceChange { | 115 | |
116 | label: "reindent dot".to_string(), | 116 | let res = SourceChange::source_file_edit_from("reindent dot", position.file_id, edit.finish()) |
117 | source_file_edits: vec![SourceFileEdit { edit: edit.finish(), file_id: position.file_id }], | 117 | .with_cursor(FilePosition { |
118 | file_system_edits: vec![], | ||
119 | cursor_position: Some(FilePosition { | ||
120 | offset: position.offset + target_indent_len - current_indent_len | 118 | offset: position.offset + target_indent_len - current_indent_len |
121 | + TextUnit::of_char('.'), | 119 | + TextUnit::of_char('.'), |
122 | file_id: position.file_id, | 120 | file_id: position.file_id, |
123 | }), | 121 | }); |
124 | }; | 122 | |
125 | Some(res) | 123 | Some(res) |
126 | } | 124 | } |
127 | 125 | ||