Skip to content

Reset ruff.configuration if it contains VS Code variables #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,36 @@ function getOptionalGlobalValue<T>(config: WorkspaceConfiguration, key: string):
return inspect?.globalValue;
}

/**
* Returns the global settings for the extension.
*
* ## Notes
*
* The global settings do not belong to a specific workspace. This means that
* variables such as `${workspaceFolder}` or `${workspaceFolder:...}` are not
* resolved. The language server does not support these variables, so they are
* filtered out. For example, if `configuration` has either of these variables,
* it will be set to `null`.
*/
export async function getGlobalSettings(namespace: string): Promise<ISettings> {
const config = getConfiguration(namespace);

let configuration = getGlobalValue<string | object | null>(config, "configuration", null);
if (typeof configuration === "string" && configuration.search(/\$\{workspaceFolder/) !== -1) {
logger.info(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log this with warn or even error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, it's not a user error but just something to note of. Refer to my other comment.

`Resetting '${namespace}.configuration' to null in global settings because it contains workspace specific variables`,
);
configuration = null;
}

return {
nativeServer: getGlobalValue<NativeServer>(config, "nativeServer", "auto"),
cwd: process.cwd(),
workspace: process.cwd(),
path: getGlobalValue<string[]>(config, "path", []),
ignoreStandardLibrary: getGlobalValue<boolean>(config, "ignoreStandardLibrary", true),
interpreter: [],
configuration: getGlobalValue<string | object | null>(config, "configuration", null),
configuration,
importStrategy: getGlobalValue<ImportStrategy>(config, "importStrategy", "fromEnvironment"),
codeAction: getGlobalValue<CodeAction>(config, "codeAction", {}),
lint: {
Expand Down