Skip to content

Commit 70b19fa

Browse files
authored
Merge pull request #21419 from unoplatform/dev/dr/hrInfoRevert
Revert "Merge pull request #21292 from unoplatform/dev/dr/hrInfo"
2 parents 156e7ed + c83e12f commit 70b19fa

File tree

14 files changed

+202
-427
lines changed

14 files changed

+202
-427
lines changed

src/SourceGenerators/Uno.UI.SourceGenerators/RemoteControl/RemoteControlGenerator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public class RemoteControlGenerator : ISourceGenerator
3333
"SolutionDir",
3434
"SolutionExt",
3535
"BuildingInsideVisualStudio",
36-
"UnoPlatformIDE",
3736
"UnoRemoteControlPort",
3837
"UseHostCompilerIfAvailable",
3938
"TargetFramework",

src/SourceGenerators/Uno.UI.Tasks/Content/Uno.UI.Tasks.targets

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@
2020
<UsingTask Condition="'$(_IsUnoUISolution)'==''" AssemblyFile="$(UnoUIMSBuildTasksPath)\Uno.UI.Tasks.v0.dll" TaskName="Uno.UI.Tasks.Assets.RetargetAssets_v0" />
2121
<UsingTask Condition="'$(_IsUnoUISolution)'==''" AssemblyFile="$(UnoUIMSBuildTasksPath)\Uno.UI.Tasks.v0.dll" TaskName="Uno.UI.Tasks.RuntimeAssetsSelector.RuntimeAssetsSelectorTask_v0" />
2222
<UsingTask Condition="'$(_IsUnoUISolution)'==''" AssemblyFile="$(UnoUIMSBuildTasksPath)\Uno.UI.Tasks.v0.dll" TaskName="Uno.UI.Tasks.RuntimeAssetsValidator.RuntimeAssetsValidatorTask_v0" />
23-
<UsingTask Condition="'$(_IsUnoUISolution)'==''" AssemblyFile="$(UnoUIMSBuildTasksPath)\Uno.UI.Tasks.v0.dll" TaskName="Uno.UI.Tasks.HotReloadInfo.HotReloadInfoTask_v0" />
2423

2524
<UsingTask Condition="'$(_IsUnoUISolution)'!=''" AssemblyFile="$(UnoUIMSBuildTasksPath)\Uno.UI.Tasks.v0.dll" TaskName="Uno.UI.Tasks.ResourcesGenerator.ResourcesGenerationTask_v0" TaskFactory="TaskHostFactory"/>
2625
<UsingTask Condition="'$(_IsUnoUISolution)'!=''" AssemblyFile="$(UnoUIMSBuildTasksPath)\Uno.UI.Tasks.v0.dll" TaskName="Uno.UI.Tasks.ResourcesGenerator.UpriFeaturesGeneratorTask_v0" TaskFactory="TaskHostFactory"/>
2726
<UsingTask Condition="'$(_IsUnoUISolution)'!=''" AssemblyFile="$(UnoUIMSBuildTasksPath)\Uno.UI.Tasks.v0.dll" TaskName="Uno.UI.Tasks.ResourcesGenerator.UpriSubstitutionsGeneratorTask_v0" TaskFactory="TaskHostFactory" />
2827
<UsingTask Condition="'$(_IsUnoUISolution)'!=''" AssemblyFile="$(UnoUIMSBuildTasksPath)\Uno.UI.Tasks.v0.dll" TaskName="Uno.UI.Tasks.Assets.RetargetAssets_v0" TaskFactory="TaskHostFactory" />
2928
<UsingTask Condition="'$(_IsUnoUISolution)'!=''" AssemblyFile="$(UnoUIMSBuildTasksPath)\Uno.UI.Tasks.v0.dll" TaskName="Uno.UI.Tasks.RuntimeAssetsSelector.RuntimeAssetsSelectorTask_v0" TaskFactory="TaskHostFactory" />
3029
<UsingTask Condition="'$(_IsUnoUISolution)'!=''" AssemblyFile="$(UnoUIMSBuildTasksPath)\Uno.UI.Tasks.v0.dll" TaskName="Uno.UI.Tasks.RuntimeAssetsValidator.RuntimeAssetsValidatorTask_v0" TaskFactory="TaskHostFactory" />
31-
<UsingTask Condition="'$(_IsUnoUISolution)'!=''" AssemblyFile="$(UnoUIMSBuildTasksPath)\Uno.UI.Tasks.v0.dll" TaskName="Uno.UI.Tasks.HotReloadInfo.HotReloadInfoTask_v0" TaskFactory="TaskHostFactory" />
3230

