Skip to content

Commit 884f798

Browse files
authored
[JAVAVSCODE #199] Quick Fix actions are unable to edit runConfig options in global settings for non-workspace opened Java files (#211)
Fixed extension.ts `UpdateConfigurationRequest` handler to update the global `WorkspaceConfiguration` for non-workspace opened files. 1. Checked for non-workspace opened files by testing if `vscode.workspace.workspaceFile` is undefined/null. 2. Invoked `WorkspaceConfiguration.update()` with `configurationTarget = `: - `true`: for non-workspace files; - `null`: otherwise. 3. Added a try-catch to log errors in update and prevent downstream failures. 4. Avoided an unnecessary `await` and used the `Thenable` chain of `update()`. Fixes #199 Signed-off-by: Siddharth Srinivasan <[email protected]>
1 parent 78ba888 commit 884f798

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

vscode/src/extension.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,22 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
11001100
return selected ? Array.isArray(selected) ? selected : [selected] : undefined;
11011101
});
11021102
c.onRequest(UpdateConfigurationRequest.type, async (param) => {
1103-
await vscode.workspace.getConfiguration(param.section).update(param.key, param.value);
1104-
runConfigurationUpdateAll();
1103+
handleLog(log, "Received config update: " + param.section + "." + param.key + "=" + param.value);
1104+
let wsFile: vscode.Uri | undefined = vscode.workspace.workspaceFile;
1105+
let wsConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(param.section);
1106+
if (wsConfig) {
1107+
try {
1108+
wsConfig.update(param.key, param.value, wsFile ? null : true)
1109+
.then(() => {
1110+
handleLog(log, "Updated configuration: " + param.section + "." + param.key + "=" + param.value + "; in: " + (wsFile ? wsFile.toString() : "Global"));
1111+
})
1112+
.then(() => {
1113+
runConfigurationUpdateAll();
1114+
});
1115+
} catch (err) {
1116+
handleLog(log, "Failed to update configuration. Reason: " + (typeof err === "string" ? err : err instanceof Error ? err.message : "error"));
1117+
}
1118+
}
11051119
});
11061120
c.onRequest(SaveDocumentsRequest.type, async (request : SaveDocumentRequestParams) => {
11071121
const uriList = request.documents.map(s => {

0 commit comments

Comments
 (0)