Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect excludes in ruff server configuration discovery #11551

Merged
merged 3 commits into from
May 27, 2024

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented May 26, 2024

Summary

Right now, we're discovering configuration files even within (e.g.) virtual environments, because we're recursing without respecting the exclude field on parent configuration.

Closes astral-sh/ruff-vscode#478.

Test Plan

Installed Pandas; verified that I saw no warnings:

Screenshot 2024-05-26 at 8 09 05 PM

@charliermarsh charliermarsh requested a review from dhruvmanila May 26, 2024 23:46
@charliermarsh charliermarsh added bug Something isn't working server Related to the LSP server labels May 26, 2024
continue;
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is loosely drawn from python_files_in_path.

@charliermarsh charliermarsh force-pushed the charlie/extension-excludes branch from a951ab5 to e9cfb77 Compare May 26, 2024 23:47
@charliermarsh charliermarsh marked this pull request as draft May 26, 2024 23:56
Copy link
Contributor

github-actions bot commented May 27, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@@ -80,25 +85,23 @@ impl RuffSettings {

impl RuffSettingsIndex {
pub(super) fn new(root: &Path, editor_settings: &ResolvedEditorSettings) -> Self {
let mut index = BTreeMap::default();
let index = RefCell::new(BTreeMap::new());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need some sort of mechanism here because we have to both immutably borrow index in filter_entry (which has to be a closure) and mutably borrow it in the for loop body.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't see any obvious way to avoid using RefCell without collecting them all in a vector.

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if I understand this change correctly, does it mean that the root cause of the issue is that the server uses a low level API from the linter (check_path) which means the server doesn't benefit from any logic before that?

If that's the case, then I don't think the server benefits from the cache either and I wonder what other logic would be required here. Nevertheless, I don't think that needs to be checked or addressed in this PR.

Comment on lines 127 to 128
.rev()
.find(|(path, _)| directory.starts_with(path))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit

Suggested change
.rev()
.find(|(path, _)| directory.starts_with(path))
.rfind(|(path, _)| directory.starts_with(path))

Comment on lines 129 to 155
{
if let Some(file_name) = directory.file_name() {
let candidate = Candidate::new(&directory);
let basename = Candidate::new(file_name);
if match_candidate_exclusion(
&candidate,
&basename,
&settings.file_resolver.exclude,
) {
tracing::debug!("Ignored path via `exclude`: {}", directory.display());
return false;
} else if match_candidate_exclusion(
&candidate,
&basename,
&settings.file_resolver.extend_exclude,
) {
tracing::debug!(
"Ignored path via `extend-exclude`: {}",
directory.display()
);
return false;
}
}
}

true
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I first assumed that the { starts a new block, and only after removing it realised that it starts the for body.

I think it would be good to extract the WalkDir::new into a variable

@MichaReiser
Copy link
Member

A possible alternative to avoid the RefCell is to use WalkDir::skip_current_dir instead of the filter_entries API. It avoids the need for a closure,

@charliermarsh
Copy link
Member Author

So, if I understand this change correctly, does it mean that the root cause of the issue is that the server uses a low level API from the linter (check_path) which means the server doesn't benefit from any logic before that?

Yes, I believe so.

@charliermarsh
Copy link
Member Author

If either of you want to modify and merge + release this today, feel free -- otherwise I may be able to get to it tonight.

@charliermarsh
Copy link
Member Author

Gonna try and fix-up + merge this now.

@charliermarsh charliermarsh force-pushed the charlie/extension-excludes branch 2 times, most recently from 15e168e to 6b6adfb Compare May 27, 2024 16:53
@charliermarsh
Copy link
Member Author

I removed RefCell in favor of skip_current_dir().

@charliermarsh charliermarsh enabled auto-merge (squash) May 27, 2024 16:53
@charliermarsh charliermarsh force-pushed the charlie/extension-excludes branch from 6b6adfb to 60464d3 Compare May 27, 2024 16:55
@charliermarsh charliermarsh merged commit 34a5063 into main May 27, 2024
15 checks passed
@charliermarsh charliermarsh deleted the charlie/extension-excludes branch May 27, 2024 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Related to the LSP server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extension is showing warnings about configuration issues in pyproject.toml files in a .venv
3 participants