Skip to content

Commit

Permalink
Conside include, extend-include for the native server
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Jul 9, 2024
1 parent bf3d903 commit 9041186
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/ruff_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ ruff_workspace = { workspace = true }

anyhow = { workspace = true }
crossbeam = { workspace = true }
globset = { workspace = true }
jod-thread = { workspace = true }
lsp-server = { workspace = true }
lsp-types = { workspace = true }
Expand Down
14 changes: 14 additions & 0 deletions crates/ruff_server/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ pub(crate) fn check(
return DiagnosticsMap::default();
}

if file_resolver_settings.include.is_match(document_path) {
tracing::debug!("Included path via `include`: {:?}", document_path.display());
} else if file_resolver_settings
.extend_include
.is_match(document_path)
{
tracing::debug!(
"Included path via `extend-include`: {:?}",
document_path.display()
);
} else {
return DiagnosticsMap::default();
}

detect_package_root(
document_path
.parent()
Expand Down
11 changes: 11 additions & 0 deletions crates/ruff_server/src/server/api/requests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ fn format_text_document(
tracing::debug!("Ignored path via `{}`: {}", exclusion, file_path.display());
return Ok(None);
}

if file_resolver_settings.include.is_match(&file_path) {
tracing::debug!("Included path via `include`: {:?}", file_path.display());
} else if file_resolver_settings.extend_include.is_match(&file_path) {
tracing::debug!(
"Included path via `extend-include`: {:?}",
file_path.display()
);
} else {
return Ok(None);
}
}

let source = text_document.contents();
Expand Down
18 changes: 6 additions & 12 deletions crates/ruff_server/src/session/index/ruff_settings.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use globset::Candidate;
use ruff_linter::{
display_settings, fs::normalize_path_to, settings::types::FilePattern,
settings::types::PreviewMode,
};
use ruff_workspace::resolver::match_candidate_exclusion;
use ruff_workspace::resolver::match_exclusion;
use ruff_workspace::{
configuration::{Configuration, FormatConfiguration, LintConfiguration, RuleSelection},
pyproject::{find_user_settings_toml, settings_toml},
Expand Down Expand Up @@ -41,6 +40,7 @@ impl std::fmt::Display for RuffSettings {
display_settings! {
formatter = f,
fields = [
self.file_resolver,
self.linter,
self.formatter
]
Expand Down Expand Up @@ -146,20 +146,14 @@ impl RuffSettingsIndex {
.range(..directory.clone())
.rfind(|(path, _)| directory.starts_with(path))
{
let candidate = Candidate::new(&directory);
let basename = Candidate::new(file_name);
if match_candidate_exclusion(
&candidate,
&basename,
&settings.file_resolver.exclude,
) {
if match_exclusion(&directory, file_name, &settings.file_resolver.exclude) {
tracing::debug!("Ignored path via `exclude`: {}", directory.display());

walker.skip_current_dir();
continue;
} else if match_candidate_exclusion(
&candidate,
&basename,
} else if match_exclusion(
&directory,
file_name,
&settings.file_resolver.extend_exclude,
) {
tracing::debug!(
Expand Down

0 comments on commit 9041186

Please sign in to comment.