简体   繁体   English

设置 VSCode 以包含/排除 C++ 智能感知的文件夹

[英]Setting up VSCode to include/exclude folders for C++ intellisense

I often have a project with CMake to manage my build system.我经常有一个 CMake 项目来管理我的构建系统。 So you can imagine I would have a load of third-party headers, and my own headers within my install folder.所以你可以想象我会在我的安装文件夹中有很多第三方头文件和我自己的头文件。

This is extremely troublesome when I have 2 copy of the same header: one in my install folder (old one) and the one I'm modifying right now (new one).当我有两个相同标题的副本时,这非常麻烦:一个在我的安装文件夹中(旧的),而我现在正在修改的一个(新的)。 When that happens, sometimes intellisense won't know which is the correct one and might think that my function signature is wrong (because it is looking at the older version).发生这种情况时,有时智能感知不知道哪个是正确的,并且可能认为我的函数签名是错误的(因为它正在查看旧版本)。

Same problem when you trying to Ctrl + Left click into a class/function in order to quickly navigate to its definition.当您尝试 Ctrl + 左键单击类/函数以快速导航到其定义时,同样的问题。 It might direct me to the wrong file (in install folder) and thus modify that file won't have an effect in the project (since the "real" file will quickly modify the old one).它可能会将我引导到错误的文件(在安装文件夹中),因此修改该文件不会对项目产生影响(因为“真实”文件将快速修改旧文件)。

An example of what my include folder structure in my install folder:我的安装文件夹中include文件夹结构的示例:

- boost
    |- fake_boost_header.h
- eigen
    |- not_reap_eigen_header.h
- abseil
    |- real_fake_abseil_header.h
- my_header.h
- my_other_header.h

I have tried the following solution, but seems like it is not working:我尝试了以下解决方案,但似乎不起作用:

Have includePath in c_cpp_properties.json to be install/include/<all_third_party_folder> .将 c_cpp_properties.json 中的 includePath 设置为install/include/<all_third_party_folder>

Any idea is welcome.欢迎任何想法。 I'm more than open to use third-party plugin...我非常愿意使用第三方插件...

It seems to me your install/include/<...> solution does the opposite of what you want, in that it will guarantee VS Code finds the headers in your install folder first.在我看来,您的install/include/<...>解决方案与您想要的相反,因为它将保证 VS Code 首先在您的install文件夹中找到标头。 You probably want include/** so that it searches all subdirectories in your include folder, assuming that's where the headers are that need editing.您可能需要include/**以便它搜索include文件夹中的所有子目录,假设这是需要编辑的标题。

I'm not sure why you'd want VS Code to know about your install folder, as that's the output of your build / code generation process.我不确定您为什么希望 VS Code 了解您的安装文件夹,因为这是您的构建/代码生成过程的输出。 If you need versions of third-party code in your install folder, have your build process copy them in from somewhere in your source tree, so that you're not mixing (external) source code and generated code in the same directory.如果您需要安装文件夹中的第三方代码版本,请让您的构建过程从源代码树的某个位置复制它们,这样您就不会在同一目录中混合(外部)源代码和生成的代码。 That is, treat the third party code as source code in itself, even if the only thing you do with it is copy it into your install folder.也就是说,将第三方代码本身视为源代码,即使您对它所做的唯一事情是将其复制到您的install文件夹中。 Then you can add the install folder to the list of excluded folders in .vscode/settings.json to avoid VS Code searching those directories:然后,您可以将install文件夹添加到.vscode/settings.json中的排除文件夹列表中,以避免 VS Code 搜索这些目录:

{
    ...
    "C_Cpp.files.exclude": {
        "install/**": true,
        ...
    },
    "files.watcherExclude": {
        "install/**": true,
        ...
    },
    "search.exclude": {
        "install/**": true,
        ...
    },
    "files.exclude": {
        "install/**": true,
        ...
    },
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM