63

I installed Visual Studio Code 1.1 with the C/C++ extension, opened my C++ project and tried to use "Go to definition" in vain.

The "Go to definition" is not working at all. Example, go to definition of a class member:

int i = m_myVar;

(I opened a simpler project with one file and it was working for this one)

In the end, what I want is good indexation of my big project, is there a way to install Intellisense?

Gama11
  • 31,714
  • 9
  • 78
  • 100
Nicosmik
  • 791
  • 1
  • 5
  • 7

25 Answers25

85

I had a the same issue: F12 and Ctrl + Click and Right Click "Go To Definition" wasn't working. The fix for me was:

  1. Go to Extensions
  2. Click "Disable All Installed Extensions"
  3. Close and Reopen VS Code
  4. Back to Extensions and "Enable All Extensions"

Essentially enable/disable all extensions fixed the issue.

Dmitriy R. Starson
  • 1,180
  • 8
  • 9
23

I recently came across this same issue and after trying all of the suggested solutions I could find with no success, I found this article:

https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc

Basically my project grew too large and VS code was no longer able to track all files, which messed up the "go to definition" functionality.

After following the steps on the link to increase the maximum number of files to be tracked, the issue was resolved.

The correction is pretty simple (tested on Ubuntu 18.04):

Add this line:

fs.inotify.max_user_watches=524288

to the end of the file /etc/sysctl.conf

After saving, run the following command:

sudo sysctl -p

Hopefully this will be useful to someone else, this has been bothering me for the last few days.

hermesfelipe
  • 355
  • 2
  • 5
12

I had a similar problem except with Python and google searches for solutions kept bringing me back to this post so I figured I'd post my solution here in the hopes that it might help other people.

I was working on a remote cluster through VScode Remote and was getting similar errors to the original question(all 'go to ___' functionality was unavailable and was even getting a 'too large to track' error) and I thought I had to increase the number of watches, which didn't end up helping.

All I needed to do was install a python interpreter on the remote VScode server. This fixed my problem.

MattyIce
  • 121
  • 1
  • 6
7

I believe vscode 1.1 (well, 1.1.1 actually) + the C++ extension (cpptools) is as much Intellisense as we can get for now.

You should load your big project with the "open folder" function to make vscode know about the other files.

https://blogs.msdn.microsoft.com/vcblog/2016/03/31/cc-extension-for-visual-studio-code/ warns about letting the indexing finish first (red icon in lower right corner during indexing) and mentions the current limitations on the source code parsing.

Frank T
  • 116
  • 1
  • 1
    The flaming red platform icon, which denotes parsing in progress is **red since more than 30 minutes**. So I have no parsing at all. My colleagues have their same issue on their projects. – Nicosmik May 26 '16 at 13:27
  • 4
    I can't even get this "red icon" to appear - I've added several folders to my c_cpp_properties.json file and still no dice. (running on linux) – dtmland Oct 05 '16 at 17:32
  • 1
    Don't worry folks, the feature doesn't even work in VS2017 pro! – A.R. Mar 13 '18 at 02:56
4

Have you saved your workspace? Or did you just open a folder with File->Open Folder? This question already has many answers, but none of them address this case, which was my issue.

The question is not specific enough for me to know if you are having the exact same symptoms as my case.

If:

  • You have not saved your workspace. vscode doesn't say "(workspace)" at the top of the window.
  • None of the goto functions are working, but instead report: "No ___ found for ____"
  • The tag parser database icon in the bottom right is always there but only reports "Parsing open files", rather than telling you how many files have been parsed.

Then:

Try saving your workspace.

Saving workspace

3

I tried the methods mentioned in this thread none of them seemed to work for me. A simple solution that worked for me is that I closed the current workspace and created a new workspace, added the folders which I required(same as the old workspace), and saved the new workspace. Waited for a couple of minutes to index and IntelliSense is able to find definitions now.

omniSlash
  • 69
  • 4
3

I am using VSCode 1.52.1 on Ubuntu 20.04.

