dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19k stars 4.03k forks source link

Cannot "Go To Definition" of a type keyword if you are within that type in decompilation #25301

Open davkean opened 6 years ago

davkean commented 6 years ago

(Turn on decompilation)

  1. Create Console App (.NET Framework)
  2. In the following, CTRL+Click int
    class Program
    {
        static void Main(string[] args)
        {
            int foo;
        }
    }
  1. When prompted say Yes to decompile
  2. Scroll down to bool TryParse(string s, out int result)
  3. try and CTRL+Click int

Expected: To go to the top of the class to the definition Actual: It's not clickable

siegfriedpammer commented 6 years ago

I just had a look at this and I discovered the following difference between metadata view and decompiled view:

Decompiled view: grafik

Metadata view: grafik

Notice the use of int (decompiler) vs. Int32 (metadata)... seems that VS cannot deal with the keyword, if it's the containing type. Note that other "primitive types" still use the keyword, even in metadata view.

Are we forced to include additional logic in the decompiler to output types in the same manner, or can we convince VS to treat the keyword and the type name the same?

sharwell commented 6 years ago

Are we forced to include additional logic in the decompiler to output types in the same manner, or can we convince VS to treat the keyword and the type name the same?

I would prefer the latter (fix VS to allow Go To Definition on keywords in metadata).

siegfriedpammer commented 6 years ago

So far I have found that it works up to this point:

https://github.com/dotnet/roslyn/blob/11541f4de596c3a9973c1af9bd7d5b683770dc04/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs#L32-L42

An int keyword properly gets identified as System.Int32 and the definition is found, but d.CanNavigateTo(...) returns false, because

https://github.com/dotnet/roslyn/blob/11541f4de596c3a9973c1af9bd7d5b683770dc04/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs#L101-L122

On line 120 the call to SymbolKey.Resolve fails.

Actually, I am not sure where to go from here to find a solution to this problem. I don't know Roslyn very well yet... any help would be very much appreciated!