-
Notifications
You must be signed in to change notification settings - Fork 402
Switch to dotnet-watch delta appliers #9758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+687
−100
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...Studio.ProjectSystem.Managed.VS/ProjectSystem/VS/HotReload/HotReloadDebugStateProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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.md file in the project root for more information. | ||
|
||
using Microsoft.VisualStudio.ProjectSystem.HotReload; | ||
using Microsoft.VisualStudio.Shell.Interop; | ||
|
||
namespace Microsoft.VisualStudio.ProjectSystem.VS.HotReload; | ||
|
||
// TODO: Replace with IDebuggerStateService | ||
// https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2571211 | ||
|
||
[Export(typeof(IHotReloadDebugStateProvider))] | ||
[method: ImportingConstructor] | ||
internal sealed class HotReloadDebugStateProvider( | ||
IProjectThreadingService threadingService, | ||
IVsUIService<SVsShellDebugger, IVsDebugger> debugger) : IHotReloadDebugStateProvider | ||
{ | ||
public async ValueTask<bool> IsSuspendedAsync(CancellationToken cancellationToken) | ||
{ | ||
await threadingService.SwitchToUIThread(cancellationToken); | ||
|
||
var dbgmode = new DBGMODE[1]; | ||
return ErrorHandler.Succeeded(debugger.Value.GetMode(dbgmode)) && | ||
(dbgmode[0] & ~DBGMODE.DBGMODE_EncMask) == DBGMODE.DBGMODE_Break; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...o.ProjectSystem.Managed.VS/ProjectSystem/VS/HotReload/VisualStudioBrowserRefreshServer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// 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.md file in the project root for more information. | ||
|
||
using System.Net; | ||
using Microsoft.DotNet.HotReload; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.VisualStudio.Threading; | ||
|
||
namespace Microsoft.VisualStudio.ProjectSystem.HotReload; | ||
|
||
internal sealed class VisualStudioBrowserRefreshServer( | ||
ILogger logger, | ||
ILoggerFactory loggerFactory, | ||
string projectName, | ||
int port, | ||
int sslPort, | ||
string virtualDirectory) | ||
: AbstractBrowserRefreshServer(GetMiddlewareAssemblyPath(), logger, loggerFactory) | ||
{ | ||
private const string MiddlewareTargetFramework = "net6.0"; | ||
|
||
private static string GetMiddlewareAssemblyPath() | ||
=> ProjectHotReloadSession.GetInjectedAssemblyPath(MiddlewareTargetFramework, "Microsoft.AspNetCore.Watch.BrowserRefresh"); | ||
|
||
protected override bool SuppressTimeouts | ||
=> false; | ||
|
||
// for testing | ||
internal Task? WebSocketListeningTask { get; private set; } | ||
|
||
protected override ValueTask<WebServerHost> CreateAndStartHostAsync(CancellationToken cancellationToken) | ||
{ | ||
var httpListener = CreateListener(projectName, port, sslPort); | ||
WebSocketListeningTask = ListenAsync(cancellationToken); | ||
|
||
return new(new WebServerHost(httpListener, GetWebSocketUrls(projectName, port, sslPort), virtualDirectory)); | ||
|
||
async Task ListenAsync(CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
httpListener.Start(); | ||
|
||
while (!cancellationToken.IsCancellationRequested) | ||
{ | ||
Logger.LogDebug("Waiting for a browser connection"); | ||
|
||
// wait for incoming request: | ||
var context = await httpListener.GetContextAsync(); | ||
if (!context.Request.IsWebSocketRequest) | ||
{ | ||
context.Response.StatusCode = 400; | ||
context.Response.Close(); | ||
continue; | ||
} | ||
|
||
try | ||
{ | ||
// Accepting Socket Next request. If the context has a "Sec-WebSocket-Protocol" header it passes back in the AcceptWebSocket | ||
var protocol = context.Request.Headers["Sec-WebSocket-Protocol"]; | ||
var webSocketContext = await context.AcceptWebSocketAsync(subProtocol: protocol).WithCancellation(cancellationToken); | ||
|
||
_ = OnBrowserConnected(webSocketContext.WebSocket, webSocketContext.SecWebSocketProtocols.FirstOrDefault()); | ||
} | ||
catch (Exception e) | ||
{ | ||
Logger.LogError("Accepting web socket exception: {Message}", e.Message); | ||
|
||
context.Response.StatusCode = 500; | ||
context.Response.Close(); | ||
} | ||
} | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
// nop | ||
} | ||
catch (Exception e) | ||
{ | ||
Logger.LogError("HttpListener exception: {Message}", e.Message); | ||
} | ||
} | ||
} | ||
|
||
private static HttpListener CreateListener(string projectName, int port, int sslPort) | ||
{ | ||
var httpListener = new HttpListener(); | ||
|
||
httpListener.Prefixes.Add($"http://localhost:{port}/{projectName}/"); | ||
if (sslPort >= 0) | ||
{ | ||
httpListener.Prefixes.Add($"https://localhost:{sslPort}/{projectName}/"); | ||
} | ||
|
||
return httpListener; | ||
} | ||
|
||
private static ImmutableArray<string> GetWebSocketUrls(string projectName, int port, int sslPort) | ||
{ | ||
return sslPort >= 0 ? [GetWebSocketUrl(port, isSecure: false), GetWebSocketUrl(sslPort, isSecure: true)] : [GetWebSocketUrl(port, isSecure: false)]; | ||
|
||
string GetWebSocketUrl(int port, bool isSecure) | ||
=> $"{(isSecure ? "wss" : "ws")}://localhost:{port}/{projectName}/"; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ProjectSystem.Managed.VS/ProjectSystem/VS/Web/VisualStudioBrowserRefreshServerAccessor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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.md file in the project root for more information. | ||
|
||
using Microsoft.DotNet.HotReload; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.VisualStudio.ProjectSystem.HotReload; | ||
using Microsoft.VisualStudio.ProjectSystem.VS.HotReload; | ||
|
||
namespace Microsoft.VisualStudio.ProjectSystem.VS.Web; | ||
|
||
public sealed class VisualStudioBrowserRefreshServerAccessor( | ||
ILogger logger, | ||
ILoggerFactory loggerFactory, | ||
string projectName, | ||
int port, | ||
int sslPort, | ||
string virtualDirectory) | ||
: AbstractBrowserRefreshServerAccessor | ||
{ | ||
internal override AbstractBrowserRefreshServer Server { get; } = new VisualStudioBrowserRefreshServer( | ||
logger, | ||
loggerFactory, | ||
projectName, | ||
port, | ||
sslPort, | ||
virtualDirectory); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/PublicAPI.Unshipped.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
Microsoft.VisualStudio.ProjectSystem.VS.Debug.IDebugProfileLaunchTargetsProvider5 | ||
Microsoft.VisualStudio.ProjectSystem.VS.Debug.IDebugProfileLaunchTargetsProvider5.OnAfterLaunchAsync(Microsoft.VisualStudio.ProjectSystem.Debug.DebugLaunchOptions launchOptions, Microsoft.VisualStudio.ProjectSystem.Debug.ILaunchProfile! profile, Microsoft.VisualStudio.ProjectSystem.VS.Debug.IDebugLaunchSettings! debugLaunchSetting, Microsoft.VisualStudio.Debugger.Interop.IVsLaunchedProcess! vsLaunchedProcess, Microsoft.VisualStudio.Shell.Interop.VsDebugTargetProcessInfo processInfo) -> System.Threading.Tasks.Task! | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...tSystem.Managed/ProjectSystem/HotReload/Contracts/AbstractBrowserRefreshServerAccessor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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.md file in the project root for more information. | ||
|
||
using Microsoft.DotNet.HotReload; | ||
|
||
namespace Microsoft.VisualStudio.ProjectSystem.VS.HotReload; | ||
|
||
public abstract class AbstractBrowserRefreshServerAccessor : IDisposable | ||
{ | ||
private protected AbstractBrowserRefreshServerAccessor() | ||
{ | ||
} | ||
|
||
public void Dispose() | ||
=> Server.Dispose(); | ||
|
||
public ValueTask StartServerAsync(CancellationToken cancellationToken) | ||
=> Server.StartAsync(cancellationToken); | ||
|
||
public void ConfigureLaunchEnvironment(IDictionary<string, string> builder, bool enableHotReload) | ||
=> Server.ConfigureLaunchEnvironment(builder, enableHotReload); | ||
|
||
public ValueTask RefreshBrowserAsync(CancellationToken cancellationToken) | ||
=> Server.RefreshBrowserAsync(cancellationToken); | ||
|
||
public ValueTask SendPingMessageAsync(CancellationToken cancellationToken) | ||
=> Server.SendPingMessageAsync(cancellationToken); | ||
|
||
public ValueTask SendReloadMessageAsync(CancellationToken cancellationToken) | ||
=> Server.SendReloadMessageAsync(cancellationToken); | ||
|
||
public ValueTask SendWaitMessageAsync(CancellationToken cancellationToken) | ||
=> Server.SendWaitMessageAsync(cancellationToken); | ||
|
||
public ValueTask UpdateStaticAssetsAsync(IEnumerable<string> relativeUrls, CancellationToken cancellationToken) | ||
=> Server.UpdateStaticAssetsAsync(relativeUrls, cancellationToken); | ||
|
||
internal abstract AbstractBrowserRefreshServer Server { get; } | ||
} |
8 changes: 8 additions & 0 deletions
8
....Managed/ProjectSystem/HotReload/Contracts/IProjectHotReloadSessionWebAssemblyCallback.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// 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.md file in the project root for more information. | ||
|
||
namespace Microsoft.VisualStudio.ProjectSystem.VS.HotReload; | ||
|
||
public interface IProjectHotReloadSessionWebAssemblyCallback : IProjectHotReloadSessionCallback | ||
{ | ||
AbstractBrowserRefreshServerAccessor BrowserRefreshServerAccessor { get; } | ||
} |
12 changes: 12 additions & 0 deletions
12
...udio.ProjectSystem.Managed/ProjectSystem/HotReload/Contracts/ISuppressDeltaApplication.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// 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.md file in the project root for more information. | ||
|
||
namespace Microsoft.VisualStudio.ProjectSystem.VS.HotReload; | ||
|
||
/// <summary> | ||
/// Allows <see cref="IProjectHotReloadSessionCallback"/> to specify whether to suppresses application of deltas | ||
/// as a workaround for https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2570151 | ||
/// </summary> | ||
public interface ISuppressDeltaApplication | ||
{ | ||
bool SuppressDeltaApplication { get; } | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.