3331
<Target Name="_UnoLangSetup">
3432
<!-- String resources -->
@@ -424,22 +422,4 @@
424422
</Task>
425423
</UsingTask>
426424

427-
<Target
428-
Name="_GenerateHotReloadInfo"
429-
BeforeTargets="BeforeCompile"
430-
Condition="'$(Configuration)'=='Debug' OR '$(UnoForceHotReloadCodeGen)' == 'true'">
431-
432-
<HotReloadInfoTask_v0
433-
IntermediateOutputPath="$(IntermediateOutputPath)">
434-
<Output
435-
TaskParameter="GeneratedFiles"
436-
ItemName="_HotReloadInfoTaskGeneratedFiles" />
437-
</HotReloadInfoTask_v0>
438-
439-
<ItemGroup>
440-
<Compile Include="@(_HotReloadInfoTaskGeneratedFiles)" />
441-
</ItemGroup>
442-
443-
</Target>
444-
445425
</Project>

src/SourceGenerators/Uno.UI.Tasks/HotReloadInfo/HotReloadInfoTask.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/SourceGenerators/Uno.UI.Tasks/Uno.UI.Tasks.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
<Link>Resources\AndroidResourceNameEncoder.cs</Link>
3434
</Compile>
3535
<Compile Include="..\Uno.UI.SourceGenerators\BindableTypeProviders\LinkerHintsHelpers.cs" Link="Helpers\LinkerHintsHelpers.cs" />
36-
<Compile Include="..\..\Uno.UI.RemoteControl\HotReload\HotReloadInfoHelper.cs" Link="HotReloadInfo/%(Filename)%(Extension)" />
37-
3836
</ItemGroup>
3937

4038
<Target Name="_copyUnoTasksBuildTime" AfterTargets="Build">

src/Uno.UI.RemoteControl.Messaging/IDEChannel/DevelopmentEnvironmentStatusIdeMessage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public record DevelopmentEnvironmentStatusIdeMessage(
1818
string? Description,
1919
string? Details,
2020
string? ErrorTrace,
21-
Command[] Actions);
21+
Command[] Actions) : IdeMessage("udei");
2222

2323
/// <summary>
2424
/// Represents a component within the development environment, including its identifier and description.

src/Uno.UI.RemoteControl.Messaging/IdeChannel/Command.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,4 @@ namespace Uno.UI.RemoteControl.Messaging.IdeChannel;
1010
/// <param name="Text">Text content to display to the user.</param>
1111
/// <param name="Name">The name/id of the command (e.g. uno.hotreload.open_hotreload_window).</param>
1212
/// <param name="Parameter">A json serialized parameter to execute the command.</param>
13-
public record Command(string Text, string Name, string? Parameter = null)
14-
{
15-
/// <summary>
16-
/// Creates a command that requests to the IDE to open a link in the browser (internal or external).
17-
/// </summary>
18-
/// <param name="Text">User-friendly text for the link.</param>
19-
/// <param name="Uri">Uri to navigate to.</param>
20-
/// <returns></returns>
21-
public Command OpenBrowser(string Text, Uri Uri)
22-
=> new(Text, "ide.open_browser", Uri.ToString());
23-
}
13+
public record Command(string Text, string Name, string? Parameter = null);

src/Uno.UI.RemoteControl.Server.Processors/HotReload/ServerHotReloadProcessor.MetadataUpdate.cs

Lines changed: 77 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ partial class ServerHotReloadProcessor : IServerProcessor, IDisposable
2727
private static readonly StringComparer _pathsComparer = OperatingSystem.IsWindows() ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal;
2828
private static readonly StringComparison _pathsComparison = OperatingSystem.IsWindows() ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
2929

30-
private bool _sendUpdatesThruDebugger;
3130
private FileSystemWatcher[]? _solutionWatchers;
3231
private IDisposable? _solutionWatcherEventsDisposable;
3332

@@ -36,12 +35,24 @@ partial class ServerHotReloadProcessor : IServerProcessor, IDisposable
3635
private WatchHotReloadService? _hotReloadService;
3736
private IReporter _reporter = new Reporter();
3837

