Skip to content

Commit

Permalink
Fix non-highlighted diagnostics in workspace diagnostics picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp-M committed Dec 18, 2023
1 parent 83d85cb commit 33e4af1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ impl Application {

// Clear any diagnostics for documents with this server open.
for doc in self.editor.documents_mut() {
doc.clear_diagnostics(server_id);
doc.clear_diagnostics(Some(server_id));
}

// Remove the language server from the registry.
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ fn lsp_stop(

for doc in cx.editor.documents_mut() {
if let Some(client) = doc.remove_language_server_by_name(ls_name) {
doc.clear_diagnostics(client.id());
doc.clear_diagnostics(Some(client.id()));
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,7 @@ impl<T: Item + 'static> Picker<T> {
CachedPreview::LargeFile
}
_ => Document::open(path, None, None, editor.config.clone())
.map(|mut doc| {
let diagnostics = editor.doc_diagnostics(&doc, |_, _| true);
doc.replace_diagnostics(diagnostics, None);
CachedPreview::Document(Box::new(doc))
})
.map(|doc| CachedPreview::Document(Box::new(doc)))
.unwrap_or(CachedPreview::NotFound),
},
)
Expand Down Expand Up @@ -492,7 +488,11 @@ impl<T: Item + 'static> Picker<T> {
let doc = match current_file {
PathOrId::Id(doc_id) => doc_mut!(editor, &doc_id),
PathOrId::Path(path) => match picker.preview_cache.get_mut(&path) {
Some(CachedPreview::Document(ref mut doc)) => doc,
Some(CachedPreview::Document(ref mut doc)) => {
let diagnostics = editor.doc_diagnostics(doc, |_, _| true);
doc.replace_diagnostics(diagnostics, None);
doc
}
_ => return,
},
};
Expand Down
15 changes: 7 additions & 8 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1781,20 +1781,19 @@ impl Document {
diagnostics: impl Iterator<Item = Diagnostic>,
language_server_id: Option<usize>,
) {
if let Some(id) = language_server_id {
self.clear_diagnostics(id);
} else {
self.diagnostics.clear();
}
self.clear_diagnostics(language_server_id);

self.diagnostics.extend(diagnostics);
self.diagnostics
.sort_by_key(|diagnostic| (diagnostic.range.start, diagnostic.severity));
}

pub fn clear_diagnostics(&mut self, language_server_id: usize) {
self.diagnostics
.retain(|d| d.language_server_id != language_server_id);
pub fn clear_diagnostics(&mut self, language_server_id: Option<usize>) {
if let Some(id) = language_server_id {
self.diagnostics.retain(|d| d.language_server_id != id);
} else {
self.diagnostics.clear();
}
}

/// Get the document's auto pairs. If the document has a recognized
Expand Down

0 comments on commit 33e4af1

Please sign in to comment.