docfx icon indicating copy to clipboard operation
docfx copied to clipboard

[Regression] Nonsense links are rendered when source generators are used

Open bkoelman opened this issue 2 months ago • 2 comments

Describe the bug When a public class internally uses the logger source generator, nonsense links are rendered in the output html of API docs.

To Reproduce Steps to reproduce the behavior:

  1. Create a class library that contains a public type, whose implementation uses the .NET logger source generator
  2. Run docfx to generate the website

Expected behavior Correct links are rendered, or the links are omitted entirely (which is what earlier docfx versions did).

Actual behavior Nonsense links are rendered, for example:

<a class="header-action link-secondary" title="View source" href="https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/dev/src/JsonApiDotNetCore/obj/Release/net8.0/Microsoft.Extensions.Logging.Generators/Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator/LoggerMessage.g.cs/#L6"><i class="bi bi-code-slash"></i></a>

Context (please complete the following information):

  • OS: Windows
  • Docfx version: v2.79.0
  • .NET version: .NET 9

bkoelman avatar Oct 17 '25 01:10 bkoelman

What could help here are some heuristics when the source location for a type is defined in multiple files, in order to choose the proper one:

  • Skip over file names that end in .g.cs
  • Skip over anything with /obj/ in the path
  • Skip over files that contain the well-known // <autogenerated /> header

Alternatively, use the same rules Roslyn uses to determine whether a file is auto-generated.

bkoelman avatar Oct 17 '25 02:10 bkoelman

I've also confirmed reported issue can be reproduced with latest main code base.

It seems there is behavior changes between Roslyn 4.12.0 -> 4.14.0.

When using Roslyn 4.12.0. syntaxNode.SyntaxTree.FilePath property return relative path. So it fails to compare path with git base path and null value is set to source.Remote.

When Roslyn updated to 4.14.0, it return absolute path for generated files. So it's handled same as normal file and resolved URL is outputted.

filzrev avatar Oct 17 '25 07:10 filzrev