Skip to content

Don't overwrite debug settings the extension doesn't manage - #198

Open
CoreyShay wants to merge 1 commit into
MBulli:masterfrom
CoreyShay:fix/preserve-unmanaged-debug-settings
Open

Don't overwrite debug settings the extension doesn't manage#198
CoreyShay wants to merge 1 commit into
MBulli:masterfrom
CoreyShay:fix/preserve-unmanaged-debug-settings

Conversation

@CoreyShay

Copy link
Copy Markdown

Problem

With Manage Working Directories and/or Manage Launch Application enabled, the extension blanks the debugger Command and Working Directory of C/C++ projects that have no WorkDir/LaunchApp item, which makes launching the project fail.

Steps to reproduce:

  1. Enable Manage Working Directories and Manage Launch Application.
  2. Open a .vcxproj whose Command / Working Directory are set in the .vcxproj (so they show non-bold, i.e. inherited, in the property pages).
  3. Add only command line arguments for that project — no working directory and no launch application item.
  4. Press F5.

Command and Working Directory are now empty, the project does not start, and Visual Studio asks you to check the debug settings. Re-entering them by hand does not help, they are cleared again on the next launch.

Cause

GetWorkDirForProject and GetLaunchAppForProject start with var result = ""; and return that empty string when the project has no item of the corresponding type. GetEnvVarsForProject likewise returns an empty dictionary.

UpdateProjectConfig only skips writing a value when it is null, so the empty string is written through to the project, and an empty

<LocalDebuggerCommand />
<LocalDebuggerWorkingDirectory />

lands in the .vcxproj.user. Those elements override the values inherited from the .vcxproj, so the effective values become empty.

Fix

Distinguish the two cases that were previously conflated:

Situation Returned Meaning
No item of that type exists null Not managed by the extension — leave the project alone
Items exist but all unchecked "" User cleared it on purpose

This preserves the existing uncheck-to-clear behaviour while no longer touching settings the extension was never asked to manage.

AggregateComamndLineItemsForProject gained an includeUnchecked flag so the "does an item of this type exist at all?" question can be answered without a second, differently-filtered tree walk. Only unchecked filtering is affected — the project-configuration and launch-profile filters still apply, so the result stays scoped to the active configuration.

Note that flattening first and filtering on IsChecked afterwards is equivalent to the previous per-container filtering, because CmdContainer.UpdateCheckedState only reports false when all children are unchecked.

CreateCommandLineArgsForProject is deliberately unchanged — returning "" for arguments is correct there, since clearing arguments is the core feature.

Tests

Four tests added to ItemAggregationServiceTests:

  • GetWorkDirForProject_ShouldReturnNull_WhenProjectHasNoWorkDirItem
  • GetWorkDirForProject_ShouldReturnEmpty_WhenWorkDirItemIsUnchecked
  • GetLaunchAppForProject_ShouldReturnNull_WhenProjectHasNoLaunchAppItem
  • GetEnvVarsForProject_ShouldReturnNull_WhenProjectHasNoEnvVarItem

Full suite: 39/39 passing.

Notes

GetEnvVarsForProject can now return null. The only other caller (ToolWindowViewModel) already null-checks its result.

When "Manage Working Directories" or "Manage Launch Application" is
enabled but a project has no WorkDir/LaunchApp item, the aggregation
returned an empty string instead of null. UpdateProjectConfig only skips
writing on null, so an empty <LocalDebuggerCommand /> and
<LocalDebuggerWorkingDirectory /> were written into the .vcxproj.user.

Those empty elements override the values inherited from the .vcxproj,
so the Command and Working Directory shown in the project property pages
were blanked on every launch and debugging failed until they were
entered again by hand. The same applied to the debug environment.

Distinguish the two cases:
  - no item of that type exists  => null  => setting is not managed,
                                             leave the project alone
  - items exist but all unchecked => ""   => user cleared it on purpose

This keeps the existing "uncheck to clear" behaviour intact while no
longer touching settings the extension was never asked to manage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant