-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add mixed C#/XAML hot reload support
- Loading branch information
1 parent
d42524b
commit 6d3ec36
Showing
21 changed files
with
429 additions
and
133 deletions.
There are no files selected for viewing
This file contains 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
src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationInfo.cs
This file contains 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 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
|
||
namespace Uno.UI.SourceGenerators.XamlGenerator | ||
{ | ||
internal class GenerationRunInfo | ||
{ | ||
private ConcurrentDictionary<string, GenerationRunFileInfo> _fileInfo = new ConcurrentDictionary<string, GenerationRunFileInfo>(); | ||
|
||
internal GenerationRunInfo(GenerationRunInfoManager manager, int index) | ||
{ | ||
Index = index; | ||
Manager = manager; | ||
} | ||
|
||
internal GenerationRunInfoManager Manager { get; } | ||
|
||
internal int Index { get; } | ||
|
||
internal GenerationRunFileInfo GetRunFileInfo(string fileId) | ||
=> _fileInfo.GetOrAdd(fileId, f => new GenerationRunFileInfo(this, f)); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationInfoManager.cs
This file contains 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,60 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Uno.Roslyn; | ||
|
||
#if NETFRAMEWORK | ||
using Uno.SourceGeneration; | ||
#endif | ||
|
||
namespace Uno.UI.SourceGenerators.XamlGenerator | ||
{ | ||
internal class GenerationRunInfoManager | ||
{ | ||
private List<GenerationRunInfo> _runs = new List<GenerationRunInfo>(); | ||
private DateTime _previousWriteTime; | ||
|
||
internal GenerationRunInfoManager() | ||
{ | ||
} | ||
|
||
public IEnumerable<GenerationRunInfo> PreviousRuns | ||
=> _runs.AsEnumerable(); | ||
|
||
internal GenerationRunInfo CreateRun() | ||
{ | ||
var runInfo = new GenerationRunInfo(this, _runs.Count); | ||
|
||
_runs.Add(runInfo); | ||
|
||
return runInfo; | ||
} | ||
|
||
internal void Update(GeneratorExecutionContext context) | ||
{ | ||
var intermediateOutputPath = context.GetMSBuildPropertyValue("IntermediateOutputPath"); | ||
|
||
if (intermediateOutputPath != null) | ||
{ | ||
var runFilePath = Path.Combine(intermediateOutputPath, "build-time-generator.touch"); | ||
|
||
if (File.Exists(runFilePath)) | ||
{ | ||
var lastWriteTime = new FileInfo(runFilePath).LastWriteTime; | ||
|
||
if(lastWriteTime > _previousWriteTime) | ||
{ | ||
_previousWriteTime = lastWriteTime; | ||
|
||
// Clear the existing runs if a full build has been started | ||
_runs.Clear(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationRunFileInfo.cs
This file contains 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,34 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Uno.UI.SourceGenerators.XamlGenerator | ||
{ | ||
internal class GenerationRunFileInfo | ||
{ | ||
private string _fileId; | ||
private Dictionary<INamedTypeSymbol, int> _appliedTypes = new Dictionary<INamedTypeSymbol, int>(); | ||
|
||
public GenerationRunFileInfo(GenerationRunInfo runInfo,string fileId) | ||
{ | ||
_fileId = fileId; | ||
RunInfo = runInfo; | ||
} | ||
|
||
internal GenerationRunInfo RunInfo { get; } | ||
|
||
internal string? ComponentCode { get; set; } | ||
|
||
internal IReadOnlyDictionary<INamedTypeSymbol, int> AppliedTypes => _appliedTypes; | ||
|
||
internal void SetAppliedTypes(Dictionary<INamedTypeSymbol, int> appliedTypes) | ||
{ | ||
foreach(var type in appliedTypes) | ||
{ | ||
_appliedTypes.Add(type.Key, type.Value); | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.