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
2 changes: 2 additions & 0 deletions src/BuiltInTools/dotnet-watch/DotNetWatchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public record DotNetWatchOptions(
bool SuppressMSBuildIncrementalism,
bool SuppressLaunchBrowser,
bool SuppressBrowserRefresh,
bool SuppressEmojis,
bool RunningAsTest)
{
public static DotNetWatchOptions Default { get; } = new DotNetWatchOptions
Expand All @@ -18,6 +19,7 @@ public record DotNetWatchOptions(
SuppressMSBuildIncrementalism: IsEnvironmentSet("DOTNET_WATCH_SUPPRESS_MSBUILD_INCREMENTALISM"),
SuppressLaunchBrowser: IsEnvironmentSet("DOTNET_WATCH_SUPPRESS_LAUNCH_BROWSER"),
SuppressBrowserRefresh: IsEnvironmentSet("DOTNET_WATCH_SUPPRESS_BROWSER_REFRESH"),
SuppressEmojis: IsEnvironmentSet("DOTNET_WATCH_SUPPRESS_EMOJIS"),
RunningAsTest: IsEnvironmentSet("__DOTNET_WATCH_RUNNING_AS_TEST")
);

Expand Down
6 changes: 3 additions & 3 deletions src/BuiltInTools/dotnet-watch/DotNetWatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -93,7 +93,7 @@ public async Task WatchAsync(DotNetWatchContext context, CancellationToken cance
var args = string.Join(" ", processSpec.Arguments);
_reporter.Verbose($"Running {processSpec.ShortDisplayName()} with the following arguments: {args}");

_reporter.Output("Started");
_reporter.Output("Started", emoji: "🚀");

Task<FileItem?> fileSetTask;
Task finishedTask;
Expand Down Expand Up @@ -141,7 +141,7 @@ await _staticFileHandler.TryHandleFileChange(context, fileItem, combinedCancella
// Process exited. Redo evaludation
context.RequiresMSBuildRevaluation = true;
// Now wait for a file to change before restarting process
context.ChangedFile = await fileSetWatcher.GetChangedFileAsync(cancellationToken, () => _reporter.Warn("Waiting for a file to change before restarting dotnet..."));
context.ChangedFile = await fileSetWatcher.GetChangedFileAsync(cancellationToken, () => _reporter.Warn("Waiting for a file to change before restarting dotnet...", emoji: "⏳"));
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/BuiltInTools/dotnet-watch/Filters/DotNetBuildFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async ValueTask ProcessAsync(DotNetWatchContext context, CancellationToke
WorkingDirectory = context.ProcessSpec.WorkingDirectory,
};

_reporter.Output("Building...");
_reporter.Output("Building...", emoji: "🔧");
var exitCode = await _processRunner.RunAsync(processSpec, cancellationToken);
context.FileSet = await _fileSetFactory.CreateAsync(cancellationToken);
if (exitCode == 0)
Expand All @@ -48,7 +48,7 @@ public async ValueTask ProcessAsync(DotNetWatchContext context, CancellationToke

// If the build fails, we'll retry until we have a successful build.
using var fileSetWatcher = new FileSetWatcher(context.FileSet, _reporter);
await fileSetWatcher.GetChangedFileAsync(cancellationToken, () => _reporter.Warn("Waiting for a file to change before restarting dotnet..."));
await fileSetWatcher.GetChangedFileAsync(cancellationToken, () => _reporter.Warn("Waiting for a file to change before restarting dotnet...", emoji: "⏳"));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/BuiltInTools/dotnet-watch/Filters/LaunchBrowserFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -97,7 +97,7 @@ private void OnOutput(object sender, DataReceivedEventArgs eventArgs)
// From emperical observation, it's noted that failing to launch a browser results in either Process.Start returning a null-value
// or for the process to have immediately exited.
// We can use this to provide a helpful message.
_reporter.Output($"Unable to launch the browser. Navigate to {launchUrl}");
_reporter.Output($"Unable to launch the browser. Navigate to {launchUrl}", emoji: "🌐");
}
}
else if (_watchContext?.BrowserRefreshServer is { } browserRefresh)
Expand Down
4 changes: 2 additions & 2 deletions src/BuiltInTools/dotnet-watch/HotReload/CompilationHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable
Expand Down Expand Up @@ -171,7 +171,7 @@ public async ValueTask<bool> TryHandleFileChange(DotNetWatchContext context, Fil
HotReloadEventSource.Log.HotReloadEnd(HotReloadEventSource.StartType.CompilationHandler);
if (applyState)
{
_reporter.Output($"Hot reload of changes succeeded.");
_reporter.Output($"Hot reload of changes succeeded.", emoji: "🔥");
}

return applyState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static async Task<ImmutableArray<string>> GetHotReloadCapabilitiesAsync(
try
{
var capabilities = await hotReloadCapabilitiesTask;
reporter.Verbose($"Hot reload capabilities: {string.Join(" ", capabilities)}.");
reporter.Verbose($"Hot reload capabilities: {string.Join(" ", capabilities)}.", emoji: "🔥");

return capabilities;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public static HotReloadProfile InferHotReloadProfile(ProjectGraph projectGraph,
// We saw a previous project that was AspNetCore. This must he a blazor hosted app.
if (aspnetCoreProject is not null && aspnetCoreProject != currentNode.ProjectInstance)
{
reporter.Verbose($"HotReloadProfile: BlazorHosted. {aspnetCoreProject.FullPath} references BlazorWebAssembly project {currentNode.ProjectInstance.FullPath}.");
reporter.Verbose($"HotReloadProfile: BlazorHosted. {aspnetCoreProject.FullPath} references BlazorWebAssembly project {currentNode.ProjectInstance.FullPath}.", emoji: "🔥");
return HotReloadProfile.BlazorHosted;
}

reporter.Verbose("HotReloadProfile: BlazorWebAssembly.");
reporter.Verbose("HotReloadProfile: BlazorWebAssembly.", emoji: "🔥");
return HotReloadProfile.BlazorWebAssembly;
}
}
Expand All @@ -50,7 +50,7 @@ public static HotReloadProfile InferHotReloadProfile(ProjectGraph projectGraph,
}
}

reporter.Verbose("HotReloadProfile: Default.");
reporter.Verbose("HotReloadProfile: Default.", emoji: "🔥");
return HotReloadProfile.Default;
}
}
Expand Down
83 changes: 83 additions & 0 deletions src/BuiltInTools/dotnet-watch/HotReload/RudeEditDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Tools.Internal;

namespace Microsoft.DotNet.Watcher.Tools
{
public class RudeEditDialog
{
private readonly IReporter _reporter;
private readonly IRequester _requester;
private readonly IConsole _console;
private bool? _restartImmediatelySessionPreference; // Session preference

public RudeEditDialog(IReporter reporter, IRequester requester, IConsole console)
{
_reporter = reporter;
_requester = requester;
_console = console;

var alwaysRestart = Environment.GetEnvironmentVariable("DOTNET_WATCH_RESTART_ON_RUDE_EDIT");

if (alwaysRestart == "1" || string.Equals(alwaysRestart, "true", StringComparison.OrdinalIgnoreCase))
{
_reporter.Verbose($"DOTNET_WATCH_RESTART_ON_RUDE_EDIT = '{alwaysRestart}'. Restarting without prompt.");
_restartImmediatelySessionPreference = true;
}
}

public async Task EvaluateAsync(CancellationToken cancellationToken)
{
if (_restartImmediatelySessionPreference.HasValue)
{
await GetRudeEditResult(_restartImmediatelySessionPreference.Value, cancellationToken);
return;
}

var key = await _requester.GetKeyAsync(
"Do you want to restart your app - Yes (y) / No (n) / Always (a) / Never (v)?",
KeyPressed,
cancellationToken);

switch (key)
{
case ConsoleKey.Escape:
case ConsoleKey.Y:
await GetRudeEditResult(restartImmediately: true, cancellationToken);
return;
case ConsoleKey.N:
await GetRudeEditResult(restartImmediately: false, cancellationToken);
return;
case ConsoleKey.A:
_restartImmediatelySessionPreference = true;
await GetRudeEditResult(restartImmediately: true, cancellationToken);
return;
case ConsoleKey.V:
_restartImmediatelySessionPreference = false;
await GetRudeEditResult(restartImmediately: false, cancellationToken);
return;
}

bool KeyPressed(ConsoleKey key)
{
return key is ConsoleKey.Y or ConsoleKey.N or ConsoleKey.A or ConsoleKey.V;
}
}

private Task GetRudeEditResult(bool restartImmediately, CancellationToken cancellationToken)
{
if (restartImmediately)
{
return Task.CompletedTask;
}

_reporter.Output("Hot reload suspended. To continue hot reload, press \"Ctrl + R\".", emoji: "🔥");

return Task.Delay(-1, cancellationToken);
}
}
}
95 changes: 0 additions & 95 deletions src/BuiltInTools/dotnet-watch/HotReload/RudeEditPreference.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable enable
Expand Down Expand Up @@ -40,7 +40,7 @@ public async ValueTask<bool> TryHandleFileChange(DotNetWatchContext context, Fil
return false;
}
await HandleBrowserRefresh(context.BrowserRefreshServer, file, cancellationToken);
_reporter.Output("Hot reload of scoped css succeeded.");
_reporter.Output("Hot reload of scoped css succeeded.", emoji: "🔥");
HotReloadEventSource.Log.HotReloadEnd(HotReloadEventSource.StartType.ScopedCssHandler);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/BuiltInTools/dotnet-watch/HotReload/StaticFileHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
Expand Down Expand Up @@ -34,7 +34,7 @@ public async ValueTask<bool> TryHandleFileChange(DotNetWatchContext context, Fil
_reporter.Verbose($"Handling file change event for static content {file.FilePath}.");
await HandleBrowserRefresh(context.BrowserRefreshServer, file, cancellationToken);
HotReloadEventSource.Log.HotReloadEnd(HotReloadEventSource.StartType.StaticHandler);
_reporter.Output("Hot reload of static file succeeded.");
_reporter.Output("Hot reload of static file succeeded.", emoji: "🔥");
return true;
}

Expand Down
Loading