|
3 | 3 | use std::collections::HashMap; |
4 | 4 |
|
5 | 5 | use flycheck::{DiagnosticLevel, DiagnosticSpan}; |
| 6 | +use itertools::Itertools; |
6 | 7 | use stdx::format_to; |
7 | 8 | use vfs::{AbsPath, AbsPathBuf}; |
8 | 9 |
|
@@ -134,30 +135,42 @@ fn map_rust_child_diagnostic( |
134 | 135 | } |
135 | 136 |
|
136 | 137 | let mut edit_map: HashMap<lsp_types::Url, Vec<lsp_types::TextEdit>> = HashMap::new(); |
| 138 | + let mut suggested_replacements = Vec::new(); |
137 | 139 | for &span in &spans { |
138 | 140 | if let Some(suggested_replacement) = &span.suggested_replacement { |
| 141 | + suggested_replacements.push(suggested_replacement); |
139 | 142 | let location = location(config, workspace_root, span); |
140 | 143 | let edit = lsp_types::TextEdit::new(location.range, suggested_replacement.clone()); |
141 | 144 | edit_map.entry(location.uri).or_default().push(edit); |
142 | 145 | } |
143 | 146 | } |
144 | 147 |
|
| 148 | + // rustc renders suggestion diagnostics by appending the suggested replacement, so do the same |
| 149 | + // here, otherwise the diagnostic text is missing useful information. |
| 150 | + let mut message = rd.message.clone(); |
| 151 | + if !suggested_replacements.is_empty() { |
| 152 | + message.push_str(": "); |
| 153 | + let suggestions = |
| 154 | + suggested_replacements.iter().map(|suggestion| format!("`{}`", suggestion)).join(", "); |
| 155 | + message.push_str(&suggestions); |
| 156 | + } |
| 157 | + |
145 | 158 | if edit_map.is_empty() { |
146 | 159 | MappedRustChildDiagnostic::SubDiagnostic(SubDiagnostic { |
147 | 160 | related: lsp_types::DiagnosticRelatedInformation { |
148 | 161 | location: location(config, workspace_root, spans[0]), |
149 | | - message: rd.message.clone(), |
| 162 | + message, |
150 | 163 | }, |
151 | 164 | suggested_fix: None, |
152 | 165 | }) |
153 | 166 | } else { |
154 | 167 | MappedRustChildDiagnostic::SubDiagnostic(SubDiagnostic { |
155 | 168 | related: lsp_types::DiagnosticRelatedInformation { |
156 | 169 | location: location(config, workspace_root, spans[0]), |
157 | | - message: rd.message.clone(), |
| 170 | + message: message.clone(), |
158 | 171 | }, |
159 | 172 | suggested_fix: Some(lsp_ext::CodeAction { |
160 | | - title: rd.message.clone(), |
| 173 | + title: message, |
161 | 174 | group: None, |
162 | 175 | kind: Some(lsp_types::CodeActionKind::QUICKFIX), |
163 | 176 | edit: Some(lsp_ext::SnippetWorkspaceEdit { |
|
0 commit comments