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

[BUG] Go to Definition on a source-generated method doesn't work #457

Closed
svick opened this issue Aug 30, 2023 · 4 comments
Closed

[BUG] Go to Definition on a source-generated method doesn't work #457

svick opened this issue Aug 30, 2023 · 4 comments
Assignees
Labels
area-roslyn bug Something isn't working

Comments

@svick
Copy link

svick commented Aug 30, 2023

Describe the Issue

It seems that using Go to Definition on a partial method whose definition comes from a source generator does not work.

Steps To Reproduce

  1. Create a new .Net 7 project.

  2. Add the following code:

    using System;
    using System.Text.RegularExpressions;
    
    partial class Target
    {
        [GeneratedRegex("abc|def", RegexOptions.IgnoreCase, "en-US")]
        private static partial Regex AbcOrDefGeneratedRegex();
    
        static void Main()
        {
            Console.WriteLine(AbcOrDefGeneratedRegex().Match("foo"));
        }
    }
  3. Use Go to Definition on AbcOrDefGeneratedRegex().

  4. Error "Request textDocument/definition failed." pops up. The log contains:

[Error - 4:09:41 PM] [LanguageServerHost]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 174
   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 464
   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 429
   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
[Error - 4:09:41 PM] Request textDocument/definition failed.
  Message: Invalid URI: The format of the URI could not be determined.
  Code: -32000 
[object Object]

Environment Information

  • Latest release (v0.3.21) or pre-release version Dev Kit extension (v0.4.8)
  • v2.0.416 of C# extension
@svick svick added the bug Something isn't working label Aug 30, 2023
@lifengl lifengl added area-project Project load, Solution Explorer and removed area-project-cps labels Sep 1, 2023
@tmeschter tmeschter removed their assignment Sep 5, 2023
@tmeschter tmeschter added area-roslyn and removed area-project Project load, Solution Explorer labels Sep 5, 2023
@tmeschter
Copy link
Member

Moving to area-roslyn as the exception is coming from the Language Server and does not seem to involve the .NET Project System.

@arunchndr
Copy link
Member

Possibly related to dotnet/vscode-csharp#6256 (comment).

@svick could you set the 'dotnet.server.trace' setting to 'Trace' and attach the contents of the C# LSP trace logs? That should tell us what URI its throwing on.

@svick
Copy link
Author

svick commented Sep 12, 2023

@arkalyanms I'm currently on vacation, so I might not be able to do that soon. But the steps I provided should be enough for you to reproduce it yourself.

@arunchndr
Copy link
Member

Ah yes this repros only with C# Dev Kit installed. Solo C# seems fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-roslyn bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants