Skip to content

Commit

Permalink
Capture file content on open instead of save (dotnet#54643)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Jul 7, 2021
1 parent 9be3cfd commit 32bc44a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 63 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Connects <see cref="VisualStudioWorkspace"/> to the ServiceHub services.
/// Launches ServiceHub if it is not running yet and starts services that push information from <see cref="VisualStudioWorkspace"/> to the ServiceHub process.
/// </summary>
[ExportEventListener(WellKnownEventListeners.Workspace, WorkspaceKind.Host), Shared]
internal sealed class VisualStudioWorkspaceEditAndContinueListener : IEventListener<object>, 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();
}
}
}

0 comments on commit 32bc44a

Please sign in to comment.