Skip to content

Commit

Permalink
fix diagnostic sign issues (#769)
Browse files Browse the repository at this point in the history
* fix diagnostic sign issues

* mark all existing signs as obsolete
  • Loading branch information
richardtsai authored and autozimu committed Mar 14, 2019
1 parent 1459d24 commit 467747b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2018"

[dependencies]
failure = "0"
itertools = "0.8"
log = "0.4"
log4rs = "0"
structopt = "0"
Expand Down
38 changes: 24 additions & 14 deletions src/language_server_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::lsp::request::Request;
use crate::rpcclient::RpcClient;
use crate::sign::Sign;
use failure::err_msg;
use itertools::Itertools;
use notify::Watcher;
use std::sync::mpsc;
use vim::try_get;
Expand Down Expand Up @@ -2226,31 +2227,38 @@ impl LanguageClient {
let bufnr = self.vim()?.get_bufnr(&filename, params)?;
let viewport = self.vim()?.get_viewport(params)?;

// use the most severe diagnostic of each line as the sign
let signs_next: Vec<_> = self.update(|state| {
let limit = if let Some(n) = state.diagnosticsSignsMax {
n as usize
} else {
usize::max_value()
};
Ok(state
.diagnostics
.entry(filename.clone())
.or_default()
.iter()
.filter_map(|diag| {
if viewport.overlaps(diag.range) {
let name = format!(
"LanguageClient{:?}",
diag.severity.unwrap_or(DiagnosticSeverity::Hint)
);
Some(Sign::new(diag.range.start.line, name))
} else {
None
}
.filter(|diag| viewport.overlaps(diag.range))
.map(|diag| {
(
diag.range.start.line,
diag.severity.unwrap_or(DiagnosticSeverity::Hint),
)
})
.group_by(|(line, _)| *line)
.into_iter()
.filter_map(|(_, group)| group.min_by_key(|(_, severity)| *severity))
.take(limit)
.map(|(line, severity)| Sign::new(line, format!("LanguageClient{:?}", severity)))
.collect())
})?;
let signs_prev: Vec<_> = self.update(|state| {
Ok(state
.signs
.entry(filename.clone())
.or_default()
.range(viewport.start..viewport.end)
.iter()
.map(|(_, sign)| sign.clone())
.collect())
})?;
Expand Down Expand Up @@ -2280,12 +2288,14 @@ impl LanguageClient {
.set_signs(&filename, &signs_to_add, &signs_to_delete)?;
self.update(|state| {
let signs = state.signs.entry(filename.clone()).or_default();
for sign in signs_to_add {
signs.insert(sign.line, sign);
}
// signs might be deleted AND added in the same line to change severity,
// so deletions must be before additions
for sign in signs_to_delete {
signs.remove(&sign.line);
}
for sign in signs_to_add {
signs.insert(sign.line, sign);
}
Ok(())
})?;

Expand Down

0 comments on commit 467747b

Please sign in to comment.