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
|
@ -1,4 +1,6 @@
|
|||
pub use language::*;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use rust_embed::RustEmbed;
|
||||
use std::borrow::Cow;
|
||||
use std::{str, sync::Arc};
|
||||
|
@ -7,6 +9,30 @@ use std::{str, sync::Arc};
|
|||
#[folder = "languages"]
|
||||
struct LanguageDir;
|
||||
|
||||
struct RustDiagnosticProcessor;
|
||||
|
||||
impl DiagnosticProcessor for RustDiagnosticProcessor {
|
||||
fn process_diagnostics(&self, params: &mut lsp::PublishDiagnosticsParams) {
|
||||
lazy_static! {
|
||||
static ref REGEX: Regex = Regex::new("(?m)`([^`]+)\n`").unwrap();
|
||||
}
|
||||
|
||||
for diagnostic in &mut params.diagnostics {
|
||||
for message in diagnostic
|
||||
.related_information
|
||||
.iter_mut()
|
||||
.flatten()
|
||||
.map(|info| &mut info.message)
|
||||
.chain([&mut diagnostic.message])
|
||||
{
|
||||
if let Cow::Owned(sanitized) = REGEX.replace_all(message, "`$1`") {
|
||||
*message = sanitized;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build_language_registry() -> LanguageRegistry {
|
||||
let mut languages = LanguageRegistry::default();
|
||||
languages.add(Arc::new(rust()));
|
||||
|
@ -26,6 +52,7 @@ fn rust() -> Language {
|
|||
.unwrap()
|
||||
.with_outline_query(load_query("rust/outline.scm").as_ref())
|
||||
.unwrap()
|
||||
.with_diagnostics_processor(RustDiagnosticProcessor)
|
||||
}
|
||||
|
||||
fn markdown() -> Language {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue