Skip to content

Commit 2120fa7

Browse files
Put back a check for IVsMonitorSelection to avoid use of UIContext
Right now it appears we have a bug that when that update runs, it updates the Solution.WorkspaceVersion which breaks the ability for TryApplyChanges to work later. CodeModel doesn't deal with that case so leaving this in causes CodeModel tests to get flaky. Furthermore, the WhenActivated() calls can't be unsubscribed, and will leak for later tests, which can cause our tests to OOM in CI.
1 parent e4288e8 commit 2120fa7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/VisualStudio/Core/Def/ProjectSystem/VisualStudioWorkspaceImpl_SourceGenerators.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
55
using System.Linq;
66
using Microsoft.CodeAnalysis.Host;
77
using Microsoft.VisualStudio.Shell;
8+
using Microsoft.VisualStudio.Shell.Interop;
89

910
namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
1011

1112
internal abstract partial class VisualStudioWorkspaceImpl
1213
{
1314
private void SubscribeToSourceGeneratorImpactingEvents()
1415
{
16+
// HACK: We don't want to subscribe to these in unit tests; the use of WhenActivated can cause a leak if these don't actually
17+
// run, and that API gives us no way to unsubscribe. Further; right now raising events to update the source generator versions
18+
// causes TryApplyChanges to also fail.
19+
if (ServiceProvider.GlobalProvider.GetService(typeof(IVsMonitorSelection)) == null)
20+
return;
21+
1522
// This pattern ensures that we are called whenever the build starts/completes even if it is already in progress.
1623
KnownUIContexts.SolutionBuildingContext.WhenActivated(() =>
1724
{

0 commit comments

Comments
 (0)