mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:21 +00:00
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:
parent
02ebb2ee61
commit
0bae7e613d
7 changed files with 75 additions and 13 deletions
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue