mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Fix configuration inheritance for configurations specified in the LSP settings (#13285)
This commit is contained in:
parent
b04948fb72
commit
312bd86e48
3 changed files with 17 additions and 10 deletions
|
@ -340,7 +340,7 @@ impl<'a> ConfigurationTransformer for EditorConfigurationTransformer<'a> {
|
||||||
|
|
||||||
// Merge in the editor-specified configuration file, if it exists.
|
// Merge in the editor-specified configuration file, if it exists.
|
||||||
let editor_configuration = if let Some(config_file_path) = configuration {
|
let editor_configuration = if let Some(config_file_path) = configuration {
|
||||||
match open_configuration_file(&config_file_path, project_root) {
|
match open_configuration_file(&config_file_path) {
|
||||||
Ok(config_from_file) => editor_configuration.combine(config_from_file),
|
Ok(config_from_file) => editor_configuration.combine(config_from_file),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
tracing::error!("Unable to find editor-specified configuration file: {err}");
|
tracing::error!("Unable to find editor-specified configuration file: {err}");
|
||||||
|
@ -363,11 +363,18 @@ impl<'a> ConfigurationTransformer for EditorConfigurationTransformer<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_configuration_file(
|
fn open_configuration_file(config_path: &Path) -> crate::Result<Configuration> {
|
||||||
config_path: &Path,
|
ruff_workspace::resolver::resolve_configuration(
|
||||||
project_root: &Path,
|
config_path,
|
||||||
) -> crate::Result<Configuration> {
|
Relativity::Parent,
|
||||||
let options = ruff_workspace::pyproject::load_options(config_path)?;
|
&IdentityTransformer,
|
||||||
|
)
|
||||||
Configuration::from_options(options, Some(config_path), project_root)
|
}
|
||||||
|
|
||||||
|
struct IdentityTransformer;
|
||||||
|
|
||||||
|
impl ConfigurationTransformer for IdentityTransformer {
|
||||||
|
fn transform(&self, config: Configuration) -> Configuration {
|
||||||
|
config
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ pub fn find_user_settings_toml() -> Option<PathBuf> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load `Options` from a `pyproject.toml` or `ruff.toml` file.
|
/// Load `Options` from a `pyproject.toml` or `ruff.toml` file.
|
||||||
pub fn load_options<P: AsRef<Path>>(path: P) -> Result<Options> {
|
pub(super) fn load_options<P: AsRef<Path>>(path: P) -> Result<Options> {
|
||||||
if path.as_ref().ends_with("pyproject.toml") {
|
if path.as_ref().ends_with("pyproject.toml") {
|
||||||
let pyproject = parse_pyproject_toml(&path)?;
|
let pyproject = parse_pyproject_toml(&path)?;
|
||||||
let mut ruff = pyproject
|
let mut ruff = pyproject
|
||||||
|
|
|
@ -263,7 +263,7 @@ pub trait ConfigurationTransformer {
|
||||||
// configuration file extends another in the same path, we'll re-parse the same
|
// configuration file extends another in the same path, we'll re-parse the same
|
||||||
// file at least twice (possibly more than twice, since we'll also parse it when
|
// file at least twice (possibly more than twice, since we'll also parse it when
|
||||||
// resolving the "default" configuration).
|
// resolving the "default" configuration).
|
||||||
fn resolve_configuration(
|
pub fn resolve_configuration(
|
||||||
pyproject: &Path,
|
pyproject: &Path,
|
||||||
relativity: Relativity,
|
relativity: Relativity,
|
||||||
transformer: &dyn ConfigurationTransformer,
|
transformer: &dyn ConfigurationTransformer,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue