dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 670 forks source link

Go to definition navigates to Metadata instead of decompiled source code. #5574

Open ghost opened 1 year ago

ghost commented 1 year ago

Issue Description

Go to definition navigates to Metadata instead of decompiled source code. I am using Kubernetes client library and trying to navigate to the decompiled source code using "Go To Definition". However, I am being navigated to the Metadata for the navigated method instead of the decompile source code. Hovering over the method name when pressing the CMD key (I have different key mappings), it shows me" 2 implementation available". However, when I try navigating to implementation, I am given a "FileNotFound exception in the Omnisharp Logs and the editor window. The editor windows have error - "The editor could not be opened because the file was not found, Create File ".

The path shown in gutter is the same that I see in omnisharp logs - /$metadata$/Project/<Redacted>/<Redacted>/Assembly/KubernetesClient/Basic/Symbol/k8s/IAppsV1Operations.cs

I guess, $metadata$ is not resolved before handing over request to file system because when I click on "Create file", I get the following error in a popup window - Unable to write file /$metadata$/Project/<Redacted>/<Redacted>/Assembly/KubernetesClient/Basic/Symbol/k8s/IAppsV1Operations.cs' (Unknown (FileSystemError): Error: EROFS: read-only file system, mkdir '/$metadata$')

Steps to Reproduce

Expected Behavior

Should have navigated to decompiled source in editor.

Actual Behavior

Navigating to Metadata instead of source code. On next attempt of "go to definition" from the shown metadata, getting a File Not found error.

Logs

OmniSharp log

Starting OmniSharp server at 2/5/2023, 9:20:08 PM
    Target: /Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/<Redacted>.sln

OmniSharp server started with .NET 7.0.102
.
    Path: /Users/ankurtyagi/.vscode/extensions/ms-dotnettools.csharp-1.25.4-darwin-arm64/.omnisharp/1.39.4-net6.0/OmniSharp.dll
    PID: 24665

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Unknown 0.0 (Unknown)
[info]: OmniSharp.Services.DotNetCliService
        Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
