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 .globalconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# CA2025: Do not pass 'IDisposable' instances into unawaited tasks
dotnet_diagnostic.CA2025.severity = suggestion
22 changes: 11 additions & 11 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<!-- We are not using package source mapping. -->
<NoWarn>$(NoWarn);NU1507</NoWarn>
<NetCoreVersion>10.0.0-preview.4.25258.110</NetCoreVersion>
<NetCoreVersion>10.0.0-preview.5.25277.114</NetCoreVersion>
<AspNetCoreVersion>$(NetCoreVersion)</AspNetCoreVersion>
<RoslynVersion>5.0.0-1.25252.6</RoslynVersion>
<FluentUIVersion>4.11.8</FluentUIVersion>
<NuGetVersion>6.13.1</NuGetVersion>
<RoslynVersion>5.0.0-1.25321.102</RoslynVersion>
<FluentUIVersion>4.12.0</FluentUIVersion>
<NuGetVersion>6.14.0</NuGetVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AwesomeAssertions" Version="8.0.1" />
<PackageVersion Include="AwesomeAssertions" Version="9.0.0" />
<PackageVersion Include="Blazored.LocalStorage" Version="4.5.0" />
<!-- When upating BlazorMonaco, check that VIM mode works. See https://github.com/jjonescz/DotNetLab/pull/57. -->
<PackageVersion Include="BlazorMonaco" Version="3.2.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="ICSharpCode.Decompiler" Version="9.0.0.7889" />
<PackageVersion Include="ICSharpCode.Decompiler" Version="9.1.0.7988" />
<PackageVersion Include="MetadataReferenceService.BlazorWasm" Version="0.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.App.Ref" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="$(AspNetCoreVersion)" />
Expand All @@ -29,17 +29,17 @@
<PackageVersion Include="Microsoft.Extensions.Logging" Version="$(NetCoreVersion)" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components" Version="$(FluentUIVersion)" />
<PackageVersion Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="$(FluentUIVersion)" />
<PackageVersion Include="Microsoft.Net.Compilers.Razor.Toolset" Version="10.0.0-preview.25252.1" />
<PackageVersion Include="Microsoft.Net.Compilers.Razor.Toolset" Version="10.0.0-preview.25321.102" />
<PackageVersion Include="Microsoft.Net.Compilers.Toolset" Version="$(RoslynVersion)" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="Microsoft.NETCore.App.Ref" Version="$(NetCoreVersion)" />
<PackageVersion Include="Microsoft.TeamFoundationServer.Client" Version="19.225.1" />
<PackageVersion Include="NuGet.Protocol" Version="$(NuGetVersion)" />
<PackageVersion Include="NuGet.Versioning" Version="$(NuGetVersion)" />
<PackageVersion Include="protobuf-net" Version="3.2.46" />
<PackageVersion Include="protobuf-net" Version="3.2.52" />
<PackageVersion Include="System.IO.Hashing" Version="$(NetCoreVersion)" />
<PackageVersion Include="xunit.v3" Version="1.1.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
<PackageVersion Include="xunit.v3" Version="2.0.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.1" />
<!-- Pinned transitive dependencies -->
<PackageVersion Include="System.Data.SqlClient" Version="4.9.0" />
</ItemGroup>
Expand Down
111 changes: 0 additions & 111 deletions DotNetLab.sln

This file was deleted.

29 changes: 29 additions & 0 deletions DotNetLab.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Solution>
<Folder Name="/eng/">
<File Path="eng/build.sh" />
<File Path="eng/CopyDotNetDTs.targets" />
</Folder>
<Folder Name="/src/">
<Project Path="src/App/App.csproj" />
<Project Path="src/Compiler/Compiler.csproj" />
<Project Path="src/RazorAccess/RazorAccess.csproj" />
<Project Path="src/RoslynAccess/RoslynAccess.csproj" />
<Project Path="src/RoslynWorkspaceAccess/RoslynWorkspaceAccess.csproj" />
<Project Path="src/Server/Server.csproj" />
<Project Path="src/Shared/Shared.csproj" />
<Project Path="src/Worker/Worker.csproj" />
<Project Path="src/WorkerApi/WorkerApi.csproj" />
</Folder>
<Folder Name="/test/">
<Project Path="test/UnitTests/UnitTests.csproj" />
</Folder>
<Folder Name="/_/">
<File Path=".gitignore" />
<File Path=".globalconfig" />
<File Path="Directory.Build.props" />
<File Path="Directory.Packages.props" />
<File Path="global.json" />
<File Path="nuget.config" />
<File Path="README.md" />
</Folder>
</Solution>
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "10.0.100-preview.4.25258.110",
"workloadVersion": "10.0.100-preview.4.25263.1"
"version": "10.0.100-preview.5.25277.114",
"workloadVersion": "10.0.100-preview.5.25306.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace DotNetLab.Lab;

