Refactor doc.shown_diagnostics to avoid an extra HashSet

Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
pull/2507/head
Philipp Mildenberger 2 years ago
parent 1122928c2a
commit 9639f42766

@ -16,7 +16,7 @@ use serde::de::{self, Deserialize, Deserializer};
use serde::Serialize; use serde::Serialize;
use std::borrow::Cow; use std::borrow::Cow;
use std::cell::Cell; use std::cell::Cell;
use std::collections::{HashMap, HashSet}; use std::collections::HashMap;
use std::fmt::Display; use std::fmt::Display;
use std::future::Future; use std::future::Future;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -1581,13 +1581,16 @@ impl Document {
} }
pub fn shown_diagnostics(&self) -> impl Iterator<Item = &Diagnostic> + DoubleEndedIterator { pub fn shown_diagnostics(&self) -> impl Iterator<Item = &Diagnostic> + DoubleEndedIterator {
let ls_ids: HashSet<_> = self self.diagnostics.iter().filter(|d| {
.language_servers_with_feature(LanguageServerFeature::Diagnostics) self.language_servers()
.map(|ls| ls.id()) .find(|ls| ls.id() == d.language_server_id)
.collect(); .and_then(|ls| {
self.diagnostics let config = self.language_config()?;
.iter() let features = config.language_servers.get(ls.name())?;
.filter(move |d| ls_ids.contains(&d.language_server_id)) Some(features.has_feature(LanguageServerFeature::Diagnostics))
})
== Some(true)
})
} }
pub fn replace_diagnostics( pub fn replace_diagnostics(

Loading…
Cancel
Save