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

Use fallback settings when indexing the project #12362

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions crates/ruff_server/src/session/index/ruff_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl RuffSettings {
impl RuffSettingsIndex {
pub(super) fn new(root: &Path, editor_settings: &ResolvedEditorSettings) -> Self {
let mut index = BTreeMap::default();
let mut respect_gitignore = true;
let mut respect_gitignore = None;

// Add any settings from above the workspace root.
for directory in root.ancestors() {
Expand All @@ -113,7 +113,8 @@ impl RuffSettingsIndex {
continue;
};

respect_gitignore = settings.file_resolver.respect_gitignore;
respect_gitignore = Some(settings.file_resolver.respect_gitignore);

index.insert(
directory.to_path_buf(),
Arc::new(RuffSettings {
Expand All @@ -127,9 +128,13 @@ impl RuffSettingsIndex {
}
}

let fallback = Arc::new(RuffSettings::fallback(editor_settings, root));

// Add any settings within the workspace itself
let mut builder = WalkBuilder::new(root);
builder.standard_filters(respect_gitignore);
builder.standard_filters(
respect_gitignore.unwrap_or_else(|| fallback.file_resolver().respect_gitignore),
);
builder.hidden(false);
builder.threads(
std::thread::available_parallelism()
Expand Down Expand Up @@ -157,26 +162,27 @@ impl RuffSettingsIndex {

// If the directory is excluded from the workspace, skip it.
if let Some(file_name) = directory.file_name() {
if let Some((_, settings)) = index
let settings = index
.read()
.unwrap()
.range(..directory.clone())
.rfind(|(path, _)| directory.starts_with(path))
{
if match_exclusion(&directory, file_name, &settings.file_resolver.exclude) {
tracing::debug!("Ignored path via `exclude`: {}", directory.display());
return WalkState::Continue;
} else if match_exclusion(
&directory,
file_name,
&settings.file_resolver.extend_exclude,
) {
tracing::debug!(
"Ignored path via `extend-exclude`: {}",
directory.display()
);
return WalkState::Continue;
}
.map(|(_, settings)| settings.clone())
Copy link
Member

Choose a reason for hiding this comment

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

Are these clones necessary?

Copy link
Member

Choose a reason for hiding this comment

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

I think these are all Arc<RuffSettings> so this should be cheap.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, these are all Arcs

Copy link
Member Author

Choose a reason for hiding this comment

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

It otherwise throws "rustc: temporary value dropped while borrowed" if I use a reference

                    let settings = index
                        .read()
                        .unwrap()
                        .range(..directory.clone())
                        .rfind(|(path, _)| directory.starts_with(path))
                        .map(|(_, settings)| settings)
                        .unwrap_or(&fallback);

.unwrap_or_else(|| fallback.clone());

if match_exclusion(&directory, file_name, &settings.file_resolver.exclude) {
tracing::debug!("Ignored path via `exclude`: {}", directory.display());
return WalkState::Skip;
} else if match_exclusion(
&directory,
file_name,
&settings.file_resolver.extend_exclude,
) {
tracing::debug!(
"Ignored path via `extend-exclude`: {}",
directory.display()
);
return WalkState::Skip;
}
}

Expand All @@ -203,8 +209,6 @@ impl RuffSettingsIndex {
})
});

let fallback = Arc::new(RuffSettings::fallback(editor_settings, root));

Self {
index: index.into_inner().unwrap(),
fallback,
Expand Down
Loading