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 9637979
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 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_workspace_settings: 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_workspace_settings: Option<bool>,
}

/// This is a direct representation of the workspace settings schema,
Expand Down Expand Up @@ -259,6 +261,9 @@ impl ResolvedClientSettings {
Some(settings.exclude.as_ref()?.clone())
}),
line_length: Self::resolve_optional(all_settings, |settings| settings.line_length),
prioritize_workspace_settings: Self::resolve_or(all_settings, |settings| {
settings.prioritize_workspace_settings
}, false)
},
}
}
Expand Down Expand Up @@ -324,6 +329,7 @@ impl ResolvedEditorSettings {
ignore,
exclude,
line_length,
prioritize_workspace_settings
} = self.clone();

let editor_configuration = Configuration {
Expand Down Expand Up @@ -354,7 +360,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 +606,8 @@ mod tests {
extend_select: None,
ignore: None,
exclude: None,
line_length: None
line_length: None,
prioritize_workspace_settings: false,
}
}
);
Expand Down Expand Up @@ -624,7 +635,8 @@ mod tests {
extend_select: None,
ignore: None,
exclude: None,
line_length: None
line_length: None,
prioritize_workspace_settings: false,
}
}
);
Expand Down Expand Up @@ -706,7 +718,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_workspace_settings: false,
}
}
);
Expand Down

0 comments on commit 9637979

Please sign in to comment.