VSCode intellisense与C ++标头

时间:2017-08-10 11:28:09

标签: c++ visual-studio-code intellisense

我搜索了这个,但我找不到任何东西。如果它是愚蠢的,我将毫无问题地结束我的问题。我在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
}

我正在开发Ubuntu 16.04。我面临的问题是,当我输入我的.cpp文件时,intellisense的标头不起作用。

MyFooClass.h
#pragma once

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

class MyFooClass
{
private:
    //My private fields

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

当我使用

实现MyFooClass.cpp时
#include "MyFooClass.h"

Intellisense不适用于.h中的函数和数据在我看来,默认情况下应该在我的配置中启用它,但我不知道是否必须添加新内容。非常感谢你。

1 个答案:

答案 0 :(得分:1)

如果您仍然感兴趣,或者有人使用Google在此主题中遇到障碍:

VSC必须使用两个不同的引擎进行自动完成。 1.遗产&#34; Tag Parser&#34; 2. IntelliSense引擎

后者是此时的默认值,&#34; Tag Parser&#34;是一个后备解决方案。如您所愿,两者都在c_cpp_properties.json中配置。 browse中的路径以递归方式搜索并仅由Tag Parser使用,而includePath中的路径不会被递归搜索并由IntelliSense引擎使用。

鉴于您的标题MyFooClass.h不是直接位于根文件夹而是位于子文件夹include中,您必须将"${workspaceRoot}/include"添加到includePath才能有一个有效的智能感知代码完成。

现在他们有更好的文档: https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/c_cpp_properties.json.md