Skip to content

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

Closed as not planned
@arunchndr

Description

@arunchndr

From vscode-dotnettools created by svick: microsoft/vscode-dotnettools#457

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions