Skip to content

Fix generation of SourceKey path in RDG #48017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 4, 2023
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
1 change: 1 addition & 0 deletions eng/TrimmableProjects.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<TrimmableProject Include="Microsoft.AspNetCore.Routing" />
<TrimmableProject Include="Microsoft.AspNetCore.WebUtilities" />
<TrimmableProject Include="Microsoft.AspNetCore.Html.Abstractions" />
<TrimmableProject Include="Microsoft.AspNetCore.Identity" />
<TrimmableProject Include="Microsoft.Extensions.Identity.Core" />
<TrimmableProject Include="Microsoft.Extensions.Identity.Stores" />
<TrimmableProject Include="Microsoft.AspNetCore.Connections.Abstractions" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<Compile Include="$(SharedSourceRoot)RoslynUtils\WellKnownTypeData.cs" LinkBase="Shared" />
<Compile Include="$(SharedSourceRoot)RoslynUtils\WellKnownTypes.cs" LinkBase="Shared" />
<Compile Include="$(SharedSourceRoot)RoslynUtils\SymbolExtensions.cs" LinkBase="Shared" />
<Compile Include="$(SharedSourceRoot)RoslynUtils\SyntaxTreeExtensions.cs" LinkBase="Shared" />
<Compile Include="$(SharedSourceRoot)RoslynUtils\ParsabilityHelper.cs" LinkBase="Shared" />
<Compile Include="$(SharedSourceRoot)RoslynUtils\CodeWriter.cs" LinkBase="Shared" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ public static int GetSignatureHashCode(Endpoint endpoint)

private static (string, int) GetLocation(IInvocationOperation operation)
{
var filePath = operation.Syntax.SyntaxTree.FilePath;
var span = operation.Syntax.SyntaxTree.GetLineSpan(operation.Syntax.Span);
var operationSpan = operation.Syntax.Span;
var filePath = operation.Syntax.SyntaxTree.GetDisplayPath(operationSpan, operation.SemanticModel?.Compilation.Options.SourceReferenceResolver);
var span = operation.Syntax.SyntaxTree.GetLineSpan(operationSpan);
var lineNumber = span.StartLinePosition.Line + 1;
return (filePath, lineNumber);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.AspNetCore.Authentication.BearerToken.DTO;
using Microsoft.AspNetCore.Builder;
Expand All @@ -28,8 +27,6 @@ public static class IdentityApiEndpointRouteBuilderExtensions
/// Call <see cref="EndpointRouteBuilderExtensions.MapGroup(IEndpointRouteBuilder, string)"/> to add a prefix to all the endpoints.
/// </param>
/// <returns>An <see cref="IEndpointConventionBuilder"/> to further customize the added endpoints.</returns>
// TODO: Remove RequiresDynamicCode when https://github.com/dotnet/aspnetcore/issues/47918 is fixed and RDG is enabled.
[RequiresDynamicCode("This API requires generated code that is not compatible with native AOT applications.")]
public static IEndpointConventionBuilder MapIdentityApi<TUser>(this IEndpointRouteBuilder endpoints) where TUser : class, new()
{
ArgumentNullException.ThrowIfNull(endpoints);
Expand Down
7 changes: 3 additions & 4 deletions src/Identity/Core/src/Microsoft.AspNetCore.Identity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;identity;membership</PackageTags>
<IsPackable>false</IsPackable>
<!-- TODO: Re-enable trimming once https://github.com/dotnet/aspnetcore/issues/47918 is fixed and RDG is enabled. -->
<!--<IsTrimmable>true</IsTrimmable>-->
<IsTrimmable>true</IsTrimmable>
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
</PropertyGroup>

<ItemGroup>
Expand All @@ -31,7 +31,6 @@
</ItemGroup>

<ItemGroup>
<!-- TODO: Re-enable RDG once https://github.com/dotnet/aspnetcore/issues/47918 is fixed. -->
<!--<ProjectReference Include="$(RepoRoot)/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />-->
<ProjectReference Include="$(RepoRoot)/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions src/Shared/RoslynUtils/SyntaxTreeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;

internal static class SyntaxTreeExtensions
{
// Utilize the same logic used by the `CallerLinePathAttribute` for generating
// a file path for a given syntax tree.
// Source copied from https://github.com/dotnet/roslyn/blob/5b47c7fe326faa35940f220c14f718cd0b820c38/src/Compilers/Core/Portable/Syntax/SyntaxTree.cs#L274-L293 until
// public APIs are available.
internal static string GetDisplayPath(this SyntaxTree tree, TextSpan span, SourceReferenceResolver? resolver)
{
var mappedSpan = tree.GetMappedLineSpan(span);
if (resolver == null || mappedSpan.Path.Length == 0)
{
return mappedSpan.Path;
}

return resolver.NormalizePath(mappedSpan.Path, baseFilePath: mappedSpan.HasMappedPath ? tree.FilePath : null) ?? mappedSpan.Path;
}
}