Skip to content
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

Go to definition for a source generated file fails to open the generated file #6426

Open
dibarbet opened this issue Sep 22, 2023 · 32 comments · May be fixed by #5858
Open

Go to definition for a source generated file fails to open the generated file #6426

dibarbet opened this issue Sep 22, 2023 · 32 comments · May be fixed by #5858
Assignees
Milestone

Comments

@dibarbet
Copy link
Member

Repro:

  1. Open Roslyn solution and wait for load
  2. Find any type with a definition in Syntax.xml.Syntax.Generated.cs - for example BaseTypeDeclarationSyntax here
  3. 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 
@DanielLaberge
Copy link

This affects us in a project that uses RefitGenerator.
It's very problematic as it completely breaks CTRL+T (show all symbols).

[Error - 1:58:26 PM] [LanguageServerHost] System.UriFormatException: Failed create URI from 'InterfaceStubGeneratorV2\Refit.Generator.InterfaceStubGeneratorV2\IAccountService.g.cs'; original string: 'InterfaceStubGeneratorV2\Refit.Generator.InterfaceStubGeneratorV2\IAccountService.g.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 477
   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 442
   at Microsoft.CodeAnalysis.LanguageServer.Handler.WorkspaceSymbolsHandler.LSPNavigateToCallback.AddItemAsync(Project project, INavigateToSearchResult result, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs:line 90
   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.<>c__DisplayClass13_0.<<GetOnItemFoundCallback>b__0>d.MoveNext() in /_/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.cs:line 37
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.AddResultIfMatchAsync(DocumentId documentId, Document document, DeclaredSymbolInfo declaredSymbolInfo, PatternMatcher nameMatcher, PatternMatcher containerMatcher, DeclaredSymbolInfoKindSet kinds, Func`2 onResultFound, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs:line 162
   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.ProcessIndexAsync(DocumentId documentId, Document document, String patternName, String patternContainer, DeclaredSymbolInfoKindSet kinds, Func`2 onResultFound, TopLevelSyntaxTreeIndex index, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs:line 123
   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.ProcessDocumentAsync(Document document, String patternName, String patternContainer, DeclaredSymbolInfoKindSet kinds, Func`2 onResultFound, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs:line 96
   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.ProcessDocumentsAsync(Document searchDocument, String patternName, String patternContainer, DeclaredSymbolInfoKindSet kinds, Func`2 onResultFound, ISet`1 documents, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs:line 83
   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.SearchGeneratedDocumentsInCurrentProcessAsync(Project project, String pattern, IImmutableSet`1 kinds, Func`2 onResultFound, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.GeneratedDocumentSearch.cs:line 60
   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.SearchGeneratedDocumentsAsync(Project project, String searchPattern, IImmutableSet`1 kinds, Document activeDocument, Func`2 onResultFound, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.GeneratedDocumentSearch.cs:line 42
   at Microsoft.CodeAnalysis.NavigateTo.NavigateToSearcher.<>c__DisplayClass19_0.<<ProcessOrderedProjectsAsync>g__SearchCoreAsync|0>d.MoveNext() in /_/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs:line 322
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.NavigateTo.NavigateToSearcher.<>c__DisplayClass19_0.<<ProcessOrderedProjectsAsync>g__SearchCoreAsync|0>d.MoveNext() in /_/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs:line 339
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.NavigateTo.NavigateToSearcher.ProcessOrderedProjectsAsync(Boolean parallel, ImmutableArray`1 orderedProjects, HashSet`1 seenItems, Func`4 processProjectAsync, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs:line 301
   at Microsoft.CodeAnalysis.NavigateTo.NavigateToSearcher.SearchAllProjectsAsync(Boolean isFullyLoaded, NavigateToSearchScope scope, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs:line 186
   at Microsoft.CodeAnalysis.NavigateTo.NavigateToSearcher.SearchAsync(Boolean searchCurrentDocument, NavigateToSearchScope scope, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs:line 130
   at Microsoft.CodeAnalysis.NavigateTo.NavigateToSearcher.SearchAsync(Boolean searchCurrentDocument, NavigateToSearchScope scope, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs:line 140
   at Microsoft.CodeAnalysis.LanguageServer.Handler.WorkspaceSymbolsHandler.HandleRequestAsync(WorkspaceSymbolParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs:line 69
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176
[Error - 1:58:26 PM] Request workspace/symbol failed.
  Message: Failed create URI from 'InterfaceStubGeneratorV2\Refit.Generator.InterfaceStubGeneratorV2\IAccountService.g.cs'; original string: 'InterfaceStubGeneratorV2\Refit.Generator.InterfaceStubGeneratorV2\IAccountService.g.cs'
  Code: -32000 

@geekley
Copy link

geekley commented Oct 27, 2023

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.

@penev92
Copy link

penev92 commented Dec 1, 2023

I'm adding source generators to OpenRA/OpenRA#21234 and this is proving to be a blocker for us!

@pepone
Copy link

pepone commented Dec 1, 2023

@penev92 you can workaround this by setting EmitCompilerGeneratedFiles property to true

@penev92
Copy link

penev92 commented Dec 1, 2023

Even then the C# extension throws on all navigation operations that deal with creating an URL for generated code and once I manually open a generated file it can't use any symbols in it to navigate out.

@markcagatandavis
Copy link

markcagatandavis commented Dec 5, 2023

I'm getting the same error and not sure why.

`Using dotnet configured on PATH
Dotnet path: C:\Program Files\dotnet\dotnet.exe
Activating C# + C# Dev Kit + C# IntelliCode...
waiting for named pipe information from server...
[stdout] {"pipeName":"\\\\.\\pipe\\0ffc6eee"}
received named pipe information from server
attempting to connect client to server...
client has connected to server
[Info  - 6:22:10 PM] [Program] Language server initialized
[Info  - 6:22:18 PM] [WorkspaceProjectFactoryService] Project C:\Users\markc\Documents\GitHub\MyFirstCSharpProject\MyFirstCSharpProject.csproj loaded by C# Dev Kit
[Error - 7:34:55 PM] [LanguageServerHost] System.UriFormatException: Failed create URI from 'Godot.SourceGenerators\Godot.SourceGenerators.ScriptPropertiesGenerator\PlayerMove_ScriptProperties.generated.cs'; original string: 'Godot.SourceGenerators\Godot.SourceGenerators.ScriptPropertiesGenerator\PlayerMove_ScriptProperties.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 System.Uri..ctor(String uriString, UriKind uriKind)
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 180
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 188
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.<TextSpanToLocationAsync>g__ConvertTextSpanToLocationAsync|32_0(Document document, TextSpan span, Boolean isStale, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 479
   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 444
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindUsagesLSPContext.ComputeLocationAsync(Nullable`1 documentSpan, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 209
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindUsagesLSPContext.GenerateVSReferenceItemAsync(Int32 definitionId, Int32 id, Nullable`1 documentSpan, ImmutableDictionary`2 properties, ClassifiedTextElement definitionText, Glyph definitionGlyph, Nullable`1 symbolUsageInfo, Boolean isWrittenTo, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 194
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindUsagesLSPContext.OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 167
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindReferencesProgressAdapter.OnReferenceFoundAsync(SymbolGroup group, ISymbol definition, ReferenceLocation location, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs:line 123
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<>c__DisplayClass20_0.<<ProcessDocumentAsync>g__ProcessDocumentAsync|0>d.MoveNext() in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 301
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessDocumentAsync(Document document, MetadataUnifyingSymbolHashSet symbols, Dictionary`2 symbolToGlobalAliases, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 302
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessDocumentAsync(Document document, MetadataUnifyingSymbolHashSet symbols, Dictionary`2 symbolToGlobalAliases, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 302
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessProjectAsync(Project project, ImmutableArray`1 allSymbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 244
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessProjectAsync(Project project, ImmutableArray`1 allSymbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 244
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 132
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 132
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 132
   at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.FindReferencesAsync(ISymbol symbol, Solution solution, IStreamingFindReferencesProgress progress, IImmutableSet`1 documents, FindReferencesSearchOptions options, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindReferences_Current.cs:line 68
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindReferencesAsync(IFindUsagesContext context, ISymbol symbol, Project project, FindReferencesSearchOptions options, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 154
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindSymbolReferencesAsync(IFindUsagesContext context, ISymbol symbol, Project project, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 125
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindSymbolReferencesAsync(IFindUsagesContext context, Document document, Int32 position, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 103
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindLiteralOrSymbolReferencesAsync(IFindUsagesContext context, Document document, Int32 position, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 65
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindAllReferencesHandler.HandleRequestAsync(ReferenceParams referenceParams, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs:line 68
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176
[Error - 7:34:55 PM] Request textDocument/references failed.
  Message: Failed create URI from 'Godot.SourceGenerators\Godot.SourceGenerators.ScriptPropertiesGenerator\PlayerMove_ScriptProperties.generated.cs'; original string: 'Godot.SourceGenerators\Godot.SourceGenerators.ScriptPropertiesGenerator\PlayerMove_ScriptProperties.generated.cs'
  Code: -32000 
[object Object]`

@AdriaandeJongh
Copy link

FYI: this is also blocking any 'Find all references' functionality for me.

@Ardub92
Copy link

Ardub92 commented Dec 10, 2023

I'm getting the same error and not sure why.

`Using dotnet configured on PATH
Dotnet path: C:\Program Files\dotnet\dotnet.exe
Activating C# + C# Dev Kit + C# IntelliCode...
waiting for named pipe information from server...
[stdout] {"pipeName":"\\\\.\\pipe\\0ffc6eee"}
received named pipe information from server
attempting to connect client to server...
client has connected to server
[Info  - 6:22:10 PM] [Program] Language server initialized
[Info  - 6:22:18 PM] [WorkspaceProjectFactoryService] Project C:\Users\markc\Documents\GitHub\MyFirstCSharpProject\MyFirstCSharpProject.csproj loaded by C# Dev Kit
[Error - 7:34:55 PM] [LanguageServerHost] System.UriFormatException: Failed create URI from 'Godot.SourceGenerators\Godot.SourceGenerators.ScriptPropertiesGenerator\PlayerMove_ScriptProperties.generated.cs'; original string: 'Godot.SourceGenerators\Godot.SourceGenerators.ScriptPropertiesGenerator\PlayerMove_ScriptProperties.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 System.Uri..ctor(String uriString, UriKind uriKind)
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 180
   --- End of inner exception stack trace ---
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 188
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.<TextSpanToLocationAsync>g__ConvertTextSpanToLocationAsync|32_0(Document document, TextSpan span, Boolean isStale, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 479
   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 444
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindUsagesLSPContext.ComputeLocationAsync(Nullable`1 documentSpan, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 209
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindUsagesLSPContext.GenerateVSReferenceItemAsync(Int32 definitionId, Int32 id, Nullable`1 documentSpan, ImmutableDictionary`2 properties, ClassifiedTextElement definitionText, Glyph definitionGlyph, Nullable`1 symbolUsageInfo, Boolean isWrittenTo, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 194
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindUsagesLSPContext.OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 167
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindReferencesProgressAdapter.OnReferenceFoundAsync(SymbolGroup group, ISymbol definition, ReferenceLocation location, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs:line 123
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.<>c__DisplayClass20_0.<<ProcessDocumentAsync>g__ProcessDocumentAsync|0>d.MoveNext() in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 301
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessDocumentAsync(Document document, MetadataUnifyingSymbolHashSet symbols, Dictionary`2 symbolToGlobalAliases, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 302
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessDocumentAsync(Document document, MetadataUnifyingSymbolHashSet symbols, Dictionary`2 symbolToGlobalAliases, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 302
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessProjectAsync(Project project, ImmutableArray`1 allSymbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 244
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ProcessProjectAsync(Project project, ImmutableArray`1 allSymbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 244
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 132
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 132
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 132
   at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.FindReferencesAsync(ISymbol symbol, Solution solution, IStreamingFindReferencesProgress progress, IImmutableSet`1 documents, FindReferencesSearchOptions options, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_FindReferences_Current.cs:line 68
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindReferencesAsync(IFindUsagesContext context, ISymbol symbol, Project project, FindReferencesSearchOptions options, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 154
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindSymbolReferencesAsync(IFindUsagesContext context, ISymbol symbol, Project project, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 125
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindSymbolReferencesAsync(IFindUsagesContext context, Document document, Int32 position, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 103
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindLiteralOrSymbolReferencesAsync(IFindUsagesContext context, Document document, Int32 position, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService_FindReferences.cs:line 65
   at Microsoft.CodeAnalysis.LanguageServer.Handler.FindAllReferencesHandler.HandleRequestAsync(ReferenceParams referenceParams, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs:line 68
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176
[Error - 7:34:55 PM] Request textDocument/references failed.
  Message: Failed create URI from 'Godot.SourceGenerators\Godot.SourceGenerators.ScriptPropertiesGenerator\PlayerMove_ScriptProperties.generated.cs'; original string: 'Godot.SourceGenerators\Godot.SourceGenerators.ScriptPropertiesGenerator\PlayerMove_ScriptProperties.generated.cs'
  Code: -32000 
[object Object]`

This temporary fix introduced here

@geekley
Copy link

geekley commented Dec 11, 2023

It seems they changed default setting back to use OmniSharp instead of Roslyn.

Having it set to OmniSharp used to solve the issue IIRC, but now, when using "jump to definition" or "find all references" of Godot partial classes in OmniSharp, I do get to see the generated code in the popup thingy, but when clicking to actually open it in a new tab, there's another issue, an error in the Virtual Text Document Provider, it seems:

The editor could not be opened due to an unexpected error: Unable to resolve text model content for resource omnisharp-source-generated:/Godot.SourceGenerators/Godot.SourceGenerators.ScriptMethodsGenerator/[...]_ScriptMethods.generated.cs

In the dev tools console log:

ERR Error: Unable to resolve text model content for resource omnisharp-source-generated:/Godot.SourceGenerators/Godot.SourceGenerators.ScriptMethodsGenerator/MyNS.MyClass_ScriptMethods.generated.cs
    at u.resolveTextModelContent (workbench.desktop.main.js:2413:50371)
    at async u.doCreateReferencedObject (workbench.desktop.main.js:2413:49039)
    at async v.acquire (workbench.desktop.main.js:37:3821)
    at async h.createModelReference (workbench.desktop.main.js:2413:51322)
    at async u.resolve (workbench.desktop.main.js:1903:52420)
    at async r.setInput (workbench.desktop.main.js:2402:15966)
    at async d.doSetInput (workbench.desktop.main.js:2400:35207)
    at async d.doOpenEditor (workbench.desktop.main.js:2400:33029)
    at async d.openEditor (workbench.desktop.main.js:2400:31739)
    at async workbench.desktop.main.js:2530:31512
    at async C.doOpenCodeEditor (workbench.desktop.main.js:1186:99411)
    at async C.openCodeEditor (workbench.desktop.main.js:720:6831)

@jasonmalinowski
Copy link
Member

@geekley Who was "they" in this case?

@thorx2
Copy link

thorx2 commented Jan 12, 2024

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.

@JeremyTCD
Copy link

JeremyTCD commented Jan 12, 2024

Used to get the System.UriFormatException, I'm getting a different error when I try to "go to definition" now:

The editor could not be opened due to an unexpected error:
Unable to resolve resource source-generated:/Pictoria.Server.Generators/Pictoria.Server.Generators.DataAccessLayerIncrementalGenerator/PlayerModel.Generated.cs

Using the latest insider build:

Version: 1.86.0-insider (user setup)
Commit: a45edfc415d19852fa3c3e1cd255a02de9e016d2
Date: 2024-01-11T05:36:37.776Z
Electron: 27.2.1
ElectronBuildId: 26149897
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Windows_NT x64 10.0.22621

and vscode-csharp v2.15.30.

Edit:

Context: Pictoria.Server.Generators is a class library project with several incremental generators, including DataAccessLayerIncrementalGenerator. A console project references Pictoria.Server.Generators as a "project reference". I get the error when, in console project logic, I "go to definition" a Pictoria.Server.Generators generated type.

@benrad
Copy link

benrad commented Jan 12, 2024

Extension version 2.15.30 appears to have resolved the go to symbol, go to definition, and go to implementations issues for me, too. This is a huge improvement in the experience for me and my team--thanks very much to the maintainers.

@jasonmalinowski
Copy link
Member

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:

  1. The Roslyn server has to send down a custom URI to VS Code for source generated files, since they're potentially virtual and not on disk.
  2. The Roslyn VS Code extension then needs to recognize this URI and go display the dynamic content and such.

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.

@jasonmalinowski jasonmalinowski changed the title Go to definition fails with System.UriFormatException Go to definition for a source generated file fails to open the generated file Jan 12, 2024
@JeremyTCD
Copy link

@jasonmalinowski thanks for clarifying, appreciate the work you're putting into this issue!

@hutterm
Copy link

hutterm commented Feb 12, 2024

@jasonmalinowski any update on this?

@jasonmalinowski
Copy link
Member

@hutterm It's in code review now, so should land if not this week then next week.

@arsinclair
Copy link

@jasonmalinowski two weeks have passed, any update here?

@jasonmalinowski
Copy link
Member

@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.

@DanteMarshal
Copy link

DanteMarshal commented May 21, 2024

@jasonmalinowski two weeks have passed, any update here?

three months now :/

@Ardub92
Copy link

Ardub92 commented Jun 8, 2024

@jasonmalinowski two weeks have passed, any update here?

three months now :/

As I remember it should work now. I updated my extension and it works good.

@JeremyTCD
Copy link

@jasonmalinowski two weeks have passed, any update here?

three months now :/

As I remember it should work now. I updated my extension and it works good.

Does navigating to source generator generated files work for you? Still broken for me with the latest updates.

@nikolalukovic
Copy link

Still broken...

@megasuperlexa
Copy link

this is embarrassing and makes me switch to Jetbrains ide sometimes

@microhobby
Copy link

Still occurring. Even using the <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>

@nikolalukovic
Copy link

Any plans for this to get fixed? This is a blocker which forces me to use other IDEs...

@penev92
Copy link

penev92 commented Sep 7, 2024

Bump!
This is proving to be quite the blocker for us at https://github.com/OpenRA/OpenRA and for many others, I'm sure. Is @jasonmalinowski able to finish it? Is someone able to take over? Can someone lay out a plan for what else is needed so someone else can take over?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.