Skip to content

Commit 61fc39b

Browse files
committed
Avoid indexing the workspace for single-file support
1 parent 8dd2a31 commit 61fc39b

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

crates/ruff_server/src/server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ impl Workspace {
551551
}
552552

553553
/// Set the client settings for this workspace.
554+
#[must_use]
554555
pub fn with_settings(mut self, settings: ClientSettings) -> Self {
555556
self.settings = Some(settings);
556557
self

crates/ruff_server/src/session/index.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ impl Index {
286286
settings.ruff_settings = ruff_settings::RuffSettingsIndex::new(
287287
root,
288288
settings.client_settings.editor_settings(),
289+
false,
289290
);
290291
}
291292
}
@@ -422,6 +423,7 @@ impl WorkspaceSettingsIndex {
422423
let workspace_settings_index = ruff_settings::RuffSettingsIndex::new(
423424
&workspace_path,
424425
client_settings.editor_settings(),
426+
workspace.is_default(),
425427
);
426428

427429
self.insert(

crates/ruff_server/src/session/index/ruff_settings.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,19 @@ impl RuffSettings {
100100
}
101101

102102
impl RuffSettingsIndex {
103-
pub(super) fn new(root: &Path, editor_settings: &ResolvedEditorSettings) -> Self {
103+
pub(super) fn new(
104+
root: &Path,
105+
editor_settings: &ResolvedEditorSettings,
106+
is_default_workspace: bool,
107+
) -> Self {
104108
let mut has_error = false;
105109
let mut index = BTreeMap::default();
106110
let mut respect_gitignore = None;
111+
let should_skip_workspace = usize::from(!is_default_workspace);
107112

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

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

165+
if is_default_workspace {
166+
if has_error {
167+
let root = root.display();
168+
show_err_msg!(
169+
"Error while resolving settings from workspace {root}. \
170+
Please refer to the logs for more details.",
171+
);
172+
}
173+
174+
return RuffSettingsIndex { index, fallback };
175+
}
176+
159177
// Add any settings within the workspace itself
160178
let mut builder = WalkBuilder::new(root);
161179
builder.standard_filters(
@@ -266,7 +284,7 @@ impl RuffSettingsIndex {
266284
);
267285
}
268286

269-
Self {
287+
RuffSettingsIndex {
270288
index: index.into_inner().unwrap(),
271289
fallback,
272290
}

0 commit comments

Comments
 (0)