vscode-csharp: Go to definition for a source generated file fails to open the generated file
Repro:
- Open Roslyn solution and wait for load
- Find any type with a definition in
Syntax.xml.Syntax.Generated.cs
- for exampleBaseTypeDeclarationSyntax
here - Expect navigate to definition location, instead throws an error with the following stack:
[Error - 3:46:20 PM] [LanguageServerHost] System.UriFormatException: Failed create URI from 'CSharpSyntaxGenerator\CSharpSyntaxGenerator.SourceGenerator\Syntax.xml.Syntax.Generated.cs'; original string: 'CSharpSyntaxGenerator\CSharpSyntaxGenerator.SourceGenerator\Syntax.xml.Syntax.Generated.cs'
---> System.UriFormatException: Invalid URI: The format of the URI could not be determined.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 186
--- End of inner exception stack trace ---
at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 186
at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.<TextSpanToLocationAsync>g__ConvertTextSpanToLocation|30_0(Document document, TextSpan span, Boolean isStale, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 491
at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.TextSpanToLocationAsync(Document document, TextSpan textSpan, Boolean isStale, Nullable`1 context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 503
at Microsoft.CodeAnalysis.LanguageServer.Handler.AbstractGoToDefinitionHandler.GetDefinitionAsync(TextDocumentPositionParams request, Boolean typeOnly, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs:line 141
at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176
[Error - 3:46:20 PM] Request textDocument/definition failed.
Message: Failed create URI from 'CSharpSyntaxGenerator\CSharpSyntaxGenerator.SourceGenerator\Syntax.xml.Syntax.Generated.cs'; original string: 'CSharpSyntaxGenerator\CSharpSyntaxGenerator.SourceGenerator\Syntax.xml.Syntax.Generated.cs'
Code: -32000
About this issue
- Original URL
- State: open
- Created 9 months ago
- Reactions: 31
- Comments: 24 (6 by maintainers)
I get this bug on a Godot project too. Godot uses source generators. It happens when I try to use “jump to definition” or “find all references”, only where it involves generated code, it seems. In non-partial classes, it works fine.
@arsinclair This demonstrates why I should never give a promise of a ship date – I’m now on leave with the arrival of our new baby. 👶 We’ll have somebody else wrap up the work but we’re still handing that off.
FYI: this is also blocking any ‘Find all references’ functionality for me.
@jasonmalinowski two weeks have passed, any update here?
@hutterm It’s in code review now, so should land if not this week then next week.
To clarify a bit: there’s still more work to do to make Go to Definition to source generated files actually work. To give a bit of a sense how this works:
The UriFormatException was because we had a place that wasn’t correctly doing the first step. So if you had find references that found 10 references, and just one happened to be in a source generated file, then we’d fail to create the URI properly and thus the entire request would fail. Which was icky. So we fixed that; the work for step 2 isn’t in, which is why @JeremyTCD is getting the error he’s seeing. But that’ll only happen if you actually need to open a generated file. In my example of Find References w/ 10 references, at least now you can view the other 9. 😄
I’m leaving this bug open until I actually fix the end-to-end though. I’ll retitle it.
This affects us in a project that uses RefitGenerator. It’s very problematic as it completely breaks CTRL+T (show all symbols).
The latest update of v2.15.30 seems to have fixed the issue. Was able to find references without errors for a Godot (v4.2.1) project. Would like a second opinion from anyone else who was previously facing this issue.