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]: Cannot go to definition of source-generated type #70832

Closed
just-ero opened this issue Nov 15, 2023 · 2 comments
Closed

[Bug]: Cannot go to definition of source-generated type #70832

just-ero opened this issue Nov 15, 2023 · 2 comments
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@just-ero
Copy link

just-ero commented Nov 15, 2023

Version Used

  • Compiler version: '4.9.0-1.23530.4 (79d1884)'
  • VSCode: 1.84.2, 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e, x64
  • C# extension: v2.10.28, C# Dev Kit extension: v1.1.9

Steps to Reproduce

A minimal repro can be found at the end of this issue.

  1. Create or open any C# project.
  2. Add a package reference to any package which source-generates types.
  3. Attempt to navigate to the definition of any of those types.

Expected Behavior

The navigation to the definition succeeds.

Actual Behavior

The navigation fails with an error message from the C# extension similar to the one below (the URI will of course differ):

[Error - 4:33:49 PM] [LanguageServerHost] System.UriFormatException: Failed create URI from 'PolySharp.SourceGenerators\PolySharp.SourceGenerators.PolyfillsGenerator\System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.g.cs'; original string: 'PolySharp.SourceGenerators\PolySharp.SourceGenerators.PolyfillsGenerator\System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.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 System.Uri..ctor(String uriString, UriKind uriKind)
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.CreateAbsoluteUri(String absolutePath) in /_/src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 178
   --- 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 124
[Error - 4:33:49 PM] Request textDocument/definition failed.
  Message: Failed create URI from 'PolySharp.SourceGenerators\PolySharp.SourceGenerators.PolyfillsGenerator\System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.g.cs'; original string: 'PolySharp.SourceGenerators\PolySharp.SourceGenerators.PolyfillsGenerator\System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.g.cs'
  Code: -32000 
[object Object]

Minimal repro

MyProject.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <LangVersion>9.0</LangVersion>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="PolySharp" Version="1.13.2" />
  </ItemGroup>

  <PropertyGroup>
    <PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
  </PropertyGroup>

</Project>

Class1.cs

namespace MyProject
{
    public class Class1
    {
        // Hovering over this attribute and hitting `Ctrl` shows a Visual Studio Code pop-up saying
        // 'Request textDocument/definition failed.' and does not allow navigation.
        [MemberNotNullWhen(true)]
        public bool Foo { get; }
    }
}
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 15, 2023
@davidwengier
Copy link
Contributor

FYI @jasonmalinowski

Not sure you have another tracking issue to dupe this against for #68771

@jasonmalinowski
Copy link
Member

jasonmalinowski commented Nov 17, 2023

I think dotnet/vscode-csharp#6426 is the tracking bug.

@jasonmalinowski jasonmalinowski closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants