Skip to content

Commit af82f19

Browse files
committed
use Unknown ConfigurationOrigin instead of None
1 parent ccadd49 commit af82f19

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ fn open_configuration_file(config_path: &Path) -> crate::Result<Configuration> {
443443
config_path,
444444
Relativity::Cwd,
445445
&IdentityTransformer,
446-
None,
446+
ruff_workspace::resolver::ConfigurationOrigin::Unknown,
447447
)
448448
}
449449

crates/ruff_workspace/src/resolver.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub fn resolve_configuration(
303303
pyproject: &Path,
304304
relativity: Relativity,
305305
transformer: &dyn ConfigurationTransformer,
306-
origin: Option<ConfigurationOrigin>,
306+
origin: ConfigurationOrigin,
307307
) -> Result<Configuration> {
308308
let mut configurations = indexmap::IndexMap::new();
309309
let mut next = Some(fs::normalize_path(pyproject));
@@ -321,7 +321,7 @@ pub fn resolve_configuration(
321321

322322
// Resolve the current path.
323323
let version_strategy =
324-
if configurations.is_empty() && matches!(origin, Some(ConfigurationOrigin::Ancestor)) {
324+
if configurations.is_empty() && matches!(origin, ConfigurationOrigin::Ancestor) {
325325
// For configurations that are discovered by
326326
// walking back from a file, we will attempt to
327327
// infer the `target-version` if it is missing
@@ -383,7 +383,7 @@ fn resolve_scoped_settings<'a>(
383383
pyproject: &'a Path,
384384
relativity: Relativity,
385385
transformer: &dyn ConfigurationTransformer,
386-
origin: Option<ConfigurationOrigin>,
386+
origin: ConfigurationOrigin,
387387
) -> Result<(&'a Path, Settings)> {
388388
let configuration = resolve_configuration(pyproject, relativity, transformer, origin)?;
389389
let project_root = relativity.resolve(pyproject);
@@ -400,16 +400,18 @@ pub fn resolve_root_settings(
400400
origin: ConfigurationOrigin,
401401
) -> Result<Settings> {
402402
let (_project_root, settings) =
403-
resolve_scoped_settings(pyproject, relativity, transformer, Some(origin))?;
403+
resolve_scoped_settings(pyproject, relativity, transformer, origin)?;
404404
Ok(settings)
405405
}
406406

407407
#[derive(Debug, Clone, Copy)]
408408
/// How the configuration is provided.
409409
pub enum ConfigurationOrigin {
410+
/// Origin is unknown to the caller
411+
Unknown,
410412
/// User specified path to specific configuration file
411413
UserSpecified,
412-
/// User-level configuration
414+
/// User-level configuration (e.g. in `~/.config/ruff/pyproject.toml`)
413415
UserSettings,
414416
/// In parent or higher ancestor directory of path
415417
Ancestor,
@@ -442,7 +444,7 @@ pub fn python_files_in_path<'a>(
442444
&pyproject,
443445
Relativity::Parent,
444446
transformer,
445-
None,
447+
ConfigurationOrigin::Unknown,
446448
)?;
447449
resolver.add(root, settings);
448450
// We found the closest configuration.
@@ -597,7 +599,7 @@ impl ParallelVisitor for PythonFilesVisitor<'_, '_> {
597599
&pyproject,
598600
Relativity::Parent,
599601
self.transformer,
600-
None,
602+
ConfigurationOrigin::Unknown,
601603
) {
602604
Ok((root, settings)) => {
603605
self.global.resolver.write().unwrap().add(root, settings);
@@ -730,8 +732,12 @@ pub fn python_file_at_path(
730732
if resolver.is_hierarchical() {
731733
for ancestor in path.ancestors() {
732734
if let Some(pyproject) = settings_toml(ancestor)? {
733-
let (root, settings) =
734-
resolve_scoped_settings(&pyproject, Relativity::Parent, transformer, None)?;
735+
let (root, settings) = resolve_scoped_settings(
736+
&pyproject,
737+
Relativity::Parent,
738+
transformer,
739+
ConfigurationOrigin::Unknown,
740+
)?;
735741
resolver.add(root, settings);
736742
break;
737743
}

0 commit comments

Comments
 (0)