In my case, for whatever reason,c_cpp_properties.json has become set to Disabled in ~/.config/Code/User/settings.json.

Manually changing it to Enabled solved the problem.

gh-tera
  • 31
  • 1
  • Thanks for pointing me in the right direction. I had a line there that was disabling Intellisense. "C_Cpp.intelliSenseEngine": "disabled", – Sebastian Hölzer Feb 01 '23 at 15:18
3

It wasn't working on my laptop as well after installing a few VSCode extensions. I decided to close and re-open VSCode with administrator permission and suddenly it sorted out.

Kevy Granero
  • 643
  • 5
  • 17
2

I have been trying to fix this for a long time. In the end, what worked for me was simply reinstalling VSCode, then installing the latest C/C++ extension (v0.18.1). Then, in your .vscode/c_cpp_properties.json file, under includePath, add your include folder which has all your header files.

Nik
  • 2,885
  • 2
  • 25
  • 25
bunbun
  • 2,595
  • 3
  • 34
  • 52
2

Fixed mine by UNCHECKING C_Cpp > Default > Limit Symbols To Included Headers Your mileage may vary. Good luck!

Daniel Ames
  • 66
  • 1
  • 6
  • Can you explain at all why this might have worked? – Stun Brick Jul 26 '22 at 06:28
  • 3
    I wish I could, my friend. This very very common problem seems to have a zillion different possible causes. Just google this and you'll find so many different answers. With no magic bullet to be found, I just started combing through my own settings looking for suspicious things. I saw this and was like, "well, I guess if it's only searching includes for symbols, that would be bad." Since my project is for UEFI, which has definitions scattered throughout hundreds of files, that are all included and linked by the uefi build, not necessarily by a traditional #include. – Daniel Ames Jul 26 '22 at 22:53
  • Agreed, it's almost impossible to find out. Disable+Enable all extensions (see below), for Typescript importing Types (extension .d.ts) often works, for Angular supposedly one should [install the Angular Language Service Extension](https://angular.io/guide/language-service#:~:text=In%20Visual%20Studio%2C%20install%20the,and%20click%20the%20Install%20button), on other occasions, including plain javascript it's just a complete guess... :-/ – Frank N Jul 30 '22 at 10:45
1

If you have multiple versions of a language on your PC, specify the exact language you are using in the VScode(in my case, I am using Python, so I must specify the version to the python Interpreter in VS Code)

If you could not do it whatsoever, then uninstall all the other versions that you don't use and then if you go to VS Code, it will ask the version to be used, and you would have only one version, so when you select the version, the "Go To Definition" will be activated.

Nikhil MVS
  • 31
  • 1
  • 4
1

I was having a similar issue with java on Ubuntu 20.04 using OpenJDK version 11 (openjdk-11-jdk in apt). At first I didn't have the JRE installed, so I installed it and it still didn't work.

Afterwards, I went to the CTRL + SHIFT + P menu and then to Java: Configure Java Runtime, there I saw in the Java Tooling Runtime tab that /usr/lib/jvm/java-11-openjdk-amd64 was selected, changed it to /usr/lib/jvm/java-1.11.0-openjdk-amd64 just to see if it would work, and after a restart it did. I'm not sure why this is, but I hope it may help somone else.

Devyzr
  • 299
  • 5
  • 13
1

For python ensure your code analysis settings are correct. In my case the languageServer was accidentally set to 'None'. Reverting it to 'default' or 'pylance' did the trick.

Sumeet Singh
  • 331
  • 2
  • 7
0

Just to inform if none of above works then In my case i was using Kite extension in my VS code, I just disabled it and it worked. I think kite extension is blocking this feature.

Rushbh
  • 1
0

OS: Linux Ubuntu 22.04

if you encountered with following error:

"The .NET Core SDK cannot be located. .NET Core debugging will not be enabled. Make sure the .NET Core SDK is installed and is on the path."

enter image description here

Normally Vscode remains unable to locate .Net sdk. need to set path manually.

sudo ln -s /snap/dotnet-sdk/current/dotnet /usr/local/bin/dotnet

