Skip to content

Commit

Permalink
Implement workspace prioritization setting
Browse files Browse the repository at this point in the history
  • Loading branch information
snowsignal committed Apr 25, 2024
1 parent cee38f3 commit a71e3ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
20 changes: 17 additions & 3 deletions crates/ruff_server/src/session/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub(crate) struct ResolvedEditorSettings {
pub(super) ignore: Option<Vec<RuleSelector>>,
pub(super) exclude: Option<Vec<String>>,
pub(super) line_length: Option<LineLength>,
pub(super) prioritize_file_configuration: bool,
}

/// This is a direct representation of the settings schema sent by the client.
Expand All @@ -52,6 +53,7 @@ pub(crate) struct ClientSettings {
code_action: Option<CodeActionOptions>,
exclude: Option<Vec<String>>,
line_length: Option<LineLength>,
prioritize_file_configuration: Option<bool>,
}

/// This is a direct representation of the workspace settings schema,
Expand Down Expand Up @@ -251,6 +253,11 @@ impl ResolvedClientSettings {
Some(settings.exclude.as_ref()?.clone())
}),
line_length: Self::resolve_optional(all_settings, |settings| settings.line_length),
prioritize_file_configuration: Self::resolve_or(
all_settings,
|settings| settings.prioritize_file_configuration,
false,
),
},
}
}
Expand Down Expand Up @@ -383,6 +390,7 @@ mod tests {
),
exclude: None,
line_length: None,
prioritize_file_configuration: None,
},
workspace_settings: [
WorkspaceSettings {
Expand Down Expand Up @@ -429,6 +437,7 @@ mod tests {
),
exclude: None,
line_length: None,
prioritize_file_configuration: None,
},
workspace: Url {
scheme: "file",
Expand Down Expand Up @@ -488,6 +497,7 @@ mod tests {
),
exclude: None,
line_length: None,
prioritize_file_configuration: None,
},
workspace: Url {
scheme: "file",
Expand Down Expand Up @@ -538,7 +548,8 @@ mod tests {
extend_select: None,
ignore: None,
exclude: None,
line_length: None
line_length: None,
prioritize_file_configuration: false,
}
}
);
Expand Down Expand Up @@ -566,7 +577,8 @@ mod tests {
extend_select: None,
ignore: None,
exclude: None,
line_length: None
line_length: None,
prioritize_file_configuration: false,
}
}
);
Expand Down Expand Up @@ -620,6 +632,7 @@ mod tests {
80,
),
),
prioritize_file_configuration: None,
},
),
}
Expand Down Expand Up @@ -648,7 +661,8 @@ mod tests {
extend_select: None,
ignore: Some(vec![RuleSelector::from_str("RUF001").unwrap()]),
exclude: Some(vec!["third_party".into()]),
line_length: Some(LineLength::try_from(80).unwrap())
line_length: Some(LineLength::try_from(80).unwrap()),
prioritize_file_configuration: false,
}
}
);
Expand Down
7 changes: 6 additions & 1 deletion crates/ruff_server/src/session/workspace/ruff_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl<'a> ConfigurationTransformer for EditorConfigurationTransformer<'a> {
ignore,
exclude,
line_length,
prioritize_file_configuration: prioritize_workspace_settings,
} = self.0.clone();

let project_root = self.1;
Expand Down Expand Up @@ -149,6 +150,10 @@ impl<'a> ConfigurationTransformer for EditorConfigurationTransformer<'a> {
..Default::default()
};

editor_configuration.combine(project_configuration)
if prioritize_workspace_settings {
project_configuration.combine(editor_configuration)
} else {
editor_configuration.combine(project_configuration)
}
}
}

0 comments on commit a71e3ed

Please sign in to comment.