diff options
Diffstat (limited to 'crates/ra_ide/src/lib.rs')
-rw-r--r-- | crates/ra_ide/src/lib.rs | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 83cb498f7..5ac002d82 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -42,9 +42,6 @@ mod inlay_hints; | |||
42 | mod expand_macro; | 42 | mod expand_macro; |
43 | mod ssr; | 43 | mod ssr; |
44 | 44 | ||
45 | #[cfg(test)] | ||
46 | mod test_utils; | ||
47 | |||
48 | use std::sync::Arc; | 45 | use std::sync::Arc; |
49 | 46 | ||
50 | use ra_cfg::CfgOptions; | 47 | use ra_cfg::CfgOptions; |
@@ -87,12 +84,12 @@ pub use ra_db::{ | |||
87 | pub use ra_ide_db::{ | 84 | pub use ra_ide_db::{ |
88 | change::{AnalysisChange, LibraryData}, | 85 | change::{AnalysisChange, LibraryData}, |
89 | line_index::{LineCol, LineIndex}, | 86 | line_index::{LineCol, LineIndex}, |
90 | line_index_utils::translate_offset_with_edit, | ||
91 | search::SearchScope, | 87 | search::SearchScope, |
92 | source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, | 88 | source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, |
93 | symbol_index::Query, | 89 | symbol_index::Query, |
94 | RootDatabase, | 90 | RootDatabase, |
95 | }; | 91 | }; |
92 | pub use ra_text_edit::{Indel, TextEdit}; | ||
96 | 93 | ||
97 | pub type Cancelable<T> = Result<T, Canceled>; | 94 | pub type Cancelable<T> = Result<T, Canceled>; |
98 | 95 | ||
@@ -100,8 +97,22 @@ pub type Cancelable<T> = Result<T, Canceled>; | |||
100 | pub struct Diagnostic { | 97 | pub struct Diagnostic { |
101 | pub message: String, | 98 | pub message: String, |
102 | pub range: TextRange, | 99 | pub range: TextRange, |
103 | pub fix: Option<SourceChange>, | ||
104 | pub severity: Severity, | 100 | pub severity: Severity, |
101 | pub fix: Option<Fix>, | ||
102 | } | ||
103 | |||
104 | #[derive(Debug)] | ||
105 | pub struct Fix { | ||
106 | pub label: String, | ||
107 | pub source_change: SourceChange, | ||
108 | } | ||
109 | |||
110 | impl Fix { | ||
111 | pub fn new(label: impl Into<String>, source_change: SourceChange) -> Self { | ||
112 | let label = label.into(); | ||
113 | assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.')); | ||
114 | Self { label, source_change } | ||
115 | } | ||
105 | } | 116 | } |
106 | 117 | ||
107 | /// Info associated with a text range. | 118 | /// Info associated with a text range. |
@@ -289,14 +300,10 @@ impl Analysis { | |||
289 | 300 | ||
290 | /// Returns an edit to remove all newlines in the range, cleaning up minor | 301 | /// Returns an edit to remove all newlines in the range, cleaning up minor |
291 | /// stuff like trailing commas. | 302 | /// stuff like trailing commas. |
292 | pub fn join_lines(&self, frange: FileRange) -> Cancelable<SourceChange> { | 303 | pub fn join_lines(&self, frange: FileRange) -> Cancelable<TextEdit> { |
293 | self.with_db(|db| { | 304 | self.with_db(|db| { |
294 | let parse = db.parse(frange.file_id); | 305 | let parse = db.parse(frange.file_id); |
295 | let file_edit = SourceFileEdit { | 306 | join_lines::join_lines(&parse.tree(), frange.range) |
296 | file_id: frange.file_id, | ||
297 | edit: join_lines::join_lines(&parse.tree(), frange.range), | ||
298 | }; | ||
299 | SourceChange::source_file_edit("Join lines", file_edit) | ||
300 | }) | 307 | }) |
301 | } | 308 | } |
302 | 309 | ||
@@ -500,7 +507,7 @@ impl Analysis { | |||
500 | ) -> Cancelable<Result<SourceChange, SsrError>> { | 507 | ) -> Cancelable<Result<SourceChange, SsrError>> { |
501 | self.with_db(|db| { | 508 | self.with_db(|db| { |
502 | let edits = ssr::parse_search_replace(query, parse_only, db)?; | 509 | let edits = ssr::parse_search_replace(query, parse_only, db)?; |
503 | Ok(SourceChange::source_file_edits("Structural Search Replace", edits)) | 510 | Ok(SourceChange::source_file_edits(edits)) |
504 | }) | 511 | }) |
505 | } | 512 | } |
506 | 513 | ||