Tuesday, February 6, 2024

[SOLVED] Visual Studio Code C# - Go to Implementations/Definitions broken after reinstall

Issue

I have a bunch of C+ files that I have to convert to Python. For that I installed VSC on Linux and opened the folder with the C# files. I was able to press F12 on a function call to jump to the definition - very helpful.
Yesterday I accepted the upgrade message for several files and ended up with an error of missing dotnet8 SDK. I have tried to install from the MS repository, but without success.
To make a long story short I finally uninstalled everything and installed VSC new (from the repository http://packages.microsoft.com/repos/code/).

Now the "Go to definition" Function always states "No definition found for ", even when it's in the same file.

I have absolutely no knowledge about VSC. I don't even know what information I can post here. I only have these few files. It's not a runable project, but the code search did work before.

What am I missing? The python part is done with PyCharm, not with VSC.

I open the folder with the C# files in VSC.
Then open a file from the list.
Then place the cursor on a function call and press F12 (or right mouse button) to go to implementation or definition.

It should jump to that part in the code.


Solution

Code navigation (as well as code completion, refactoring, etc) are provided by the LSP. Originally built for vscode, it's now been adopted by others (including neovim).

For C# in VSCode, this is provided by the C# Extension (used to be called OmniSharp, so you might still see the old name in some documentation). The easiest way is to install it from the "Extensions" tab (side tab? I don't know what they call it). Do a search for it, and install either the C# extension by itself, or as part of the C# Dev Kit extension (which bundles it with a couple others).

If it's already installed, try removing it and reinstalling. If it still fails try nuking your ~/.vscode dir, and potentially ~/.config/Code as well (and lose all your config!)

Also, make sure you actually have .NET 8 SDK installed. Run dotnet --list-sdks on the terminal.



Answered By - NPras
Answer Checked By - David Goodson (WPSolving Volunteer)