Skip to content

Commit a5d74bd

Browse files
authored
Fix priority of diagnostic's virtual texts (#1172)
1 parent f315543 commit a5d74bd

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

src/config/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ impl Config {
194194
None => HoverPreviewOption::Auto,
195195
};
196196

197+
let mut diagnostics_display = DiagnosticsDisplay::default();
198+
res.diagnostics_display.into_iter().for_each(|(k, v)| {
199+
diagnostics_display.insert(k, v);
200+
});
201+
197202
Ok(Config {
198203
auto_start: res.auto_start == 1,
199204
server_commands: res.server_commands,
@@ -210,7 +215,7 @@ impl Config {
210215
),
211216
diagnostics_enable: res.diagnostics_enable == 1,
212217
diagnostics_list,
213-
diagnostics_display: res.diagnostics_display,
218+
diagnostics_display,
214219
code_lens_display: res.code_lens_display.unwrap_or_default(),
215220
window_log_message_level: message_type(&res.window_log_message_level)?,
216221
hover_preview,

src/language_server_protocol.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,26 +3033,28 @@ impl LanguageClient {
30333033
viewport: &viewport::Viewport,
30343034
) -> Result<Vec<VirtualText>> {
30353035
let mut virtual_texts = vec![];
3036-
let diagnostics = self.get_state(|state| state.diagnostics.clone())?;
3036+
let diagnostics =
3037+
self.get_state(|state| state.diagnostics.get(filename).cloned().unwrap_or_default())?;
3038+
let diagnostics: Vec<Diagnostic> = diagnostics
3039+
.into_iter()
3040+
.sorted_by(|a, b| Ord::cmp(&b.severity, &a.severity))
3041+
.collect();
30373042
let diagnostics_display = self.get_config(|c| c.diagnostics_display.clone())?;
3038-
let diag_list = diagnostics.get(filename);
3039-
if let Some(diag_list) = diag_list {
3040-
for diag in diag_list {
3041-
if viewport.overlaps(diag.range) {
3042-
let mut explanation = diag.message.clone();
3043-
if let Some(source) = &diag.source {
3044-
explanation = format!("{}: {}\n", source, explanation);
3045-
}
3046-
virtual_texts.push(VirtualText {
3047-
line: diag.range.start.line,
3048-
text: explanation.replace("\n", " "),
3049-
hl_group: diagnostics_display
3050-
.get(&(diag.severity.unwrap_or(DiagnosticSeverity::Hint) as u64))
3051-
.ok_or_else(|| anyhow!("Failed to get display"))?
3052-
.virtual_texthl
3053-
.clone(),
3054-
});
3043+
for diag in diagnostics {
3044+
if viewport.overlaps(diag.range) {
3045+
let mut explanation = diag.message.clone();
3046+
if let Some(source) = &diag.source {
3047+
explanation = format!("{}: {}\n", source, explanation);
30553048
}
3049+
virtual_texts.push(VirtualText {
3050+
line: diag.range.start.line,
3051+
text: explanation.replace("\n", " "),
3052+
hl_group: diagnostics_display
3053+
.get(&(diag.severity.unwrap_or(DiagnosticSeverity::Hint) as u64))
3054+
.ok_or_else(|| anyhow!("Failed to get display"))?
3055+
.virtual_texthl
3056+
.clone(),
3057+
});
30563058
}
30573059
}
30583060

0 commit comments

Comments
 (0)