[info]: OmniSharp.Services.DotNetCliService
        Using the 'dotnet' on the PATH.
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 4 MSBuild instance(s)
            1: .NET Core SDK 7.0.102 17.4.1 - "/usr/local/share/dotnet/sdk/7.0.102/"
            2: .NET Core SDK 7.0.101 17.4.0 - "/usr/local/share/dotnet/sdk/7.0.101/"
            3: .NET Core SDK 6.0.405 17.3.2 - "/usr/local/share/dotnet/sdk/6.0.405/"
            4: .NET Core SDK 6.0.403 17.3.2 - "/usr/local/share/dotnet/sdk/6.0.403/"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: .NET Core SDK 7.0.102 17.4.1 - "/usr/local/share/dotnet/sdk/7.0.102/"
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Did not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/<Redacted>.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/src/<Redacted>.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/src/<Redacted>.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/src/<Redacted>.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/test/<Redacted>.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/test/<Redacted>.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/test/<Redacted>.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Did not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc' on host 24615.
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/src/<Redacted>.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/src/<Redacted>.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/src/<Redacted>.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/src/<Redacted>.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/src/<Redacted>.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/src/<Redacted>.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/src/<Redacted>.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/src/<Redacted>.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/src/<Redacted>.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/test/<Redacted>.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/test/<Redacted>.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/test/<Redacted>.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/test/<Redacted>.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/test/<Redacted>.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/test/<Redacted>.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/test/<Redacted>.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/test/<Redacted>.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/ankurtyagi/workspace/Compute-CCI-ExecSvc/test/<Redacted>.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: <Redacted>
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: <Redacted>
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: <Redacted>
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: <Redacted>
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: <Redacted>
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: <Redacted>
[info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers
        Solution initialized -> queue all documents for code analysis. Initial document count: 158.
Received response for /v2/gotodefinition but could not find request.
Received response for /findusages but could not find request.
[warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService
        No document found. File: $metadata$/Project/<Redacted>/<Redacted>/Assembly/KubernetesClient/Basic/Symbol/k8s/IAppsV1Operations.cs.
[warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService
        No document found. File: $metadata$/Project/<Redacted>/<Redacted>/Assembly/KubernetesClient/Basic/Symbol/k8s/IAppsV1Operations.cs.
[warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService
        No document found. File: $metadata$/Project/<Redacted>/<Redacted>/Assembly/KubernetesClient/Basic/Symbol/k8s/IAppsV1Operations.cs.

C# log

Empty

Environment information

VSCode version: 1.74.3 C# Extension: 1.25.4

Mono Information There is a problem with running OmniSharp on mono: Error: Unable to find Mono. Ensure that Mono's '/bin' folder is added to your environment's PATH variable.
Dotnet Information .NET SDK: Version: 7.0.102 Commit: 4bbdd14480 Runtime Environment: OS Name: Mac OS X OS Version: 13.2 OS Platform: Darwin RID: osx.13-arm64 Base Path: /usr/local/share/dotnet/sdk/7.0.102/ Host: Version: 7.0.2 Architecture: arm64 Commit: d037e070eb .NET SDKs installed: 6.0.403 [/usr/local/share/dotnet/sdk] 6.0.405 [/usr/local/share/dotnet/sdk] 7.0.101 [/usr/local/share/dotnet/sdk] 7.0.102 [/usr/local/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Other architectures found: None Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |auto-using|Fudge|0.7.15| |codespaces|GitHub|1.13.7| |copilot|GitHub|1.71.8269| |csharp|ms-dotnettools|1.25.4| |dotnet-test-explorer|formulahendry|0.7.8| |EditorConfig|EditorConfig|0.16.4| |intellij-idea-keybindings|k--kato|1.5.5| |namespace|adrianwilczynski|1.1.2| |nuget-reverse-package-search|jesschadwick|0.1.68| |powershell|ms-vscode|2023.1.0| |roslynator|josefpihrt-vscode|4.2.0| |vscode-icons|vscode-icons-team|12.2.0| |vscode-proto3|zxh404|0.5.5|;
filipw commented 1 year ago

Did you enable decompilation support? there is a setting "omnisharp.enableDecompilationSupport": true

filipw commented 1 year ago

Navigating to Metadata instead of source code. On next attempt of "go to definition" from the shown metadata, getting a File Not found error.

however, this (navigation within the metadata/decompiled source) is not currently supported, also not for decompiled sources.

You can navigate from source to metadata (or decompiled source) and from metadata to metadata in another file (or in another decompiled source), but not from metadata to metadata in the same file (or in the same decompile source).

ghost commented 1 year ago

Did you enable decompilation support? there is a setting "omnisharp.enableDecompilationSupport": true

Yes, it's enabled and the Terms Agreement is also accepted.

Navigating to Metadata instead of source code. On next attempt of "go to definition" from the shown metadata, getting a File Not found error.

however, this (navigation within the metadata/decompiled source) is not currently supported, also not for decompiled sources.

You can navigate from source to metadata (or decompiled source) and from metadata to metadata in another file (or in another decompiled source), but not from metadata to metadata in the same file (or in the same decompile source).

Thanks, I didn't know this. Though it seems to be very weird limitation. Any Idea, if this is being worked upon or planned ?

Anyhow, Navigating (using GoToDefinition) from Source to decompiled source should work but rather I get navigated to metadata instead.

filipw commented 1 year ago

Anyhow, Navigating (using GoToDefinition) from Source to decompiled source should work but rather I get navigated to metadata instead.

I think something is wrong with the extension passing the options to OmniSharp then. You should be able to use the following workaround:

Create a file omnisharp.json at ~/.omnisharp/omnisharp.json with the following content and restart OmniSharp.

{
    "RoslynExtensionsOptions": {
        "EnableDecompilationSupport": true
    }
}