Respect file exclusions in ruff server (#11590)

## Summary

Closes https://github.com/astral-sh/ruff/issues/11587.

## Test Plan

- Added a lint error to `test_server.py` in `vscode-ruff`.
- Validated that, prior to this change, diagnostics appeared in the
file.
- Validated that, with this change, no diagnostics were shown.
- Validated that, with this change, no diagnostics were fixed on-save.
This commit is contained in:
Charlie Marsh 2024-05-28 22:58:36 -04:00 committed by GitHub
parent 531ae5227c
commit 204c59e353
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 235 additions and 43 deletions

View file

@ -16,6 +16,8 @@ use ruff_python_index::Indexer;
use ruff_python_parser::AsMode;
use ruff_source_file::{LineIndex, Locator};
use ruff_text_size::{Ranged, TextRange};
use ruff_workspace::resolver::match_any_exclusion;
use ruff_workspace::FileResolverSettings;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
@ -60,12 +62,29 @@ pub(crate) type Diagnostics = FxHashMap<lsp_types::Url, Vec<lsp_types::Diagnosti
pub(crate) fn check(
query: &DocumentQuery,
file_resolver_settings: &FileResolverSettings,
linter_settings: &LinterSettings,
encoding: PositionEncoding,
) -> Diagnostics {
let document_path = query.file_path();
let source_kind = query.make_source_kind();
// If the document is excluded, return an empty list of diagnostics.
if let Some(exclusion) = match_any_exclusion(
document_path,
&file_resolver_settings.exclude,
&file_resolver_settings.extend_exclude,
Some(&linter_settings.exclude),
None,
) {
tracing::debug!(
"Ignored path via `{}`: {}",
exclusion,
document_path.display()
);
return Diagnostics::default();
}
let package = detect_package_root(
document_path
.parent()