C++ VSCode“转到定义”不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37341849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VSCode "go to definition" not working
提问by Nicosmik
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.
我安装了带有 C/C++ 扩展的 Visual Studio Code 1.1,打开了我的 C++ 项目并尝试使用“转到定义”但徒劳无功。
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?
最后,我想要的是我的大项目的良好索引,有没有办法安装 Intellisense?
回答by Frank T
I believe vscode 1.1 (well, 1.1.1 actually) + the C++ extension (cpptools) is as much Intellisense as we can get for now.
我相信 vscode 1.1(嗯,实际上是 1.1.1)+ C++ 扩展(cpptools)是我们目前所能获得的智能感知。
You should load your big project with the "open folder" function to make vscode know about the other files.
您应该使用“打开文件夹”功能加载您的大项目,以使 vscode 了解其他文件。
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.
https://blogs.msdn.microsoft.com/vcblog/2016/03/31/cc-extension-for-visual-studio-code/警告让索引首先完成(索引期间右下角的红色图标)和提到了当前对源代码解析的限制。
回答by bunbun
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.
我一直试图解决这个问题很长时间。最后,对我有用的只是重新安装 VSCode,然后安装最新的 C/C++ 扩展 (v0.18.1)。然后,在您的.vscode/c_cpp_properties.json
文件中的 下includePath
,添加包含所有头文件的包含文件夹。
回答by hermesfelipe
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:
我最近遇到了同样的问题,在尝试了所有我找不到的建议解决方案后,我发现了这篇文章:
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.
基本上我的项目变得太大了,VS 代码不再能够跟踪所有文件,这弄乱了“转到定义”功能。
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):
更正非常简单(在 Ubuntu 18.04 上测试):
Add this line:
添加这一行:
fs.inotify.max_user_watches=524288
to the end of the file /etc/sysctl.conf
到文件末尾 /etc/sysctl.conf
After saving, run the following command:
保存后,运行以下命令:
sudo sysctl -p
须藤 sysctl -p
Hopefully this will be useful to someone else, this has been bothering me for the last few days.
希望这对其他人有用,这最近几天一直困扰着我。
回答by Xantios
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...
我在安装扩展 C/C++ 时遇到了类似的问题。我通过下载旧版本的扩展并升级到最新版本来解决它。不知怎的,它解决了这个问题......
回答by Xingjun Tan
Make sure you have installed the extension "C/C++". Please refer to https://code.visualstudio.com/docs/languages/cpp
确保您已安装扩展“C/C++”。请参考https://code.visualstudio.com/docs/languages/cpp