Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode "go to definition" not working

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?

like image 290
Nicosmik Avatar asked May 20 '16 08:05

Nicosmik


People also ask

How do you activate go to definition in VS Code?

Go to Definition If a language supports it, you can go to the definition of a symbol by pressing F12. Tip: You can jump to the definition with Ctrl+Click or open the definition to the side with Ctrl+Alt+Click.

Why is IntelliSense not working in VS Code?

Troubleshooting. If you find IntelliSense has stopped working, the language service may not be running. Try restarting VS Code and this should solve the issue. If you are still missing IntelliSense features after installing a language extension, open an issue in the repository of the language extension.

How do you jump to a line in VS Code?

The Go To Line dialog box lets you move to a specific line in the active document. To access this dialog box, open a document for editing, and then select Edit > Go To > Go To Line or press Ctrl+G.


4 Answers

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.

like image 54
hermesfelipe Avatar answered Oct 24 '22 05:10

hermesfelipe


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.

like image 40
Frank T Avatar answered Sep 25 '22 22:09

Frank T


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.

like image 23
Dmitriy R. Starson Avatar answered Oct 24 '22 05:10

Dmitriy R. Starson


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.

like image 9
MattyIce Avatar answered Oct 24 '22 04:10

MattyIce