restart omnisharp & restart vscode

Mehran Khan
  • 960
  • 1
  • 6
  • 16
0

No need to do anything. Just close and re-open. It will work.

Vinit Bodhwani
  • 413
  • 1
  • 5
  • 16
0

All of the above didn't work for me as well as web searched answers for similar and peek that doesn't work. My environment is Windows based and working at vsCode over Ubuntu 20 with ssh.

The root cause at my case was local Windows vsCode file:

C:\Users\<user>\AppData\Roaming\Code\User\settings.json

included Disabled at C_Cpp.intelliSenseEngine field. when changed to enabled it was working, and so on, now all web explanations of search folders, such as it's written at https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference become relevant

The key factor is to edit the local machine setting, and not the remote machine setting.json, though the c_cpp_properties.json to be edited is in the remote machine

Once it's working, setting remote VM (working area) file of .vscode/c_cpp_properties.json with "intelliSenseMode" and "includePath" according to directives at the above link and https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options along with enabled squiggles (at vsCode setings): enter image description here

provides a working environments with ability to navigate well for definitions and pick options

GM1
  • 380
  • 3
  • 14
0

Check if the language extension or IntelliSense is working properly. You can try updating the extension or IntelliSense, or checking if the feature is supported for the language you are using.

For me it was C/C++ i re-installed the extension and that fixed it.

Haseeb Mir
  • 928
  • 1
  • 13
  • 22
0

In my case, I just installed extension named "C/C++ Extension Pack", restart VS code, then all good"

Charlie
  • 639
  • 9
  • 19
0

clangd plugin

For C/C++, I highly recommend looking into the clangd plugin: https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd which integrates clangd into vscode.

This plugin parses code using clang based on a compile_commads.json database which contains the exact compilation commands as produced by the build system, and as a result tends to produce the most accurate results. Furthermore it also automatically ignores large directories for you, which is a big problem in large projects:

How to setup VS Code for C++ with clangd support? provides some working configurations:

  "C_Cpp.intelliSenseEngine": "Disabled",
        
    "clangd.path": "/path/to/your/clangd",
    "clangd.arguments": ["-log=verbose", 
                         "-pretty", 
                         "--background-index", 
                         //"--query-driver=/bin/arm-buildroot-linux-gnueabihf-g++", //for cross compile usage
                         "--compile-commands-dir=${workspaceFolder}/build/"]

supposing that your build system places compile_commands.json under the build/ directory.

Generating compile_commands.json is already supported by many build systems, e.g. CMake: CMake not generating compile_commands.json

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
0

Just Uninstall all the extensions and then reinstall them. It worked for me.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 29 '23 at 14:28
0

Coming with the same issue to this question, but in a Golang project,

Go to definition and F12 didn't work (they say there is no definition, but there is)

My problem was because of inconsistent vendoring that caused go.mod problem and the error below at the bottom of my VS code:

Go to definition does not work

And I solved it by running go mod tidy + go mod vendor.

You may need to follow the same approach in some other languages.

Arsham Arya
  • 1,461
  • 3
  • 17
  • 25
0

Go to VSCode "Extentions" tab (Ctrl+Shift+X) :

If you have not C/C++ extention pack, you should search and install it.


If you have that :

  • Disable it.
  • Enable it again. (VSCode will reload itself)

enter image description hssere

logico
  • 43
  • 1
  • 6
-2

I also faced similar problem. In my mac os cmnd + 'click' is used to 'go to definition' then it suddenly stoped working. If that is the case then please follow these steps:

  1. restart vs code
  2. restart pc
  3. uninstall all extensions and reinstall again followed by a pc restart.
Pritom
  • 321
  • 3
  • 6
-3

I had a similar issue with the extension C/C++ installed. I solved it by downloading an older version of the extension and upgrading to the last version. Somehow it solved the problem...

Xantios
  • 19
  • 1
  • 6
    Please see [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) from StackOverflow Help. – coderpc Dec 20 '19 at 22:17