diff options
Diffstat (limited to 'crates/ra_ide/src/lib.rs')
-rw-r--r-- | crates/ra_ide/src/lib.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 97ff67ee8..d983cd910 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -97,8 +97,22 @@ pub type Cancelable<T> = Result<T, Canceled>; | |||
97 | pub struct Diagnostic { | 97 | pub struct Diagnostic { |
98 | pub message: String, | 98 | pub message: String, |
99 | pub range: TextRange, | 99 | pub range: TextRange, |
100 | pub fix: Option<SourceChange>, | ||
101 | 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 | } | ||
102 | } | 116 | } |
103 | 117 | ||
104 | /// Info associated with a text range. | 118 | /// Info associated with a text range. |
@@ -295,7 +309,8 @@ impl Analysis { | |||
295 | 309 | ||
296 | /// Returns an edit which should be applied when opening a new line, fixing | 310 | /// Returns an edit which should be applied when opening a new line, fixing |
297 | /// up minor stuff like continuing the comment. | 311 | /// up minor stuff like continuing the comment. |
298 | pub fn on_enter(&self, position: FilePosition) -> Cancelable<Option<SourceChange>> { | 312 | /// The edit will be a snippet (with `$0`). |
313 | pub fn on_enter(&self, position: FilePosition) -> Cancelable<Option<TextEdit>> { | ||
299 | self.with_db(|db| typing::on_enter(&db, position)) | 314 | self.with_db(|db| typing::on_enter(&db, position)) |
300 | } | 315 | } |
301 | 316 | ||
@@ -493,7 +508,7 @@ impl Analysis { | |||
493 | ) -> Cancelable<Result<SourceChange, SsrError>> { | 508 | ) -> Cancelable<Result<SourceChange, SsrError>> { |
494 | self.with_db(|db| { | 509 | self.with_db(|db| { |
495 | let edits = ssr::parse_search_replace(query, parse_only, db)?; | 510 | let edits = ssr::parse_search_replace(query, parse_only, db)?; |
496 | Ok(SourceChange::source_file_edits("Structural Search Replace", edits)) | 511 | Ok(SourceChange::source_file_edits(edits)) |
497 | }) | 512 | }) |
498 | } | 513 | } |
499 | 514 | ||