diff --git a/Pages/Index.razor b/Pages/Index.razor index 0e12422..547ab5e 100644 --- a/Pages/Index.razor +++ b/Pages/Index.razor @@ -1,33 +1,38 @@ @page "/" @inject NavigationManager navigationManager -@using BlazorInputFile @using System.Threading - + + @*
+ About +
*@ + + @*
*@ -
+
Program Code
Load
Source Generator
Load
Output
-
Generated Output +
+ Generated Output
Auto @@ -97,7 +102,7 @@ { options.Value = gen; - _ = Update(default); + _ = Update(default); } @@ -158,19 +163,19 @@ await generatorOutput.SetValue(runner.GeneratorOutput); } - private async Task HandleCodeFileSelected(IFileListEntry[] files) + private async Task HandleCodeFileSelected(InputFileChangeEventArgs args) { - await LoadFile(files[0], codeEditor); + await LoadFile(args.File, codeEditor); } - private async Task HandleGeneratorFileSelected(IFileListEntry[] files) + private async Task HandleGeneratorFileSelected(InputFileChangeEventArgs args) { - await LoadFile(files[0], generator); + await LoadFile(args.File, generator); } - private async Task LoadFile(IFileListEntry file, MonacoEditor editor) + private async Task LoadFile(IBrowserFile file, MonacoEditor editor) { - using (var reader = new System.IO.StreamReader(file.Data)) + using (var reader = new System.IO.StreamReader(file.OpenReadStream())) { await editor.SetValue(await reader.ReadToEndAsync()); } diff --git a/Program.cs b/Program.cs index fe97ed1..1da9cfa 100644 --- a/Program.cs +++ b/Program.cs @@ -11,7 +11,7 @@ public class Program public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.RootComponents.Add("app"); + builder.RootComponents.Add("#app"); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); diff --git a/Runner.cs b/Runner.cs index 51612e6..93b53bf 100644 --- a/Runner.cs +++ b/Runner.cs @@ -6,6 +6,7 @@ using System.Net.Http; using System.Reflection; using System.Text; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -14,7 +15,7 @@ namespace SourceGeneratorPlayground { - internal class Runner + public class Runner { private static List? s_references; @@ -35,7 +36,8 @@ internal async Task Run(string baseUri) { if (s_references == null) { - s_references = await GetReferences(baseUri); + //s_references = await GetReferences(baseUri); + s_references = await GetReferencesFromBootDoc(baseUri); } this.ProgramOutput = ""; @@ -227,21 +229,101 @@ private void ExecuteProgram(Assembly programAssembly) return header + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, errors); } - private static async Task> GetReferences(string baseUri) + private async Task> GetReferences(string baseUri) { Assembly[]? refs = AppDomain.CurrentDomain.GetAssemblies(); - var client = new HttpClient + using var client = new HttpClient + { + BaseAddress = new Uri(baseUri) + }; + + using var bootResponse = await client.GetAsync("_framework/blazor.boot.json"); + bootResponse.EnsureSuccessStatusCode(); + using var boot = JsonDocument.Parse(await bootResponse.Content.ReadAsStringAsync()); + var assemblies = boot.RootElement.GetProperty("resources").GetProperty("assembly").EnumerateObject().Select(jp => jp.Name); + + var references = new List(); + try + { + + foreach (Assembly reference in refs.Where(x => !x.IsDynamic))// && (!string.IsNullOrWhiteSpace(x.Location) || !string.IsNullOrWhiteSpace(x.CodeBase)))) + { + string path; + if (string.IsNullOrWhiteSpace(reference.Location)) + { + //MetadataReference.CreateFromFile(reference.Location); + //MetadataReference.CreateFromImage(reference.) + try + { + //var uri = new Uri(reference.EscapedCodeBase); + //path = uri.LocalPath.Substring(1); + path = reference.GetName().Name!; + //references.Add(MetadataReference.Crea($"{baseUri}/_framework/{path}")); + } + catch (Exception e) + { + var str = e.ToString(); + + throw; + } + } + else + { + path = reference.Location; + //references.Add(MetadataReference.CreateFromFile(reference.Location)); + } + //if (System.Diagnostics.Debugger.IsAttached) + //{ + // System.Diagnostics.Debugger.Log(1, "LOL", $"path: {path}"); + //} + //Console.WriteLine($"path: {path}"); + Stream? stream = await client.GetStreamAsync($"_framework/{path}.dll"); + references.Add(MetadataReference.CreateFromStream(stream)); + + } + } catch (Exception e) + { + var str = e.ToString(); + throw; + } + + return references; + } + + private async Task> GetReferencesFromBootDoc(string baseUri) + { + Assembly[]? refs = AppDomain.CurrentDomain.GetAssemblies(); + using var client = new HttpClient { BaseAddress = new Uri(baseUri) }; var references = new List(); + try + { + using var bootResponse = await client.GetAsync("_framework/blazor.boot.json"); + bootResponse.EnsureSuccessStatusCode(); + using var boot = JsonDocument.Parse(await bootResponse.Content.ReadAsStringAsync()); + var assemblies = boot.RootElement.GetProperty("resources").GetProperty("assembly").EnumerateObject().Select(jp => jp.Name); + //.Concat(boot.RootElement.GetProperty("resources").GetProperty("lazyAssembly").EnumerateObject().Select(jp => jp.Name)); - foreach (Assembly? reference in refs.Where(x => !x.IsDynamic && !string.IsNullOrWhiteSpace(x.Location))) + try { - Stream? stream = await client.GetStreamAsync($"_framework/_bin/{reference.Location}"); - references.Add(MetadataReference.CreateFromStream(stream)); + foreach (var assemblyName in assemblies) + { + Stream? stream = await client.GetStreamAsync($"_framework/{assemblyName}"); + references.Add(MetadataReference.CreateFromStream(stream)); + } + } catch (Exception e) + { + var str = e.ToString(); + throw; + } + } catch (Exception e) + { + var str = e.ToString(); + throw; } return references; diff --git a/Shared/MainLayout.razor b/Shared/MainLayout.razor index e1a9a75..63fb177 100644 --- a/Shared/MainLayout.razor +++ b/Shared/MainLayout.razor @@ -1,3 +1,7 @@ @inherits LayoutComponentBase -@Body +
+
+ @Body +
+
diff --git a/Shared/MainLayout.razor.css b/Shared/MainLayout.razor.css new file mode 100644 index 0000000..1a721ea --- /dev/null +++ b/Shared/MainLayout.razor.css @@ -0,0 +1,72 @@ +.page { + position: relative; + display: flex; + flex-direction: column; +} + +.main { + flex: 1; +} + +.sidebar { + background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); +} + +.top-row { + background-color: #f7f7f7; + border-bottom: 1px solid #d6d5d5; + justify-content: flex-end; + height: 3.5rem; + display: flex; + align-items: center; +} + + .top-row ::deep a, .top-row .btn-link { + white-space: nowrap; + margin-left: 1.5rem; + } + + .top-row a:first-child { + overflow: hidden; + text-overflow: ellipsis; + } + +@media (max-width: 767.98px) { + .top-row:not(.auth) { + display: none; + } + + .top-row.auth { + justify-content: space-between; + } + + .top-row a, .top-row .btn-link { + margin-left: 0; + } +} + +@media (min-width: 768px) { + .page { + flex-direction: row; + /* NOTE: added this o make the page fill */ + height: 100vh; + } + + .sidebar { + width: 250px; + height: 100vh; + position: sticky; + top: 0; + } + + .top-row { + position: sticky; + top: 0; + z-index: 1; + } + + .main > div { + padding-left: 2rem !important; + padding-right: 1.5rem !important; + } +} diff --git a/SourceGeneratorPlayground.csproj b/SourceGeneratorPlayground.csproj index e7514ca..29e0a23 100644 --- a/SourceGeneratorPlayground.csproj +++ b/SourceGeneratorPlayground.csproj @@ -1,10 +1,12 @@ - + - netstandard2.1 - 3.0 - preview - false + net5.0 + + + + false + @@ -13,24 +15,25 @@ - - - - - - + + + + - + all runtime; build; native; contentfiles; analyzers - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/_Imports.razor b/_Imports.razor index 3aa49f2..7bf4c37 100644 --- a/_Imports.razor +++ b/_Imports.razor @@ -3,6 +3,7 @@ @using Microsoft.AspNetCore.Components.Forms @using Microsoft.AspNetCore.Components.Routing @using Microsoft.AspNetCore.Components.Web +@using Microsoft.AspNetCore.Components.Web.Virtualization @using Microsoft.AspNetCore.Components.WebAssembly.Http @using Microsoft.JSInterop @using SourceGeneratorPlayground diff --git a/wwwroot/css/app.css b/wwwroot/css/app.css index 3a47583..8a2582c 100644 --- a/wwwroot/css/app.css +++ b/wwwroot/css/app.css @@ -2,10 +2,11 @@ html, body { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; - display:flex; - height: 98%; + /*display:flex;*/ +/* height: 98%; width: 99%; - background-color: lightgray; +*/ background-color: lightgray; + /*flex: auto;*/ } a, .btn-link { @@ -18,12 +19,16 @@ a, .btn-link { border-color: #1861ac; } -app { - padding-left: 20px; +.content { + padding-top: 1.1rem; +} + +/*#app {*/ +/* padding-left: 20px; padding-top: 20px; - display: flex; +*//* display: flex; flex: 1 1; -} +*//*}*/ .valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; @@ -49,12 +54,12 @@ app { z-index: 1000; } -#blazor-error-ui .dismiss { - cursor: pointer; - position: absolute; - right: 0.75rem; - top: 0.5rem; -} + #blazor-error-ui .dismiss { + cursor: pointer; + position: absolute; + right: 0.75rem; + top: 0.5rem; + } .monaco-editor-container { height: 100%; @@ -89,7 +94,7 @@ div.refresh div { .banner { /* grid-area: 1 / 1 / 2 / 3; */ background-color: white; - position: absolute; + /*position: absolute;*/ top: 0; left: 0; right: 0; @@ -153,4 +158,4 @@ div.refresh div { cursor: pointer; opacity: 0; filter: alpha(opacity=0); -} \ No newline at end of file +} diff --git a/wwwroot/index.html b/wwwroot/index.html index 5fbbd70..a158bfd 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -1,4 +1,4 @@ - + @@ -10,22 +10,24 @@ + - Loading... +
Loading...
An unhandled error has occurred. Reload 🗙
- + - + +