Skip to content

Commit ff10c91

Browse files
authored
Enable/Disable Hex mode button: modify setting in existing location (#1109)
* Enable/Disable Hex mode button: modify setting in existing location This button toggles the `cortex-debug.variableUseNaturalFormat` setting. Its value can come from the `settings.json` for the current User, Workspace, or Workspace Folder. If it is set in any of those places, modify it there. Otherwise, modify it in the User's global `settings.json`. Fixes #1107 * getConfigSource: fix inheritance order for language overrides The order is specified in https://code.visualstudio.com/api/references/vscode-api#WorkspaceConfiguration and has language overrides from all sources taking precedence over non-overridden settings from every source.
1 parent f9ff98b commit ff10c91

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

src/frontend/extension.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,30 @@ export class CortexDebugExtension {
331331
);
332332
}
333333

334+
private getConfigSource(config: vscode.WorkspaceConfiguration, section: string): [vscode.ConfigurationTarget, boolean] {
335+
const configurationTargetMapping: [string, vscode.ConfigurationTarget][] = [
336+
['workspaceFolder', vscode.ConfigurationTarget.WorkspaceFolder],
337+
['workspace', vscode.ConfigurationTarget.Workspace],
338+
['global', vscode.ConfigurationTarget.Global],
339+
// Modify user settings if setting isn't configured yet
340+
['default', vscode.ConfigurationTarget.Global],
341+
];
342+
const info = config.inspect(section);
343+
for (const inspectKeySuffix of ['LanguageValue', 'Value']) {
344+
for (const mapping of configurationTargetMapping) {
345+
const [inspectKeyPrefix, mappingTarget] = mapping;
346+
const inspectKey = inspectKeyPrefix + inspectKeySuffix;
347+
if (info[inspectKey] !== undefined)
348+
return [mappingTarget, inspectKeySuffix == 'LanguageValue'];
349+
}
350+
}
351+
// Shouldn't get here unless new configuration targets get added to the
352+
// VSCode API, only those sources have values for this setting, and this
353+
// setting doesn't have a default value. Still, do something rational
354+
// just in case.
355+
return [vscode.ConfigurationTarget.Global, false];
356+
}
357+
334358
// Settings changes
335359
private variablesNaturalMode(newVal: boolean, cxt?: any) {
336360
// 'cxt' contains the treeItem on which this menu was invoked. Maybe we can do something
@@ -339,7 +363,8 @@ export class CortexDebugExtension {
339363

340364
vscode.commands.executeCommand('setContext', `cortex-debug:${CortexDebugKeys.VARIABLE_DISPLAY_MODE}`, newVal);
341365
try {
342-
config.update(CortexDebugKeys.VARIABLE_DISPLAY_MODE, newVal);
366+
const [target, languageOverride] = this.getConfigSource(config, CortexDebugKeys.VARIABLE_DISPLAY_MODE);
367+
config.update(CortexDebugKeys.VARIABLE_DISPLAY_MODE, newVal, target, languageOverride);
343368
} catch (e) {
344369
console.error(e);
345370
}
@@ -353,7 +378,8 @@ export class CortexDebugExtension {
353378
const newVal = !curVal;
354379
vscode.commands.executeCommand('setContext', `cortex-debug:${CortexDebugKeys.VARIABLE_DISPLAY_MODE}`, newVal);
355380
try {
356-
config.update(CortexDebugKeys.VARIABLE_DISPLAY_MODE, newVal);
381+
const [target, languageOverride] = this.getConfigSource(config, CortexDebugKeys.VARIABLE_DISPLAY_MODE);
382+
config.update(CortexDebugKeys.VARIABLE_DISPLAY_MODE, newVal, target, languageOverride);
357383
} catch (e) {
358384
console.error(e);
359385
}

0 commit comments

Comments
 (0)