jmederosalvarado / roslyn.nvim

Roslyn LSP plugin for neovim
MIT License
198 stars 48 forks source link

Support for source generators? #14

Open hutterm opened 11 months ago

hutterm commented 11 months ago

in a project using a source generator I find that a go to definition results in

[ERROR][2023-12-06 12:33:25] ...lsp/handlers.lua:556    "[LanguageServerHost] System.UriFormatException: Failed create URI from 'PropertyChanged.SourceGenerator\\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\\RoutineVM.g.cs'; original string: 'PropertyChanged.SourceGenerator\\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\\RoutineVM.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.AbstractGoToDefinitionHandler.GetDefinitionAsync(TextDocumentPositionParams request, Boolean typeOnly, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs:line 61
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176"

similar with a find references:

[ERROR][2023-12-06 12:35:27] ...lsp/handlers.lua:556    "[LanguageServerHost] System.UriFormatException: Failed create URI from 'PropertyChanged.SourceGenerator\\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\\RoutineVM.g.cs'; original string: 'PropertyChanged.SourceGenerator\\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\\RoutineVM.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.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.OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/References/FindUsagesLSPContext.cs:line 118
   at Microsoft.CodeAnalysis.FindUsages.AbstractFindUsagesService.FindReferencesProgressAdapter.OnDefinitionFoundAsync(SymbolGroup group, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs:line 110
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ReportGroupAsync(ISymbol symbol, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 175
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.ReportGroupsAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 146
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 90
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 126
   at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.FindReferencesAsync(ImmutableArray`1 symbols, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs:line 130
   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 64
   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"

is there any way to support this?

tried updating to opts.roslyn_version = "4.9.0-2.23563.2" but that alone doesn't do it

jmederosalvarado commented 11 months ago

I would appreciate if you could provide a sample project (.cs and .csproj files) to quickly reproduce and try to fix this.

hutterm commented 11 months ago

here is a sample project. go to definition on the Prop fails SourceGenTest.zip

SchnozzleCat commented 9 months ago

Edit: Likely related from upstream: https://github.com/dotnet/vscode-csharp/issues/6426

I think this issue is keeping me from searching for workspace symbols using telescope in a project that uses source generators, meaning I would need to search for files instead.

I think a band-aid fix for now would be for this to ignore invalid URIs if possible, that would at least allow searching for non-generated symbols.

I'd be interested in fixing this, as otherwise this client is a lot better than omnisharp, but I have no idea how.

Example from a godot project:

[telescope] [WARN  10:07:55] /nix/store/piv98rgghcipdc380qambds2ks335v5k-vim-pack-dir/pack/myNeovimPackages/start/telescope.nvim/lua/telescope/pickers.lua:661: Finder failed with msg:  {
[telescope]   code = -32000,
[telescope]   data = {
[telescope]     code = -2146233033,
[telescope]     inner = {
[telescope]       code = -2146233033,
[telescope]       message = "Invalid URI: The format of the URI could not be determined.",
[telescope]       stack = "   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)\n   at System.Uri..ctor(String uriString, UriKind uriKind)\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 180",
[telescope]       type = "System.UriFormatException"
[telescope]     },
[telescope]     message = "Failed create URI from 'Godot.SourceGenerators/Godot.SourceGenerators.ScriptPropertyDefValGenerator/Schnozzle.PaletteSwap.PaletteSwapLoaderSingleton_ScriptPropertyDefVal.generated.cs'; original string: 'Godot.SourceGenerators/Godot.SourceGenerators.ScriptPropertyDefValGenerator/Schnozzle.PaletteSwap.PaletteSwapLoaderSingleton_ScriptPropertyDefVal.generated.cs'",
[telescope]     stack = "   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 188\n   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\n   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\n   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\n   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.<>c__DisplayClass13_0.<<GetOnItemFoundCallback>b__0>d.MoveNext() in /_/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.cs:line 46\n--- End of stack trace from previous location ---\n   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.AddResultIfMatchAsync(DocumentKey documentKey, 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 175\n   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.ProcessIndexAsync(DocumentKey documentKey, 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 136\n   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 109\n   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.ProcessDocumentsAsync(Document searchDocument, String patternName, String patternContainer, DeclaredSymbolInfoKindSet kinds, Func`2 onItemFound, HashSet`1 documents, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs:line 95\n   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.SearchGeneratedDocumentsInCurrentProcessAsync(ImmutableArray`1 projects, String pattern, IImmutableSet`1 kinds, Func`2 onItemFound, Func`1 onProjectCompleted, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.GeneratedDocumentSearch.cs:line 75\n   at Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.SearchGeneratedDocumentsAsync(Solution solution, ImmutableArray`1 projects, String searchPattern, IImmutableSet`1 kinds, Document activeDocument, Func`3 onResultFound, Func`1 onProjectCompleted, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.GeneratedDocumentSearch.cs:line 51\n   at Microsoft.CodeAnalysis.NavigateTo.NavigateToSearcher.<>c__DisplayClass24_0.<<SearchGeneratedDocumentsAsync>b__1>d.MoveNext() in /_/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs:line 458\n--- End of stack trace from previous location ---\n   at Microsoft.CodeAnalysis.NavigateTo.NavigateToSearcher.<>c__DisplayClass21_0.<<ProcessOrderedProjectsAsync>g__SearchCoreAsync|0>d.MoveNext() in /_/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs:line 352\n--- End of stack trace from previous location ---\n   at Microsoft.CodeAnalysis.NavigateTo.NavigateToSearcher.ProcessOrderedProjectsAsync(Boolean parallel, ImmutableArray`1 orderedProjects, HashSet`1 seenItems, Func`5 processProjectAsync, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs:line 335\n   at Microsoft.CodeAnalysis.NavigateTo.NavigateToSearcher.SearchAllProjectsAsync(Boolean isFullyLoaded, NavigateToSearchScope scope, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs:line 212\n   at Microsoft.CodeAnalysis.NavigateTo.NavigateToSearcher.SearchAsync(Boolean searchCurrentDocument, NavigateToSearchScope scope, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs:line 152\n   at Microsoft.CodeAnalysis.NavigateTo.NavigateToSearcher.SearchAsync(Boolean searchCurrentDocument, NavigateToSearchScope scope, CancellationToken cancellationToken) in /_/src/Features/Core/Portable/NavigateTo/NavigateToSearcher.cs:line 162\n   at Microsoft.CodeAnalysis.LanguageServer.Handler.WorkspaceSymbolsHandler.HandleRequestAsync(WorkspaceSymbolParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/Symbols/WorkspaceSymbolsHandler.cs:line 69\n   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken)\n   at Microsoft.CommonLanguageServerProtocol.Framework.AbstractLanguageServer`1.DelegatingEntryPoint.EntryPointAsync[TRequest,TResponse](TRequest request, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/AbstractLanguageServer.cs:line 195",
[telescope]     type = "System.UriFormatException"
[telescope]   },
[telescope]   message = "Failed create URI from 'Godot.SourceGenerators/Godot.SourceGenerators.ScriptPropertyDefValGenerator/Schnozzle.PaletteSwap.PaletteSwapLoaderSingleton_ScriptPropertyDefVal.generated.cs'; original string: 'Godot.SourceGenerators/Godot.SourceGenerators.ScriptPropertyDefValGenerator/Schnozzle.PaletteSwap.PaletteSwapLoaderSingleton_ScriptPropertyDefVal.generated.cs'",
[telescope]   <metatable> = {
[telescope]     __tostring = <function 1>
[telescope]   }
[telescope] }
SchnozzleCat commented 9 months ago

I've updated my version to 4.10.0-1.24058.1, which is the version currently tracked by the vs-code plugin. This fixes the issue with workspace symbols throwing an error in telescope for me, but the resulting file is empty.

image

Attempting to navigate to implementations on a partial type with source generated implementations still throws the following error:

Error executing vim.schedule lua callback: ...myNeovimPackages/start/trouble.nvim/lua/trouble/util.lua:158: ENOENT: no such file or directory: source-generated:///Godot.SourceGenerators/Godot.SourceGenerators.ScriptMethodsGenerator/Schnozzle.Logging.Logger_ScriptMethods.generated.cs

Edit: Annoyingly, this still fails if you use a goto_reference on something that has a source generated member...

TimVanDyke commented 5 months ago

I'd be curious if this will work for something like CommunityToolkit.MVVM too. I'd love to use this plugin for MAUI development