39-
private bool InitializeMetadataUpdater(ConfigureServer configureServer)
38+
private bool _useRoslynHotReload;
39+
private bool _useHotReloadThruDebugger;
40+
41+
private bool InitializeMetadataUpdater(ConfigureServer configureServer, Dictionary<string, string> properties)
4042
{
41-
if (configureServer.EnableMetadataUpdates)
43+
_ = bool.TryParse(_remoteControlServer.GetServerConfiguration("metadata-updates"), out _useRoslynHotReload);
44+
45+
_useRoslynHotReload = _useRoslynHotReload || configureServer.EnableMetadataUpdates;
46+
_useHotReloadThruDebugger = configureServer.EnableHotReloadThruDebugger;
47+
48+
if (_useRoslynHotReload)
4249
{
43-
_sendUpdatesThruDebugger = configureServer.EnableHotReloadThruDebugger;
44-
InitializeInner(configureServer);
50+
// Assembly registrations must be done before the workspace is initialized
51+
// Not doing so will cause the roslyn msbuild workspace to fail to load because
52+
// of a missing path on assemblies loaded from a memory stream.
53+
CompilationWorkspaceProvider.RegisterAssemblyLoader();
54+
55+
InitializeInner(configureServer, properties);
4556

4657
return true;
4758
}
@@ -51,47 +62,28 @@ private bool InitializeMetadataUpdater(ConfigureServer configureServer)
5162
}
5263
}
5364

54-
private void InitializeInner(ConfigureServer configureServer)
65+
private void InitializeInner(ConfigureServer configureServer, Dictionary<string, string> properties)
5566
{
56-
try
67+
if (Assembly.Load("Microsoft.CodeAnalysis.Workspaces") is { } wsAsm)
5768
{
58-
// Assembly registrations must be done before the workspace is initialized
59-
// Not doing so will cause the roslyn msbuild workspace to fail to load because
60-
// of a missing path on assemblies loaded from a memory stream.
61-
CompilationWorkspaceProvider.RegisterAssemblyLoader();
62-
63-
if (Assembly.Load("Microsoft.CodeAnalysis.Workspaces") is { } wsAsm)
69+
// If this assembly was loaded from a stream, it will not have a location.
70+
// This will indicate that the assembly loader from CompilationWorkspaceProvider
71+
// has been registered too late.
72+
if (string.IsNullOrEmpty(wsAsm.Location))
6473
{
65-
// If this assembly was loaded from a stream, it will not have a location.
66-
// This will indicate that the assembly loader from CompilationWorkspaceProvider
67-
// has been registered too late.
68-
if (string.IsNullOrEmpty(wsAsm.Location))
69-
{
70-
throw new InvalidOperationException("Microsoft.CodeAnalysis.Workspaces was loaded from a stream and must loaded from a known path");
71-
}
74+
throw new InvalidOperationException("Microsoft.CodeAnalysis.Workspaces was loaded from a stream and must loaded from a known path");
7275
}
73-
74-
CompilationWorkspaceProvider.InitializeRoslyn(Path.GetDirectoryName(configureServer.ProjectPath));
75-
76-
_initializeTask = Task.Run(InitializeAsync, CancellationToken.None);
7776
}
78-
catch
79-
{
80-
_ = _remoteControlServer.SendFrame(new HotReloadWorkspaceLoadResult { WorkspaceInitialized = false });
81-
_ = Notify(HotReloadEvent.Disabled);
8277

83-
throw;
84-
}
78+
CompilationWorkspaceProvider.InitializeRoslyn(Path.GetDirectoryName(configureServer.ProjectPath));
8579

86-
async Task<(Solution, WatchHotReloadService)> InitializeAsync()
80+
_initializeTask = Task.Run(
81+
async () =>
8782
{
8883
try
8984
{
9085
await Notify(HotReloadEvent.Initializing);
9186

92-
// Clone the properties from the ConfigureServer
93-
var properties = configureServer.MSBuildProperties.ToDictionary();
94-
9587
// Flag the current build as created for hot reload, which allows for running targets or settings
9688
// props/items in the context of the hot reload workspace.
9789
properties["UnoIsHotReloadHost"] = "True";
@@ -141,31 +133,32 @@ private void InitializeInner(ConfigureServer configureServer)
141133

142134
throw;
143135
}
144-
}
136+
},
137+
CancellationToken.None);
145138
}
146139

147140
private void ObserveSolutionPaths(Solution solution, params string?[] excludedDir)
148141
{
149-
var observedPaths = solution
150-
.Projects
151-
.SelectMany(project =>
152-
{
153-
var projectDir = Path.GetDirectoryName(project.FilePath);
154-
ImmutableArray<string> excludedProjectDir = [.. from dir in excludedDir where dir is not null select Path.Combine(projectDir!, dir).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)];
155-
156-
var paths = project
157-
.Documents
158-
.Select(d => d.FilePath)
159-
.Concat(project.AdditionalDocuments.Select(d => d.FilePath))
160-
.Select(Path.GetDirectoryName)
161-
.Where(path => path is not null && !excludedProjectDir.Any(dir => path.StartsWith(dir, _pathsComparison)))
162-
.Distinct()
163-
.ToArray();
164-
165-
return paths;
166-
})
167-
.Distinct()
168-
.ToArray();
142+
var observedPaths =
143+
solution.Projects
144+
.SelectMany(project =>
145+
{
146+
var projectDir = Path.GetDirectoryName(project.FilePath);
147+
ImmutableArray<string> excludedProjectDir = [.. from dir in excludedDir where dir is not null select Path.Combine(projectDir!, dir).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)];
148+
149+
var paths = project
150+
.Documents
151+
.Select(d => d.FilePath)
152+
.Concat(project.AdditionalDocuments.Select(d => d.FilePath))
153+
.Select(Path.GetDirectoryName)
154+
.Where(path => path is not null && !excludedProjectDir.Any(dir => path.StartsWith(dir, _pathsComparison)))
155+
.Distinct()
156+
.ToArray();
157+
158+
return paths;
159+
})
160+
.Distinct()
161+
.ToArray();
169162

170163
#if DEBUG
171164
Console.WriteLine($"Observing paths {string.Join(", ", observedPaths)}");
@@ -277,46 +270,40 @@ private async ValueTask ProcessSolutionChanged(HotReloadServerOperation hotReloa
277270
_reporter.Output($"Found {updates.Length} metadata updates after {sw.Elapsed}");
278271
sw.Stop();
279272

280-
switch (rudeEdits.IsEmpty, updates.IsEmpty)
281-
{
282-
case (true, true):
283-
{
284-
var compilationErrors = GetCompilationErrors(solution, ct);
285-
if (compilationErrors.IsEmpty)
286-
{
287-
_reporter.Output("No hot reload changes to apply.");
288-
await hotReload.Complete(HotReloadServerResult.NoChanges);
289-
}
290-
else
291-
{
292-
await hotReload.Complete(HotReloadServerResult.Failed);
293-
}
294-
}
295-
break;
296273

297-
case (false, _):
298-
{
299-
// Rude edit.
300-
_reporter.Output("Unable to apply hot reload because of a rude edit.");
301-
foreach (var diagnostic in hotReloadDiagnostics)
302-
{
303-
_reporter.Verbose(CSharpDiagnosticFormatter.Instance.Format(diagnostic, CultureInfo.InvariantCulture));
304-
}
274+
if (rudeEdits.IsEmpty && updates.IsEmpty)
275+
{
276+
var compilationErrors = GetCompilationErrors(solution, ct);
277+
if (compilationErrors.IsEmpty)
278+
{
279+
_reporter.Output("No hot reload changes to apply.");
280+
await hotReload.Complete(HotReloadServerResult.NoChanges);
281+
}
282+
else
283+
{
284+
await hotReload.Complete(HotReloadServerResult.Failed);
285+
}
305286

306-
await hotReload.Complete(HotReloadServerResult.RudeEdit);
307-
}
308-
break;
287+
return;
288+
}
309289

310-
//case (true, false):
311-
default:
312-
{
313-
await SendUpdates(updates);
290+
if (!rudeEdits.IsEmpty)
291+
{
292+
// Rude edit.
293+
_reporter.Output("Unable to apply hot reload because of a rude edit.");
294+
foreach (var diagnostic in hotReloadDiagnostics)
295+
{
296+
_reporter.Verbose(CSharpDiagnosticFormatter.Instance.Format(diagnostic, CultureInfo.InvariantCulture));
297+
}
314298

315-
await hotReload.Complete(HotReloadServerResult.Success);
316-
}
317-
break;
299+
await hotReload.Complete(HotReloadServerResult.RudeEdit);
300+
return;
318301
}
319302

303+
await SendUpdates(updates);
304+
305+
await hotReload.Complete(HotReloadServerResult.Success);
306+
320307
async Task SendUpdates(ImmutableArray<WatchHotReloadService.Update> updates)
321308
{
322309
#if DEBUG
@@ -325,7 +312,7 @@ async Task SendUpdates(ImmutableArray<WatchHotReloadService.Update> updates)
325312

326313
for (var i = 0; i < updates.Length; i++)
327314
{
328-
if (_sendUpdatesThruDebugger)
315+
if (_useHotReloadThruDebugger)
329316
{
330317
await _remoteControlServer.SendMessageToIDEAsync(
331318
new Uno.UI.RemoteControl.Messaging.IdeChannel.HotReloadThruDebuggerIdeMessage(

0 commit comments

Comments
 (0)