mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
ruff server
now highlights most issues as warnings (#10643)
## Summary Fixes #10588. Most diagnostics from `ruff server` now appear as a much less alarming warning instead of an error. Three diagnostics still appear as errors: `F821` (`undefined name <name>`), `E902` (`IOError`) and `E999` (`SyntaxError`). ## Test Plan With an extension using the path to a locally-built executable, open a file with multiple highlighted problems. Toggle the `Experimental Server` setting on and off. The highlights should stay as warnings. Then, modify the file to have a syntactically incorrect element. The start of the invalid syntax should now have a red highlight.
This commit is contained in:
parent
cce25ec116
commit
3f7d666e8b
1 changed files with 15 additions and 4 deletions
|
@ -100,12 +100,13 @@ fn to_lsp_diagnostic(
|
|||
})
|
||||
.flatten()
|
||||
});
|
||||
|
||||
let code = rule.noqa_code().to_string();
|
||||
|
||||
lsp_types::Diagnostic {
|
||||
range: range.to_range(document.contents(), document.index(), encoding),
|
||||
severity: Some(lsp_types::DiagnosticSeverity::ERROR),
|
||||
code: Some(lsp_types::NumberOrString::String(
|
||||
rule.noqa_code().to_string(),
|
||||
)),
|
||||
severity: Some(severity(&code)),
|
||||
code: Some(lsp_types::NumberOrString::String(code)),
|
||||
code_description: rule.url().and_then(|url| {
|
||||
Some(lsp_types::CodeDescription {
|
||||
href: lsp_types::Url::parse(&url).ok()?,
|
||||
|
@ -118,3 +119,13 @@ fn to_lsp_diagnostic(
|
|||
data,
|
||||
}
|
||||
}
|
||||
|
||||
fn severity(code: &str) -> lsp_types::DiagnosticSeverity {
|
||||
match code {
|
||||
// F821: undefined name <name>
|
||||
// E902: IOError
|
||||
// E999: SyntaxError
|
||||
"F821" | "E902" | "E999" => lsp_types::DiagnosticSeverity::ERROR,
|
||||
_ => lsp_types::DiagnosticSeverity::WARNING,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue