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 of partial class involved with source generators errors #178

Open
lem102 opened this issue Jul 21, 2024 · 4 comments
Open

Comments

@lem102
Copy link

lem102 commented Jul 21, 2024

OS: Windows 10
Editor: emacs 29.3
LSP Client: eglot 1.17

When I try go to definition of one of the partial classes in my godot project, csharp-ls throws an exception:

jsonrpc-request: jsonrpc-error: "request id=4 failed:", (jsonrpc-error-code . -32603), (jsonrpc-error-message . "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)
   at CSharpLanguageServer.Conversions.Uri.fromPath(String path) in /_//src/CSharpLanguageServer/Conversions.fs:line 25
   at CSharpLanguageServer.Conversions.Location.fromRoslynLocation(Location loc) in /_//src/CSharpLanguageServer/Conversions.fs:line 71
   at <StartupCode$CSharpLanguageServer>[email protected](Unit unitVar) in /_//src/CSharpLanguageServer/State/ServerRequestContext.fs:line 94
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\async.fs:line 508
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\async.fs:line 112"), (jsonrpc-error-data)

After adding some logging, I can see that this is because the locations from the Roslyn symbol refer to the class I have created, and the partial filepaths of Godot's source generated classes. The latter aren't valid URIs, so the above exception is thrown.

d:\programming\non-projects\Godot\2024NewGame\FollowMob.cs
Godot.SourceGenerators\Godot.SourceGenerators.ScriptPathAttributeGenerator\FollowMob_ScriptPath.generated.cs
Godot.SourceGenerators\Godot.SourceGenerators.ScriptSerializationGenerator\FollowMob_ScriptSerialization.generated.cs
Godot.SourceGenerators\Godot.SourceGenerators.ScriptMethodsGenerator\FollowMob_ScriptMethods.generated.cs
Godot.SourceGenerators\Godot.SourceGenerators.ScriptPropertyDefValGenerator\FollowMob_ScriptPropertyDefVal.generated.cs
Godot.SourceGenerators\Godot.SourceGenerators.ScriptPropertiesGenerator\FollowMob_ScriptProperties.generated.cs
Godot.SourceGenerators\Godot.SourceGenerators.ScriptSignalsGenerator\FollowMob_ScriptSignals.generated.cs

A similar error occurs on find references.

I'd like to submit a PR to sort this, but am currently at a loss on how to:

  1. Know that a location is for a source generated file (I could look for ".generated.cs" but not sure if this is a good idea).
  2. Get the correct filepath for the source generated classes.

Any pointers would be helpful 🙂

@razzmatazz
Copy link
Owner

Hey @lem102

(1) I think this is what you are looking after: https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.documentinfo.isgenerated?view=roslyn-dotnet-4.7.0

(2) Most likely you need to figure the schema yourself and implement this. Note that there is a similar code where URIs are generated for source-code-from-metadata, so that may be helpful to you:

Please do not hesitate to ask! Also, -- this server is a bit of a hack -- feel free to improvise :)

@drzbida
Copy link

drzbida commented Aug 20, 2024

can confirm this also happens with windows 11, neovim v0.10.0 in a godot project for goto definition, implementations, references, etc

i've tried to fix this for a few days, but with no F# experience and poor lsp knowledge I didn't have any results

for anyone else trying this, it seems vscode-csharp faced the same issue (and possibly partially fixed?)

dotnet/vscode-csharp#6445
dotnet/vscode-csharp#5858

@repelliuss
Copy link

I also suffer from this

@razzmatazz
Copy link
Owner

#189 looks very much related to this issue, has been merged and should fix part of the problem–it does not show refs to generated code but does not break find-references at very least.

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

No branches or pull requests

4 participants