mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00
Add server config to filter out syntax error diagnostics (#12059)
## Summary Follow-up from #11901 This PR adds a new server setting to show / hide syntax errors. ## Test Plan ### VS Code Using https://github.com/astral-sh/ruff-vscode/pull/504 with the following config: ```json { "ruff.nativeServer": true, "ruff.path": ["/Users/dhruv/work/astral/ruff/target/debug/ruff"], "ruff.showSyntaxErrors": true } ``` First, set `ruff.showSyntaxErrors` to `true`: <img width="1177" alt="Screenshot 2024-06-27 at 08 34 58" src="5d77547a
-a908-4a00-8714-7c00784e8679"> And then set it to `false`: <img width="1185" alt="Screenshot 2024-06-27 at 08 35 19" src="9720f089
-f10c-420b-a2c1-2bbb2245be35"> ### Neovim Using the following Ruff server config: ```lua require('lspconfig').ruff.setup { init_options = { settings = { showSyntaxErrors = false, }, }, } ``` First, set `showSyntaxErrors` to `true`: <img width="1279" alt="Screenshot 2024-06-27 at 08 28 03" src="e694e231
-91ba-47f8-8e8a-ad2e82b85a45"> And then set it to `false`: <img width="1284" alt="Screenshot 2024-06-27 at 08 28 20" src="25b86a57
-02b1-44f7-9f65-cf5fdde93b0c">
This commit is contained in:
parent
72b6c26101
commit
22cebdf29b
3 changed files with 50 additions and 12 deletions
|
@ -60,7 +60,11 @@ pub(crate) struct DiagnosticFix {
|
|||
/// A series of diagnostics across a single text document or an arbitrary number of notebook cells.
|
||||
pub(crate) type DiagnosticsMap = FxHashMap<lsp_types::Url, Vec<lsp_types::Diagnostic>>;
|
||||
|
||||
pub(crate) fn check(query: &DocumentQuery, encoding: PositionEncoding) -> DiagnosticsMap {
|
||||
pub(crate) fn check(
|
||||
query: &DocumentQuery,
|
||||
encoding: PositionEncoding,
|
||||
show_syntax_errors: bool,
|
||||
) -> DiagnosticsMap {
|
||||
let source_kind = query.make_source_kind();
|
||||
let file_resolver_settings = query.settings().file_resolver();
|
||||
let linter_settings = query.settings().linter();
|
||||
|
@ -156,10 +160,18 @@ pub(crate) fn check(query: &DocumentQuery, encoding: PositionEncoding) -> Diagno
|
|||
.zip(noqa_edits)
|
||||
.map(|(diagnostic, noqa_edit)| {
|
||||
to_lsp_diagnostic(diagnostic, &noqa_edit, &source_kind, &index, encoding)
|
||||
})
|
||||
.chain(parsed.errors().iter().map(|parse_error| {
|
||||
parse_error_to_lsp_diagnostic(parse_error, &source_kind, &index, encoding)
|
||||
}));
|
||||
});
|
||||
|
||||
let lsp_diagnostics = lsp_diagnostics.chain(
|
||||
show_syntax_errors
|
||||
.then(|| {
|
||||
parsed.errors().iter().map(|parse_error| {
|
||||
parse_error_to_lsp_diagnostic(parse_error, &source_kind, &index, encoding)
|
||||
})
|
||||
})
|
||||
.into_iter()
|
||||
.flatten(),
|
||||
);
|
||||
|
||||
if let Some(notebook) = query.as_notebook() {
|
||||
for (index, diagnostic) in lsp_diagnostics {
|
||||
|
@ -173,12 +185,10 @@ pub(crate) fn check(query: &DocumentQuery, encoding: PositionEncoding) -> Diagno
|
|||
.push(diagnostic);
|
||||
}
|
||||
} else {
|
||||
for (_, diagnostic) in lsp_diagnostics {
|
||||
diagnostics_map
|
||||
.entry(query.make_key().into_url())
|
||||
.or_default()
|
||||
.push(diagnostic);
|
||||
}
|
||||
diagnostics_map
|
||||
.entry(query.make_key().into_url())
|
||||
.or_default()
|
||||
.extend(lsp_diagnostics.map(|(_, diagnostic)| diagnostic));
|
||||
}
|
||||
|
||||
diagnostics_map
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue