Sanitize language server diagnostics coming from Rust
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
7250974aa6
commit
121b45e249
5 changed files with 59 additions and 13 deletions
|
@ -39,6 +39,10 @@ pub trait ToPointUtf16 {
|
|||
fn to_point_utf16(self) -> PointUtf16;
|
||||
}
|
||||
|
||||
pub trait DiagnosticProcessor: 'static + Send + Sync {
|
||||
fn process_diagnostics(&self, diagnostics: &mut lsp::PublishDiagnosticsParams);
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize)]
|
||||
pub struct LanguageConfig {
|
||||
pub name: String,
|
||||
|
@ -69,6 +73,7 @@ pub struct BracketPair {
|
|||
pub struct Language {
|
||||
pub(crate) config: LanguageConfig,
|
||||
pub(crate) grammar: Option<Arc<Grammar>>,
|
||||
pub(crate) diagnostic_processor: Option<Box<dyn DiagnosticProcessor>>,
|
||||
}
|
||||
|
||||
pub struct Grammar {
|
||||
|
@ -135,6 +140,7 @@ impl Language {
|
|||
highlight_map: Default::default(),
|
||||
})
|
||||
}),
|
||||
diagnostic_processor: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,6 +184,11 @@ impl Language {
|
|||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with_diagnostics_processor(mut self, processor: impl DiagnosticProcessor) -> Self {
|
||||
self.diagnostic_processor = Some(Box::new(processor));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
self.config.name.as_str()
|
||||
}
|
||||
|
@ -225,6 +236,12 @@ impl Language {
|
|||
.and_then(|config| config.disk_based_diagnostics_progress_token.as_ref())
|
||||
}
|
||||
|
||||
pub fn process_diagnostics(&self, diagnostics: &mut lsp::PublishDiagnosticsParams) {
|
||||
if let Some(processor) = self.diagnostic_processor.as_ref() {
|
||||
processor.process_diagnostics(diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn brackets(&self) -> &[BracketPair] {
|
||||
&self.config.brackets
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue