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:
Jane Lewis 2024-03-28 04:14:17 -07:00 committed by GitHub
parent cce25ec116
commit 3f7d666e8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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,
}
}