Skip to content

Commit

Permalink
Avoid indexing the workspace for single-file support
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Oct 16, 2024
1 parent 8dd2a31 commit 61fc39b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/ruff_server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ impl Workspace {
}

/// Set the client settings for this workspace.
#[must_use]
pub fn with_settings(mut self, settings: ClientSettings) -> Self {
self.settings = Some(settings);
self
Expand Down
2 changes: 2 additions & 0 deletions crates/ruff_server/src/session/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ impl Index {
settings.ruff_settings = ruff_settings::RuffSettingsIndex::new(
root,
settings.client_settings.editor_settings(),
false,
);
}
}
Expand Down Expand Up @@ -422,6 +423,7 @@ impl WorkspaceSettingsIndex {
let workspace_settings_index = ruff_settings::RuffSettingsIndex::new(
&workspace_path,
client_settings.editor_settings(),
workspace.is_default(),
);

self.insert(
Expand Down
26 changes: 22 additions & 4 deletions crates/ruff_server/src/session/index/ruff_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,19 @@ impl RuffSettings {
}

impl RuffSettingsIndex {
pub(super) fn new(root: &Path, editor_settings: &ResolvedEditorSettings) -> Self {
pub(super) fn new(
root: &Path,
editor_settings: &ResolvedEditorSettings,
is_default_workspace: bool,
) -> Self {
let mut has_error = false;
let mut index = BTreeMap::default();
let mut respect_gitignore = None;
let should_skip_workspace = usize::from(!is_default_workspace);

// Add any settings from above the workspace root, excluding the workspace root itself.
for directory in root.ancestors().skip(1) {
// Add any settings from above the workspace root. The ones from the workspace root will be
// added only if it's not the default workspace.
for directory in root.ancestors().skip(should_skip_workspace) {
match settings_toml(directory) {
Ok(Some(pyproject)) => {
match ruff_workspace::resolver::resolve_root_settings(
Expand Down Expand Up @@ -156,6 +162,18 @@ impl RuffSettingsIndex {

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

if is_default_workspace {
if has_error {
let root = root.display();
show_err_msg!(
"Error while resolving settings from workspace {root}. \
Please refer to the logs for more details.",
);
}

return RuffSettingsIndex { index, fallback };
}

// Add any settings within the workspace itself
let mut builder = WalkBuilder::new(root);
builder.standard_filters(
Expand Down Expand Up @@ -266,7 +284,7 @@ impl RuffSettingsIndex {
);
}

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

0 comments on commit 61fc39b

Please sign in to comment.