diff options
Diffstat (limited to 'crates/ra_cargo_watch/src/conv.rs')
-rw-r--r-- | crates/ra_cargo_watch/src/conv.rs | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/crates/ra_cargo_watch/src/conv.rs b/crates/ra_cargo_watch/src/conv.rs index 0246adfb5..a3f05bede 100644 --- a/crates/ra_cargo_watch/src/conv.rs +++ b/crates/ra_cargo_watch/src/conv.rs | |||
@@ -8,6 +8,7 @@ use lsp_types::{ | |||
8 | Location, NumberOrString, Position, Range, TextEdit, Url, WorkspaceEdit, | 8 | Location, NumberOrString, Position, Range, TextEdit, Url, WorkspaceEdit, |
9 | }; | 9 | }; |
10 | use std::{ | 10 | use std::{ |
11 | collections::HashMap, | ||
11 | fmt::Write, | 12 | fmt::Write, |
12 | path::{Component, Path, PathBuf, Prefix}, | 13 | path::{Component, Path, PathBuf, Prefix}, |
13 | str::FromStr, | 14 | str::FromStr, |
@@ -126,44 +127,34 @@ fn map_rust_child_diagnostic( | |||
126 | rd: &RustDiagnostic, | 127 | rd: &RustDiagnostic, |
127 | workspace_root: &PathBuf, | 128 | workspace_root: &PathBuf, |
128 | ) -> MappedRustChildDiagnostic { | 129 | ) -> MappedRustChildDiagnostic { |
129 | let span: &DiagnosticSpan = match rd.spans.iter().find(|s| s.is_primary) { | 130 | let spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect(); |
130 | Some(span) => span, | 131 | if spans.is_empty() { |
131 | None => { | 132 | // `rustc` uses these spanless children as a way to print multi-line |
132 | // `rustc` uses these spanless children as a way to print multi-line | 133 | // messages |
133 | // messages | 134 | return MappedRustChildDiagnostic::MessageLine(rd.message.clone()); |
134 | return MappedRustChildDiagnostic::MessageLine(rd.message.clone()); | 135 | } |
135 | } | ||
136 | }; | ||
137 | |||
138 | // If we have a primary span use its location, otherwise use the parent | ||
139 | let location = map_span_to_location(&span, workspace_root); | ||
140 | |||
141 | if let Some(suggested_replacement) = &span.suggested_replacement { | ||
142 | // Include our replacement in the title unless it's empty | ||
143 | let title = if !suggested_replacement.is_empty() { | ||
144 | format!("{}: '{}'", rd.message, suggested_replacement) | ||
145 | } else { | ||
146 | rd.message.clone() | ||
147 | }; | ||
148 | 136 | ||
149 | let edit = { | 137 | let mut edit_map: HashMap<Url, Vec<TextEdit>> = HashMap::new(); |
150 | let edits = vec![TextEdit::new(location.range, suggested_replacement.clone())]; | 138 | for &span in &spans { |
151 | let mut edit_map = std::collections::HashMap::new(); | 139 | if let Some(suggested_replacement) = &span.suggested_replacement { |
152 | edit_map.insert(location.uri, edits); | 140 | let location = map_span_to_location(span, workspace_root); |
153 | WorkspaceEdit::new(edit_map) | 141 | let edit = TextEdit::new(location.range, suggested_replacement.clone()); |
154 | }; | 142 | edit_map.entry(location.uri).or_default().push(edit); |
143 | } | ||
144 | } | ||
155 | 145 | ||
146 | if !edit_map.is_empty() { | ||
156 | MappedRustChildDiagnostic::SuggestedFix(CodeAction { | 147 | MappedRustChildDiagnostic::SuggestedFix(CodeAction { |
157 | title, | 148 | title: rd.message.clone(), |
158 | kind: Some("quickfix".to_string()), | 149 | kind: Some("quickfix".to_string()), |
159 | diagnostics: None, | 150 | diagnostics: None, |
160 | edit: Some(edit), | 151 | edit: Some(WorkspaceEdit::new(edit_map)), |
161 | command: None, | 152 | command: None, |
162 | is_preferred: None, | 153 | is_preferred: None, |
163 | }) | 154 | }) |
164 | } else { | 155 | } else { |
165 | MappedRustChildDiagnostic::Related(DiagnosticRelatedInformation { | 156 | MappedRustChildDiagnostic::Related(DiagnosticRelatedInformation { |
166 | location, | 157 | location: map_span_to_location(spans[0], workspace_root), |
167 | message: rd.message.clone(), | 158 | message: rd.message.clone(), |
168 | }) | 159 | }) |
169 | } | 160 | } |