Skip to content

Commit 68875a3

Browse files
committed
Revert "Move tracking of builds to unit-test solution crawler code (dotnet#78905)"
This reverts commit 438638e, reversing changes made to 5e2e54a.
1 parent 5ff6dc1 commit 68875a3

14 files changed

+94
-20
lines changed

src/EditorFeatures/Core/Remote/SolutionChecksumUpdater.cs

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Linq;
67
using System.Threading;
78
using System.Threading.Tasks;
89
using Microsoft.CodeAnalysis.ErrorReporting;
910
using Microsoft.CodeAnalysis.Internal.Log;
11+
using Microsoft.CodeAnalysis.Notification;
1012
using Microsoft.CodeAnalysis.Shared.Extensions;
1113
using Microsoft.CodeAnalysis.Shared.TestHooks;
1214
using Microsoft.CodeAnalysis.Telemetry;
@@ -22,6 +24,12 @@ internal sealed class SolutionChecksumUpdater
2224
{
2325
private readonly Workspace _workspace;
2426

27+
/// <summary>
28+
/// We're not at a layer where we are guaranteed to have an IGlobalOperationNotificationService. So allow for
29+
/// it being null.
30+
/// </summary>
31+
private readonly IGlobalOperationNotificationService? _globalOperationService;
32+
2533
private readonly IDocumentTrackingService _documentTrackingService;
2634

2735
/// <summary>
@@ -45,13 +53,17 @@ internal sealed class SolutionChecksumUpdater
4553
private const string SynchronizeTextChangesStatusSucceededKeyName = nameof(SolutionChecksumUpdater) + "." + SynchronizeTextChangesStatusSucceededMetricName;
4654
private const string SynchronizeTextChangesStatusFailedKeyName = nameof(SolutionChecksumUpdater) + "." + SynchronizeTextChangesStatusFailedMetricName;
4755

56+
private bool _isSynchronizeWorkspacePaused;
57+
4858
public SolutionChecksumUpdater(
4959
Workspace workspace,
5060
IAsynchronousOperationListenerProvider listenerProvider,
5161
CancellationToken shutdownToken)
5262
{
5363
var listener = listenerProvider.GetListener(FeatureAttribute.SolutionChecksumUpdater);
5464

65+
_globalOperationService = workspace.Services.SolutionServices.ExportProvider.GetExports<IGlobalOperationNotificationService>().FirstOrDefault()?.Value;
66+
5567
_workspace = workspace;
5668
_documentTrackingService = workspace.Services.GetRequiredService<IDocumentTrackingService>();
5769

@@ -74,6 +86,12 @@ public SolutionChecksumUpdater(
7486
_workspaceChangedImmediateDisposer = _workspace.RegisterWorkspaceChangedImmediateHandler(OnWorkspaceChangedImmediate);
7587
_documentTrackingService.ActiveDocumentChanged += OnActiveDocumentChanged;
7688

89+
if (_globalOperationService != null)
90+
{
91+
_globalOperationService.Started += OnGlobalOperationStarted;
92+
_globalOperationService.Stopped += OnGlobalOperationStopped;
93+
}
94+
7795
// Enqueue the work to sync the initial data over.
7896
_synchronizeActiveDocumentQueue.AddWork();
7997
_synchronizeWorkspaceQueue.AddWork();
@@ -82,21 +100,53 @@ public SolutionChecksumUpdater(
82100
public void Shutdown()
83101
{
84102
// Try to stop any work that is in progress.
103+
PauseSynchronizingPrimaryWorkspace();
104+
105+
_documentTrackingService.ActiveDocumentChanged -= OnActiveDocumentChanged;
106+
_workspaceChangedDisposer.Dispose();
107+
_workspaceChangedImmediateDisposer.Dispose();
108+
109+
if (_globalOperationService != null)
110+
{
111+
_globalOperationService.Started -= OnGlobalOperationStarted;
112+
_globalOperationService.Stopped -= OnGlobalOperationStopped;
113+
}
114+
}
115+
116+
private void OnGlobalOperationStarted(object? sender, EventArgs e)
117+
=> PauseSynchronizingPrimaryWorkspace();
118+
119+
private void OnGlobalOperationStopped(object? sender, EventArgs e)
120+
=> ResumeSynchronizingPrimaryWorkspace();
121+
122+
private void PauseSynchronizingPrimaryWorkspace()
123+
{
124+
// An expensive global operation started (like a build). Pause ourselves and cancel any outstanding work in
125+
// progress to synchronize the solution.
85126
lock (_gate)
86127
{
87128
_synchronizeWorkspaceQueue.CancelExistingWork();
129+
_isSynchronizeWorkspacePaused = true;
88130
}
131+
}
89132

90-
_documentTrackingService.ActiveDocumentChanged -= OnActiveDocumentChanged;
91-
_workspaceChangedDisposer.Dispose();
92-
_workspaceChangedImmediateDisposer.Dispose();
133+
private void ResumeSynchronizingPrimaryWorkspace()
134+
{
135+
lock (_gate)
136+
{
137+
_isSynchronizeWorkspacePaused = false;
138+
_synchronizeWorkspaceQueue.AddWork();
139+
}
93140
}
94141

95142
private void OnWorkspaceChanged(WorkspaceChangeEventArgs _)
96143
{
144+
// Check if we're currently paused. If so ignore this notification. We don't want to any work in response
145+
// to whatever the workspace is doing.
97146
lock (_gate)
98147
{
99-
_synchronizeWorkspaceQueue.AddWork();
148+
if (!_isSynchronizeWorkspacePaused)
149+
_synchronizeWorkspaceQueue.AddWork();
100150
}
101151
}
102152

src/EditorFeatures/TestUtilities/EditorTestCompositions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.CodeAnalysis.Editor.Implementation.Notification;
88
using Microsoft.CodeAnalysis.LanguageServer;
99
using Microsoft.CodeAnalysis.Test.Utilities;
10+
using Microsoft.CodeAnalysis.Test.Utilities.Notification;
1011
using Microsoft.CodeAnalysis.Text;
1112
using Microsoft.CodeAnalysis.UnitTests.Fakes;
1213
using Microsoft.CodeAnalysis.UnitTests.Remote;
@@ -56,6 +57,7 @@ public static class EditorTestCompositions
5657
typeof(TestObscuringTipManager)); // TODO: https://devdiv.visualstudio.com/DevDiv/_workitems?id=544569
5758

5859
public static readonly TestComposition EditorFeatures = FeaturesTestCompositions.Features
60+
.AddParts(typeof(TestGlobalOperationNotificationService))
5961
.Add(Editor)
6062
.AddAssemblies(
6163
typeof(TextEditorResources).Assembly,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Composition;
7+
using System.Threading;
8+
using Microsoft.CodeAnalysis.Host.Mef;
9+
using Microsoft.CodeAnalysis.Notification;
10+
using Microsoft.CodeAnalysis.Shared.TestHooks;
11+
using Microsoft.VisualStudio.Composition;
12+
13+
namespace Microsoft.CodeAnalysis.Test.Utilities.Notification;
14+
15+
[Export(typeof(IGlobalOperationNotificationService)), PartNotDiscoverable, Shared]
16+
[method: ImportingConstructor]
17+
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
18+
internal sealed class TestGlobalOperationNotificationService(
19+
IAsynchronousOperationListenerProvider listenerProvider)
20+
: AbstractGlobalOperationNotificationService(listenerProvider, CancellationToken.None);

src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingGlobalOperationAwareIdleProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
using System;
66
using System.Threading;
7-
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
7+
using Microsoft.CodeAnalysis.Notification;
88
using Microsoft.CodeAnalysis.Shared.TestHooks;
99

1010
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.SolutionCrawler;

src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.AbstractUnitTestingPriorityProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using System.Collections.Immutable;
77
using System.Threading;
88
using System.Threading.Tasks;
9-
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
109
using Microsoft.CodeAnalysis.Internal.Log;
10+
using Microsoft.CodeAnalysis.Notification;
1111
using Microsoft.CodeAnalysis.Shared.TestHooks;
1212

1313
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.SolutionCrawler;

src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.UnitTestingIncrementalAnalyzerProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
using System.Threading.Tasks;
1111
using Microsoft.CodeAnalysis.ErrorReporting;
1212
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api;
13-
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
1413
using Microsoft.CodeAnalysis.Host;
1514
using Microsoft.CodeAnalysis.Internal.Log;
1615
using Microsoft.CodeAnalysis.LanguageService;
16+
using Microsoft.CodeAnalysis.Notification;
1717
using Microsoft.CodeAnalysis.Shared.Extensions;
1818
using Microsoft.CodeAnalysis.Shared.TestHooks;
1919
using Roslyn.Utilities;

src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.UnitTestingLowPriorityProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using Microsoft.CodeAnalysis.ErrorReporting;
11-
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
1211
using Microsoft.CodeAnalysis.Internal.Log;
12+
using Microsoft.CodeAnalysis.Notification;
1313
using Microsoft.CodeAnalysis.Shared.TestHooks;
1414

1515
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.SolutionCrawler;

src/Features/Core/Portable/ExternalAccess/UnitTesting/SolutionCrawler/UnitTestingWorkCoordinator.UnitTestingNormalPriorityProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
using System.Threading.Tasks;
1111
using Microsoft.CodeAnalysis.ErrorReporting;
1212
using Microsoft.CodeAnalysis.Internal.Log;
13+
using Microsoft.CodeAnalysis.Notification;
1314
using Microsoft.CodeAnalysis.Shared.Extensions;
1415
using Microsoft.CodeAnalysis.Shared.TestHooks;
1516
using Roslyn.Utilities;
1617
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api;
17-
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
1818

1919
#if DEBUG
2020
using System.Diagnostics;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
using System;
66
using System.Composition;
77
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
8-
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
98
using Microsoft.CodeAnalysis.Host.Mef;
9+
using Microsoft.CodeAnalysis.Notification;
1010
using Microsoft.CodeAnalysis.Shared.TestHooks;
1111

12-
namespace Microsoft.VisualStudio.LanguageServices.ExternalAccess.UnitTesting;
12+
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Notification;
1313

1414
[Export(typeof(IGlobalOperationNotificationService)), Shared]
1515
[method: ImportingConstructor]

src/VisualStudio/Core/Def/RoslynPackage.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncCompletion;
1515
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
1616
using Microsoft.CodeAnalysis.ErrorReporting;
17-
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
17+
using Microsoft.CodeAnalysis.Notification;
1818
using Microsoft.CodeAnalysis.Options;
1919
using Microsoft.CodeAnalysis.Remote.ProjectSystem;
2020
using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings;
21-
using Microsoft.VisualStudio.LanguageServices.ExternalAccess.UnitTesting;
2221
using Microsoft.VisualStudio.LanguageServices.Implementation.Diagnostics;
2322
using Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService;
2423
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.RuleSets;
@@ -216,8 +215,11 @@ protected override void Dispose(bool disposing)
216215

217216
ReportSessionWideTelemetry();
218217

219-
_solutionEventMonitor?.Dispose();
220-
_solutionEventMonitor = null;
218+
if (_solutionEventMonitor != null)
219+
{
220+
_solutionEventMonitor.Dispose();
221+
_solutionEventMonitor = null;
222+
}
221223

222224
base.Dispose(disposing);
223225
}

0 commit comments

Comments
 (0)