mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:45:24 +00:00
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:
parent
531ae5227c
commit
204c59e353
11 changed files with 235 additions and 43 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue