Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 4 additions & 52 deletions src/EditorFeatures/Core/Remote/SolutionChecksumUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ internal sealed class SolutionChecksumUpdater
{
private readonly Workspace _workspace;

/// <summary>
/// We're not at a layer where we are guaranteed to have an IGlobalOperationNotificationService. So allow for
/// it being null.
/// </summary>
private readonly IGlobalOperationNotificationService? _globalOperationService;

private readonly IDocumentTrackingService _documentTrackingService;

/// <summary>
Expand All @@ -54,17 +48,13 @@ internal sealed class SolutionChecksumUpdater
private const string SynchronizeTextChangesStatusSucceededKeyName = nameof(SolutionChecksumUpdater) + "." + SynchronizeTextChangesStatusSucceededMetricName;
private const string SynchronizeTextChangesStatusFailedKeyName = nameof(SolutionChecksumUpdater) + "." + SynchronizeTextChangesStatusFailedMetricName;

private bool _isSynchronizeWorkspacePaused;

public SolutionChecksumUpdater(
Workspace workspace,
IAsynchronousOperationListenerProvider listenerProvider,
CancellationToken shutdownToken)
{
var listener = listenerProvider.GetListener(FeatureAttribute.SolutionChecksumUpdater);

_globalOperationService = workspace.Services.SolutionServices.ExportProvider.GetExports<IGlobalOperationNotificationService>().FirstOrDefault()?.Value;

_workspace = workspace;
_documentTrackingService = workspace.Services.GetRequiredService<IDocumentTrackingService>();

Expand All @@ -87,12 +77,6 @@ public SolutionChecksumUpdater(
_workspaceChangedImmediateDisposer = _workspace.RegisterWorkspaceChangedImmediateHandler(OnWorkspaceChangedImmediate);
_documentTrackingService.ActiveDocumentChanged += OnActiveDocumentChanged;

if (_globalOperationService != null)
{
_globalOperationService.Started += OnGlobalOperationStarted;
_globalOperationService.Stopped += OnGlobalOperationStopped;
}

// Enqueue the work to sync the initial data over.
_synchronizeActiveDocumentQueue.AddWork();
_synchronizeWorkspaceQueue.AddWork();
Expand All @@ -101,53 +85,21 @@ public SolutionChecksumUpdater(
public void Shutdown()
{
// Try to stop any work that is in progress.
PauseSynchronizingPrimaryWorkspace();

_documentTrackingService.ActiveDocumentChanged -= OnActiveDocumentChanged;
_workspaceChangedDisposer.Dispose();
_workspaceChangedImmediateDisposer.Dispose();

if (_globalOperationService != null)
{
_globalOperationService.Started -= OnGlobalOperationStarted;
_globalOperationService.Stopped -= OnGlobalOperationStopped;
}
}

private void OnGlobalOperationStarted(object? sender, EventArgs e)
=> PauseSynchronizingPrimaryWorkspace();

private void OnGlobalOperationStopped(object? sender, EventArgs e)
=> ResumeSynchronizingPrimaryWorkspace();

private void PauseSynchronizingPrimaryWorkspace()
{
// An expensive global operation started (like a build). Pause ourselves and cancel any outstanding work in
// progress to synchronize the solution.
lock (_gate)
{
_synchronizeWorkspaceQueue.CancelExistingWork();
_isSynchronizeWorkspacePaused = true;
}
}

private void ResumeSynchronizingPrimaryWorkspace()
{
lock (_gate)
{
_isSynchronizeWorkspacePaused = false;
_synchronizeWorkspaceQueue.AddWork();
}
_documentTrackingService.ActiveDocumentChanged -= OnActiveDocumentChanged;
_workspaceChangedDisposer.Dispose();
_workspaceChangedImmediateDisposer.Dispose();
}

private void OnWorkspaceChanged(WorkspaceChangeEventArgs _)
{
// Check if we're currently paused. If so ignore this notification. We don't want to any work in response
// to whatever the workspace is doing.
lock (_gate)
{
if (!_isSynchronizeWorkspacePaused)
_synchronizeWorkspaceQueue.AddWork();
_synchronizeWorkspaceQueue.AddWork();
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/EditorFeatures/TestUtilities/EditorTestCompositions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.CodeAnalysis.Editor.Implementation.Notification;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities.Notification;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.UnitTests.Fakes;
using Microsoft.CodeAnalysis.UnitTests.Remote;
Expand Down Expand Up @@ -57,7 +56,6 @@ public static class EditorTestCompositions
typeof(TestObscuringTipManager)); // TODO: https://devdiv.visualstudio.com/DevDiv/_workitems?id=544569

public static readonly TestComposition EditorFeatures = FeaturesTestCompositions.Features
.AddParts(typeof(TestGlobalOperationNotificationService))
.Add(Editor)
.AddAssemblies(
typeof(TextEditorResources).Assembly,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using System;

namespace Microsoft.CodeAnalysis.Notification;
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;

internal partial class AbstractGlobalOperationNotificationService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Microsoft.CodeAnalysis.Threading;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Notification;
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;

internal abstract partial class AbstractGlobalOperationNotificationService : IGlobalOperationNotificationService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using System;

namespace Microsoft.CodeAnalysis.Notification;
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;

/// <summary>
/// Optional interface that can be used to hear about when expensive global operations (like a 'build') occur in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using System;
using System.Threading;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
using Microsoft.CodeAnalysis.Shared.TestHooks;

namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.SolutionCrawler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Shared.TestHooks;

namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.SolutionCrawler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.LanguageService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Shared.TestHooks;

namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.SolutionCrawler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Roslyn.Utilities;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;

#if DEBUG
using System.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
using Microsoft.VisualStudio.Shell;

namespace Microsoft.VisualStudio.LanguageServices;
namespace Microsoft.VisualStudio.LanguageServices.ExternalAccess.UnitTesting;

/// <summary>
/// Monitors Visual Studio's UIContext for Solution building/opening/closing and notifies the GlobalOperationService.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using System;
using System.Composition;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Shared.TestHooks;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.Notification;
namespace Microsoft.VisualStudio.LanguageServices.ExternalAccess.UnitTesting;

[Export(typeof(IGlobalOperationNotificationService)), Shared]
[method: ImportingConstructor]
Expand Down
9 changes: 4 additions & 5 deletions src/VisualStudio/Core/Def/RoslynPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncCompletion;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Notification;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Remote.ProjectSystem;
using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings;
using Microsoft.VisualStudio.LanguageServices.ExternalAccess.UnitTesting;
using Microsoft.VisualStudio.LanguageServices.Implementation.Diagnostics;
using Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.RuleSets;
Expand Down Expand Up @@ -215,11 +217,8 @@ protected override void Dispose(bool disposing)

ReportSessionWideTelemetry();

if (_solutionEventMonitor != null)
{
_solutionEventMonitor.Dispose();
_solutionEventMonitor = null;
}
_solutionEventMonitor?.Dispose();
_solutionEventMonitor = null;

base.Dispose(disposing);
}
Expand Down
Loading