Skip to content

Commit 20573af

Browse files
authored
fix(commands): refresh Solution Explorer after cleaning bin/obj (#34)
Sends the standard Refresh command to each cleaned project's IVsUIHierarchy so stale nodes disappear from Solution Explorer without requiring an unload/reload, particularly under "Show All Files".
1 parent 7bbd75c commit 20573af

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/CodingWithCalvin.SuperClean/Commands/SuperCleanCommand.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
using System.Threading.Tasks;
77
using CodingWithCalvin.Otel4Vsix;
88
using Community.VisualStudio.Toolkit;
9+
using Microsoft.VisualStudio;
910
using Microsoft.VisualStudio.Shell;
11+
using Microsoft.VisualStudio.Shell.Interop;
1012
using MessageBox = System.Windows.Forms.MessageBox;
1113

1214
namespace CodingWithCalvin.SuperClean.Commands
@@ -232,8 +234,33 @@ async Task<bool> SuperCleanProjectAsync(SolutionItem project)
232234
projectActivity?.SetTag("obj.deleted", true);
233235
}
234236

237+
await RefreshInSolutionExplorerAsync(project);
238+
235239
return true;
236240
}
237241
}
242+
243+
private static async Task RefreshInSolutionExplorerAsync(SolutionItem project)
244+
{
245+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
246+
247+
project.GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out _);
248+
249+
if (hierarchy is not IVsUIHierarchy uiHierarchy)
250+
{
251+
return;
252+
}
253+
254+
var cmdGuid = VSConstants.GUID_VSStandardCommandSet97;
255+
256+
uiHierarchy.ExecCommand(
257+
itemId,
258+
ref cmdGuid,
259+
(uint)VSConstants.VSStd97CmdID.Refresh,
260+
0,
261+
IntPtr.Zero,
262+
IntPtr.Zero
263+
);
264+
}
238265
}
239266
}

0 commit comments

Comments
 (0)