简体   繁体   English

VSCode intellisense与C ++标头

[英]VSCode intellisense with C++ headers

I have searched for this but I can't find anything. 我搜索过这个但是找不到任何东西。 If it's dupe I will close my question without any problem. 如果它是愚蠢的,我将毫无问题地结束我的问题。 I have a c_cpp_properties.json configuration file in VSCODE 我在VSCODE中有一个c_cpp_properties.json配置文件

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/usr/include",
                "/usr/local/include",
                "${workspaceRoot}"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "/usr/include",
                    "/usr/local/include",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
            "name": "Linux",
            "includePath": [
                "/usr/include/x86_64-linux-gnu/c++/5",
                "/usr/include/c++/5",
                "/usr/local/include",
                "/usr/include/x86_64-linux-gnu",
                "/usr/include",
                "${workspaceRoot}"
            ],
            "defines": [],
            "intelliSenseMode": "clang-x64",
            "browse": {
                "path": [
                    "/usr/include/x86_64-linux-gnu/c++/5",
                    "/usr/include/c++/5",
                    "/usr/local/include",
                    "/usr/include/x86_64-linux-gnu",
                    "/usr/include",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
            "name": "Win32",
            "includePath": [
                "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include",
                "${workspaceRoot}"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE"
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "path": [
                    "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*",
                    "${workspaceRoot}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ],
    "version": 2
}

I'm developing in Ubuntu 16.04. 我正在开发Ubuntu 16.04。 The problem that I'm facing is that when I type in my .cpp files intellisense for headers are not working. 我面临的问题是当我输入我的.cpp文件时,intellisense的标头不起作用。

MyFooClass.h
#pragma once

#include <cstddef>
#include <fstream>
#include <string>

class MyFooClass
{
private:
    //My private fields

public:
    MyFooClass();
    virtual ~MyFooClass();
    bool MyFooFunction();
};

When I implement MyFooClass.cpp using 当我使用时实现MyFooClass.cpp

#include "MyFooClass.h"

Intellisense is not working for functions and data in .h It seems to me that this should be enabled in by default in my configuration but I dont know if I must add something new. Intellisense不适用于.h中的函数和数据。在我看来,默认情况下应该在我的配置中启用它,但我不知道是否必须添加新内容。 Thank you very much. 非常感谢你。

In case you are still interested or anyone stumbles across this thread using Google: 如果您仍然感兴趣或有任何人使用Google在此主题中遇到错误:

VSC has to two different engines for auto-completion. VSC有两个不同的引擎用于自动完成。 1. The legacy "Tag Parser" 2. The IntelliSense engine 1.遗留的“Tag Parser”2. IntelliSense引擎

The latter is the default one at this point, "Tag Parser" is a fallback solution. 后者是此时的默认值,“Tag Parser”是一种后备解决方案。 As you assumed, both are configured in c_cpp_properties.json . 如您c_cpp_properties.json ,两者都在c_cpp_properties.json中配置。 The paths in browse are searched recursively and used by Tag Parser only, whereas the paths in includePath are NOT searched recursively and used by the IntelliSense engine. browse中的路径是递归搜索的,仅由Tag Parser使用,而includePath中的路径不会被递归搜索并由IntelliSense引擎使用。

Given that your header MyFooClass.h is not located directly at the root folder but in a subfolder include , you would have to add "${workspaceRoot}/include" to your includePath in order to have a working IntelliSense code completion. 鉴于你的头MyFooClass.h没有在根文件夹,但在子文件夹直接位于include ,你就必须添加"${workspaceRoot}/include"includePath为了有一个工作的IntelliSense代码完成。

Nowadays they have a better documentation on this: https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/c_cpp_properties.json.md 现在他们有更好的文档: https//github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/c_cpp_properties.json.md

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

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