Use Annotation::tags instead of hardcoded rule matching in ruff server (#20565)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Dan Parizher 2025-09-26 03:06:26 -04:00 committed by GitHub
parent 02ebb2ee61
commit 0bae7e613d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 75 additions and 13 deletions

View file

@ -287,7 +287,7 @@ fn to_lsp_diagnostic(
let code = code.to_string();
(
Some(severity(&code)),
tags(&code),
tags(diagnostic),
Some(lsp_types::NumberOrString::String(code)),
)
} else {
@ -338,12 +338,17 @@ fn severity(code: &str) -> lsp_types::DiagnosticSeverity {
}
}
fn tags(code: &str) -> Option<Vec<lsp_types::DiagnosticTag>> {
match code {
// F401: <module> imported but unused
// F841: local variable <name> is assigned to but never used
// RUF059: Unused unpacked variable
"F401" | "F841" | "RUF059" => Some(vec![lsp_types::DiagnosticTag::UNNECESSARY]),
_ => None,
}
fn tags(diagnostic: &Diagnostic) -> Option<Vec<lsp_types::DiagnosticTag>> {
diagnostic.primary_tags().map(|tags| {
tags.iter()
.map(|tag| match tag {
ruff_db::diagnostic::DiagnosticTag::Unnecessary => {
lsp_types::DiagnosticTag::UNNECESSARY
}
ruff_db::diagnostic::DiagnosticTag::Deprecated => {
lsp_types::DiagnosticTag::DEPRECATED
}
})
.collect()
})
}