diff --git a/src/EditorFeatures/Core/Implementation/EditAndContinue/EditAndContinueSaveFileCommandHandler.cs b/src/EditorFeatures/Core/Implementation/EditAndContinue/EditAndContinueSaveFileCommandHandler.cs deleted file mode 100644 index a8c80e2830e9b..0000000000000 --- a/src/EditorFeatures/Core/Implementation/EditAndContinue/EditAndContinueSaveFileCommandHandler.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.ComponentModel.Composition; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.EditAndContinue; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Text; -using Microsoft.VisualStudio.Commanding; -using Microsoft.VisualStudio.Text.Editor.Commanding.Commands; -using Microsoft.VisualStudio.Utilities; -using Roslyn.Utilities; -using VSCommanding = Microsoft.VisualStudio.Commanding; - -namespace Microsoft.CodeAnalysis.Editor.Implementation.EditAndContinue -{ - [Export] - [Export(typeof(VSCommanding.ICommandHandler))] - [ContentType(ContentTypeNames.RoslynContentType)] - [Name(PredefinedCommandHandlerNames.EditAndContinueFileSave)] - internal sealed class EditAndContinueSaveFileCommandHandler : IChainedCommandHandler - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public EditAndContinueSaveFileCommandHandler() - { - } - - public string DisplayName => PredefinedCommandHandlerNames.EditAndContinueFileSave; - - void IChainedCommandHandler.ExecuteCommand(SaveCommandArgs args, Action nextCommandHandler, CommandExecutionContext executionContext) - { - var textContainer = args.SubjectBuffer.AsTextContainer(); - - if (Workspace.TryGetWorkspace(textContainer, out var workspace)) - { - var documentId = workspace.GetDocumentIdInCurrentContext(textContainer); - if (documentId != null) - { - // ignoring source-generated files since they shouldn't be modified and saved: - var currentDocument = workspace.CurrentSolution.GetDocument(documentId); - if (currentDocument != null) - { - var proxy = new RemoteEditAndContinueServiceProxy(workspace); - - // fire and forget - _ = Task.Run(() => proxy.OnSourceFileUpdatedAsync(currentDocument, CancellationToken.None)).ReportNonFatalErrorAsync(); - } - } - } - - nextCommandHandler(); - } - - public VSCommanding.CommandState GetCommandState(SaveCommandArgs args, Func nextCommandHandler) - => nextCommandHandler(); - } -} - diff --git a/src/Features/Core/Portable/EditAndContinue/EditAndContinueWorkspaceService.cs b/src/Features/Core/Portable/EditAndContinue/EditAndContinueWorkspaceService.cs index 06459d0085077..a2970db04abf6 100644 --- a/src/Features/Core/Portable/EditAndContinue/EditAndContinueWorkspaceService.cs +++ b/src/Features/Core/Portable/EditAndContinue/EditAndContinueWorkspaceService.cs @@ -97,7 +97,7 @@ public void OnSourceFileUpdated(Document document) foreach (var debuggingSession in GetActiveDebuggingSessions()) { // fire and forget - _ = Task.Run(() => debuggingSession.OnSourceFileUpdatedAsync(document)); + _ = Task.Run(() => debuggingSession.OnSourceFileUpdatedAsync(document)).ReportNonFatalErrorAsync(); } } diff --git a/src/VisualStudio/Core/Def/Implementation/EditAndContinue/VisualStudioWorkspaceEditAndContinueListener.cs b/src/VisualStudio/Core/Def/Implementation/EditAndContinue/VisualStudioWorkspaceEditAndContinueListener.cs new file mode 100644 index 0000000000000..bd737a536714d --- /dev/null +++ b/src/VisualStudio/Core/Def/Implementation/EditAndContinue/VisualStudioWorkspaceEditAndContinueListener.cs @@ -0,0 +1,56 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Composition; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.EditAndContinue; +using Microsoft.CodeAnalysis.Host; +using Microsoft.CodeAnalysis.Host.Mef; +using Roslyn.Utilities; + +namespace Microsoft.VisualStudio.LanguageServices.EditAndContinue +{ + /// + /// Connects to the ServiceHub services. + /// Launches ServiceHub if it is not running yet and starts services that push information from to the ServiceHub process. + /// + [ExportEventListener(WellKnownEventListeners.Workspace, WorkspaceKind.Host), Shared] + internal sealed class VisualStudioWorkspaceEditAndContinueListener : IEventListener, IEventListenerStoppable + { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public VisualStudioWorkspaceEditAndContinueListener() + { + } + + public void StartListening(Workspace workspace, object serviceOpt) + { + if (workspace is not VisualStudioWorkspace) + { + return; + } + + workspace.DocumentOpened += WorkspaceDocumentOpened; + } + + public void StopListening(Workspace workspace) + { + if (workspace is not VisualStudioWorkspace) + { + return; + } + + workspace.DocumentOpened -= WorkspaceDocumentOpened; + } + + private void WorkspaceDocumentOpened(object? sender, DocumentEventArgs e) + { + var proxy = new RemoteEditAndContinueServiceProxy(e.Document.Project.Solution.Workspace); + _ = Task.Run(() => proxy.OnSourceFileUpdatedAsync(e.Document, CancellationToken.None)).ReportNonFatalErrorAsync(); + } + } +}