Skip to content

Enable/Disable Hex mode button: modify setting in existing location#1109

Merged
haneefdm merged 2 commits intoMarus:masterfrom
malsyned:issue-1107-try2
Apr 8, 2025
Merged

Enable/Disable Hex mode button: modify setting in existing location#1109
haneefdm merged 2 commits intoMarus:masterfrom
malsyned:issue-1107-try2

Conversation

@malsyned
Copy link
Contributor

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

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 Marus#1107
@malsyned
Copy link
Contributor Author

I tested the basic functionality for this, and it worked great to select between workspace and user settings, and default to user settings if the option is unset everywhere.

I wasn't able to test the language-specific override functionality, because this particular setting doesn't seem to pull in language overrides -- at least from "[c]" or "[c++]". At any rate, that code doesn't interfere at all with this use case. I included it for completeness in case the helper routine getConfigSource() is ever needed for other settings. If it's adding complexity you don't think we need, I can take it out easily enough:

diff --git a/src/frontend/extension.ts b/src/frontend/extension.ts
index 6d08c7c..01c8337 100644
--- a/src/frontend/extension.ts
+++ b/src/frontend/extension.ts
@@ -336,22 +336,13 @@ export class CortexDebugExtension {
             ['workspaceFolderValue', vscode.ConfigurationTarget.WorkspaceFolde>
             ['workspaceValue', vscode.ConfigurationTarget.Workspace],
             ['globalValue', vscode.ConfigurationTarget.Global],
-            // Modify user settings if setting isn't configured yet
-            ['defaultValue', vscode.ConfigurationTarget.Global],
         ];
         const info = config.inspect(section);
         for (const mapping of configurationTargetMapping) {
             const [inspectKey, mappingTarget] = mapping;
-            const inspectLanguageKey = inspectKey.replace('Value', 'LanguageVa>
-            if (info[inspectLanguageKey] !== undefined)
-                return [mappingTarget, true];
             if (info[inspectKey] !== undefined)
                 return [mappingTarget, false];
         }
-        // Shouldn't get here unless new configuration targets get added to the
-        // VSCode API, only those sources have values for this setting, and th>
-        // setting doesn't have a default value. Still, do something rational
-        // just in case.
         return [vscode.ConfigurationTarget.Global, false];
     }

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.
@malsyned
Copy link
Contributor Author

Sorry for the flurry of updates. I noticed after creating the PR that my precedence order didn't match the API documentation. Should be all set to go now.

@haneefdm haneefdm merged commit ff10c91 into Marus:master Apr 8, 2025
3 checks passed
@malsyned
Copy link
Contributor Author

malsyned commented Apr 8, 2025

Thank you! I appreciate your openness to my pull requests. I really like cortex-debug and its related projects, and I'm enjoying playing a small part in improving them.

@malsyned malsyned deleted the issue-1107-try2 branch April 11, 2025 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable Hex mode button: Modify cortex-debug.variableUseNaturalFormat in User settings, not Workspace settings

2 participants