Skip to content

Commit

Permalink
Support prioritizing discovered TOML settings over editor settings (#457
Browse files Browse the repository at this point in the history
)

## Summary

Fixes #425 (though only
in the pre-release version, since this is a feature for the new LSP
server)

This is a follow-up to
#456.

A new setting has been introduced, `Prioritize File Configuration`,
which tells the extension to prioritize settings from discovered TOML
files over extension settings. Extension settings will still be used
when a set field in the extension is not set in the file configuration.

## Test Plan

Refer to astral-sh/ruff#11086 for a test plan.
  • Loading branch information
snowsignal committed May 17, 2024
1 parent d3832a6 commit 368464f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,22 @@
"scope": "resource",
"type": ["integer", "null"]
},
"ruff.configurationPreference": {
"enum": [
"editorFirst",
"filesystemFirst",
"editorOnly"
],
"enumDescriptions": [
"The default strategy - configuration set in the editor takes priority over configuration set in `.toml` files.",
"An alternative strategy - configuration set in `.toml` files takes priority over configuration set in the editor.",
"An alternative strategy - configuration set in `.toml` files is ignored entirely."
],
"markdownDescription": "The preferred method of resolving configuration in the editor with local configuration froml `.toml` files.",
"scope": "resource",
"type": "string",
"default": "editorFirst"
},
"ruff.enableExperimentalFormatter": {
"default": false,
"markdownDescription": "Controls whether Ruff registers as capable of code formatting.",
Expand Down
11 changes: 11 additions & 0 deletions src/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type ImportStrategy = "fromEnvironment" | "useBundled";

type Run = "onType" | "onSave";

type ConfigPreference = "editorFirst" | "filesystemFirst" | "editorOnly";

type CodeAction = {
disableRuleComment?: {
enable?: boolean;
Expand Down Expand Up @@ -53,6 +55,7 @@ export interface ISettings {
format: Format;
exclude?: string[];
lineLength?: number;
configurationPreference?: ConfigPreference;
}

export function getExtensionSettings(namespace: string): Promise<ISettings[]> {
Expand Down Expand Up @@ -151,6 +154,8 @@ export async function getWorkspaceSettings(
showNotifications: config.get<string>("showNotifications") ?? "off",
exclude: config.get<string[]>("exclude"),
lineLength: config.get<number>("lineLength"),
configurationPreference:
config.get<ConfigPreference>("configurationPreference") ?? "editorFirst",
};
}

Expand Down Expand Up @@ -195,6 +200,11 @@ export async function getGlobalSettings(namespace: string): Promise<ISettings> {
showNotifications: getGlobalValue<string>(config, "showNotifications", "off"),
exclude: getOptionalGlobalValue<string[]>(config, "exclude"),
lineLength: getOptionalGlobalValue<number>(config, "lineLength"),
configurationPreference: getGlobalValue<ConfigPreference>(
config,
"configurationPreference",
"editorFirst",
),
};
}

Expand Down Expand Up @@ -223,6 +233,7 @@ export function checkIfConfigurationChanged(
`${namespace}.format.preview`,
`${namespace}.exclude`,
`${namespace}.lineLength`,
`${namespace}.configurationPreference`,
// Deprecated settings (prefer `lint.args`, etc.).
`${namespace}.args`,
`${namespace}.run`,
Expand Down

0 comments on commit 368464f

Please sign in to comment.