Skip to content

Commit df3e341

Browse files
Fixing command duplicates when loading commands from provider (#38091)
There is a bug in command palette where the top level commands from extensions gets duplicated after the extension raises items changed, or when it is requested by CmdPal for any reason. This didn't happen when we kill CmdPal and open it again. When investigating, I noticed that the `UpdateCommandsForProvider` method was not deleting the top level commands for the extension. This seems to be happening because the comparison `var isTheSame = wrapper == firstCommand;` is not comparing objects of the same type. It was comparing a `TopLevelViewModel` with a `CommandItem`, and it was never set to `true`. I change it to compare the `TopLevelViewModel` of both commands, and now it seems to be detecting correctly. Another option of fix could be comparing the `CommandItem`s. closes zadjii-msft#511 --- Another bug that I found while testing today is that when a user uninstalled or updated an extension, it was still being listed as an enabled extension. This was generating duplicates in the top level commands in case of updating an extension, and resulting in unpredictable behavior and occasional crashes in CmdPal. Added a fix for that on `ExtensionService`, removing the uninstalled extensions also from the `_enabledExtensions` list. --------- Co-authored-by: Mike Griese <[email protected]>
1 parent 7368458 commit df3e341

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Models/ExtensionService.cs

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ private void UninstallPackageUnderLock(Package package)
131131
try
132132
{
133133
_installedExtensions.RemoveAll(i => removedExtensions.Contains(i));
134+
_enabledExtensions.RemoveAll(i => removedExtensions.Contains(i));
134135

135136
OnExtensionRemoved?.Invoke(this, removedExtensions);
136137
}

src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs

+4-9
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,11 @@ private async Task UpdateCommandsForProvider(CommandProviderWrapper sender, IIte
133133
var wrapper = clone[i];
134134
try
135135
{
136-
// TODO! this can be safer, we're not directly exposing ICommandItem's out of CPW anymore
137-
var thisCommand = wrapper.ItemViewModel.Model.Unsafe;
138-
if (thisCommand != null)
136+
var isTheSame = wrapper == firstCommand;
137+
if (isTheSame)
139138
{
140-
var isTheSame = thisCommand == firstCommand;
141-
if (isTheSame)
142-
{
143-
startIndex = i;
144-
break;
145-
}
139+
startIndex = i;
140+
break;
146141
}
147142
}
148143
catch

0 commit comments

Comments
 (0)