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 22, 2024
1 parent a255be7 commit 86ff807
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions crates/ruff_server/src/session/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub(crate) struct ResolvedEditorSettings {
ignore: Option<Vec<RuleSelector>>,
exclude: Option<Vec<String>>,
line_length: Option<LineLength>,
prioritize_file_configuration: bool,
}

/// This is a direct representation of the settings schema sent by the client.
Expand All @@ -60,6 +61,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 @@ -259,6 +261,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 @@ -324,6 +331,7 @@ impl ResolvedEditorSettings {
ignore,
exclude,
line_length,
prioritize_file_configuration: prioritize_workspace_settings,
} = self.clone();

let editor_configuration = Configuration {
Expand Down Expand Up @@ -354,7 +362,11 @@ impl ResolvedEditorSettings {
..Default::default()
};

let configuration = editor_configuration.combine(project_configuration);
let configuration = if prioritize_workspace_settings {
project_configuration.combine(editor_configuration)
} else {
editor_configuration.combine(project_configuration)
};

configuration.into_settings(project_root)
}
Expand Down Expand Up @@ -596,7 +608,8 @@ mod tests {
extend_select: None,
ignore: None,
exclude: None,
line_length: None
line_length: None,
prioritize_file_configuration: false,
}
}
);
Expand Down Expand Up @@ -624,7 +637,8 @@ mod tests {
extend_select: None,
ignore: None,
exclude: None,
line_length: None
line_length: None,
prioritize_file_configuration: false,
}
}
);
Expand Down Expand Up @@ -706,7 +720,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

0 comments on commit 86ff807

Please sign in to comment.