[SupportedOSPlatform("browser")]
internal sealed class LanguageServices(
internal sealed class LanguageServicesClient(
ILoggerFactory loggerFactory,
ILogger<LanguageServices> logger,
ILogger<LanguageServicesClient> logger,
IJSRuntime jsRuntime,
WorkerController worker,
BlazorMonacoInterop blazorMonacoInterop)
Expand Down
8 changes: 6 additions & 2 deletions src/App/Lab/Page.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@inject IJSRuntime JSRuntime
@inject NavigationManager NavigationManager
@inject WorkerController Worker
@inject LanguageServices LanguageServices
@inject LanguageServicesClient LanguageServices
@inject InputOutputCache Cache
@inject TemplateCache TemplateCache
@inject BlazorMonacoInterop BlazorMonacoInterop
Expand Down Expand Up @@ -772,7 +772,11 @@
{
if (!outputStates.TryGetValue(outputType, out var state))
{
state = new(await BlazorMonaco.Editor.Global.CreateModel(JSRuntime, value: text, language: language));
state = new(await BlazorMonaco.Editor.Global.CreateModel(
JSRuntime,
value: text,
language: language,
uri: $"out/{Guid.CreateVersion7()}/{outputType}"));
outputStates[outputType] = state;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/App/Lab/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@inject IJSRuntime JSRuntime
@inject ILocalStorageService LocalStorage
@inject WorkerController Worker
@inject LanguageServices LanguageServices
@inject LanguageServicesClient LanguageServices
@inject HttpClient Client

<FluentDesignTheme StorageName="theme" @bind-Mode="theme" CustomColor="@AppColors.CustomDark"
Expand Down
4 changes: 2 additions & 2 deletions src/App/Lab/TemplateCache.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

builder.Services.AddScoped<WorkerController>();
builder.Services.AddScoped<BlazorMonacoInterop>();
builder.Services.AddScoped<LanguageServices>();
builder.Services.AddScoped<LanguageServicesClient>();
builder.Services.AddScoped<InputOutputCache>();
builder.Services.AddScoped<TemplateCache>();

Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private CompiledAssembly CompileNoCache(
Type = "ir",
Label = "IR",
Language = "csharp",
EagerText = codeDocument.Map(d => d?.GetDocumentIntermediateNode().Serialize() ?? "").Serialize(),
EagerText = codeDocument.Map(d => d?.GetDocumentIntermediateNodeSafe().Serialize() ?? "").Serialize(),
},
.. string.IsNullOrEmpty(razorDiagnostics)
? ImmutableArray<CompiledFileOutput>.Empty
Expand All @@ -237,7 +237,7 @@ .. string.IsNullOrEmpty(razorDiagnostics)
Language = "html",
LazyText = new(() =>
{
var document = codeDocument.Unwrap()?.GetDocumentIntermediateNode()
var document = codeDocument.Unwrap()?.GetDocumentIntermediateNodeSafe()
?? throw new InvalidOperationException("No IR available.");

if (document.DocumentKind.StartsWith("mvc"))
Expand Down
62 changes: 44 additions & 18 deletions src/Compiler/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Text;
Expand Down Expand Up @@ -140,15 +141,7 @@ static string toBase36(ReadOnlySpan<byte> hash)

public static RazorCSharpDocument GetCSharpDocumentSafe(this RazorCodeDocument document)
{
// GetCSharpDocument extension method has been turned into an instance method in https://github.com/dotnet/razor/pull/11939.
if (document.GetType().GetMethod("GetCSharpDocument", BindingFlags.Instance | BindingFlags.NonPublic) is { } method)
{
return (RazorCSharpDocument)method.Invoke(document, [])!;
}

return (RazorCSharpDocument)typeof(RazorCodeDocument).Assembly.GetType("Microsoft.AspNetCore.Razor.Language.RazorCodeDocumentExtensions")!
.GetMethod("GetCSharpDocument", BindingFlags.Static | BindingFlags.Public)!
.Invoke(null, [document])!;
return document.GetDocumentDataSafe<RazorCSharpDocument>("GetCSharpDocument");
}

public static IReadOnlyList<RazorDiagnostic> GetDiagnostics(this RazorCSharpDocument document)
Expand All @@ -160,6 +153,24 @@ public static IReadOnlyList<RazorDiagnostic> GetDiagnostics(this RazorCSharpDocu
.GetValue(document)!;
}

private static T GetDocumentDataSafe<T>(this RazorCodeDocument document, string methodName, string? instanceMethodName = null)
{
// GetCSharpDocument and similar extension methods have been turned into instance methods in https://github.com/dotnet/razor/pull/11939.
if (document.GetType().GetMethod(instanceMethodName ?? methodName, BindingFlags.Instance | BindingFlags.NonPublic) is { } method)
{
return (T)method.Invoke(document, [])!;
}

return (T)typeof(RazorCodeDocument).Assembly.GetType("Microsoft.AspNetCore.Razor.Language.RazorCodeDocumentExtensions")!
.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public)!
.Invoke(null, [document])!;
}

public static DocumentIntermediateNode GetDocumentIntermediateNodeSafe(this RazorCodeDocument document)
{
return document.GetDocumentDataSafe<DocumentIntermediateNode>("GetDocumentIntermediateNode", "GetDocumentNode");
}

public static string GetGeneratedCode(this RazorCSharpDocument document)
{
// There can be either `string GeneratedCode` or `SourceText Text` property.
Expand All @@ -177,15 +188,7 @@ public static string GetGeneratedCode(this RazorCSharpDocument document)

public static RazorSyntaxTree GetSyntaxTreeSafe(this RazorCodeDocument document)
{
// GetSyntaxTree extension method has been turned into an instance method in https://github.com/dotnet/razor/pull/11939.
if (document.GetType().GetMethod("GetSyntaxTree", BindingFlags.Instance | BindingFlags.NonPublic) is { } method)
{
return (RazorSyntaxTree)method.Invoke(document, [])!;
}

return (RazorSyntaxTree)typeof(RazorCodeDocument).Assembly.GetType("Microsoft.AspNetCore.Razor.Language.RazorCodeDocumentExtensions")!
.GetMethod("GetSyntaxTree", BindingFlags.Static | BindingFlags.Public)!
.Invoke(null, [document])!;
return document.GetDocumentDataSafe<RazorSyntaxTree>("GetSyntaxTree");
}

public static IEnumerable<RazorProjectItem> EnumerateItemsSafe(this RazorProjectFileSystem fileSystem, string basePath)
Expand Down Expand Up @@ -241,6 +244,29 @@ .. var rest
.Invoke(engine, [projectItem, .. Enumerable.Repeat<object?>(null, method.GetParameters().Length - 1)])!;
}

public static string Serialize(this IntermediateNode node)
{
// DebuggerDisplayFormatter merged to IntermediateNodeFormatter in https://github.com/dotnet/razor/pull/11931.

var assembly = typeof(IntermediateNode).Assembly;
if (assembly.GetType("Microsoft.AspNetCore.Razor.Language.Intermediate.DebuggerDisplayFormatter") is { } debuggerDisplayFormatter)
{
var formatter = Activator.CreateInstance(debuggerDisplayFormatter)!;
debuggerDisplayFormatter.GetMethod("FormatTree", BindingFlags.Instance | BindingFlags.Public)!
.Invoke(formatter, [node]);
return formatter.ToString()!;
}
else
{
var type = assembly.GetType("Microsoft.AspNetCore.Razor.Language.Intermediate.IntermediateNodeFormatter")!;
var sb = new StringBuilder();
var formatter = type.GetConstructors().Single().Invoke([sb, 0, false])!;
type.GetMethod("FormatTree", BindingFlags.Instance | BindingFlags.Public)!
.Invoke(formatter, [node]);
return sb.ToString();
}
}

public static void SetCSharpLanguageVersionSafe(this RazorProjectEngineBuilder builder, LanguageVersion languageVersion)
{
// Changed in https://github.com/dotnet/razor/commit/40384334fd4c20180c25b3c88a82d3ca5da07487.
Expand Down
Loading