Skip to content

Commit 744aaee

Browse files
authored
Reset ruff.configuration if it contains VS Code variables (#746)
## Summary fixes: #741 ## Test Plan `settings.json`: ```json { "ruff.configuration": "${workspaceFolder}/formatter/ruff.toml" } ``` "Ruff" output channel: > [!NOTE] > > I've only kept the necessary settings here but the actual log output includes everything ``` 2025-05-01 10:38:43.029 [info] Workspace settings for /Users/dhruv/playground/ruff: { "nativeServer": "on", "cwd": "/Users/dhruv/playground/ruff", "workspace": "file:///Users/dhruv/playground/ruff", "path": [ "/Users/dhruv/work/astral/ruff/target/debug/ruff" ], "configuration": "/Users/dhruv/playground/ruff/formatter/ruff.toml", } 2025-05-01 10:38:43.030 [info] Resetting 'ruff.configuration' to null in global settings because it contains workspace specific variables 2025-05-01 10:38:43.030 [info] Global settings: { "nativeServer": "on", "cwd": "/", "workspace": "/", "path": [ "/Users/dhruv/work/astral/ruff/target/debug/ruff" ], "configuration": null, } ``` `settings.json`: ```json { "ruff.configuration": "${workspaceFolder:root}/formatter/ruff.toml" } ``` "Ruff" output channel: ``` 2025-05-01 10:40:42.200 [info] Workspace settings for /Users/dhruv/playground/ruff: { "nativeServer": "on", "cwd": "/Users/dhruv/playground/ruff", "workspace": "file:///Users/dhruv/playground/ruff", "path": [ "/Users/dhruv/work/astral/ruff/target/debug/ruff" ], "configuration": "${workspaceFolder:root}/formatter/ruff.toml", } 2025-05-01 10:40:42.200 [info] Resetting 'ruff.configuration' to null in global settings because it contains workspace specific variables 2025-05-01 10:40:42.200 [info] Global settings: { "nativeServer": "on", "cwd": "/", "workspace": "/", "path": [ "/Users/dhruv/work/astral/ruff/target/debug/ruff" ], "configuration": null, } ``` For this specific test case, you can see that the workspace settings also includes the `${workspaceFolder:root}` because it doesn't exists. That would also create an error: ``` 2025-05-01 10:42:14.245925000 ERROR Failed to load settings from `configuration`: error looking key 'workspaceFolder:root' up: environment variable not found ``` I think we should handle that as well.
1 parent ec180ab commit 744aaee

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/common/settings.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,36 @@ function getOptionalGlobalValue<T>(config: WorkspaceConfiguration, key: string):
196196
return inspect?.globalValue;
197197
}
198198

199+
/**
200+
* Returns the global settings for the extension.
201+
*
202+
* ## Notes
203+
*
204+
* The global settings do not belong to a specific workspace. This means that
205+
* variables such as `${workspaceFolder}` or `${workspaceFolder:...}` are not
206+
* resolved. The language server does not support these variables, so they are
207+
* filtered out. For example, if `configuration` has either of these variables,
208+
* it will be set to `null`.
209+
*/
199210
export async function getGlobalSettings(namespace: string): Promise<ISettings> {
200211
const config = getConfiguration(namespace);
212+
213+
let configuration = getGlobalValue<string | object | null>(config, "configuration", null);
214+
if (typeof configuration === "string" && configuration.search(/\$\{workspaceFolder/) !== -1) {
215+
logger.info(
216+
`Resetting '${namespace}.configuration' to null in global settings because it contains workspace specific variables`,
217+
);
218+
configuration = null;
219+
}
220+
201221
return {
202222
nativeServer: getGlobalValue<NativeServer>(config, "nativeServer", "auto"),
203223
cwd: process.cwd(),
204224
workspace: process.cwd(),
205225
path: getGlobalValue<string[]>(config, "path", []),
206226
ignoreStandardLibrary: getGlobalValue<boolean>(config, "ignoreStandardLibrary", true),
207227
interpreter: [],
208-
configuration: getGlobalValue<string | object | null>(config, "configuration", null),
228+
configuration,
209229
importStrategy: getGlobalValue<ImportStrategy>(config, "importStrategy", "fromEnvironment"),
210230
codeAction: getGlobalValue<CodeAction>(config, "codeAction", {}),
211231
lint: {

0 commit comments

Comments
 (0)