本文介绍了带有C ++头的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
}

我正在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中的功能和数据,在我看来,默认情况下应在我的配置中启用此功能,但我不知道是否必须添加一些新内容.非常感谢.

解决方案

如果您仍然感兴趣,或者有人使用Google偶然发现了这个话题:

VSC必须使用两个不同的引擎来自动完成.1.旧版标签解析器"2. IntelliSense引擎

后者是目前的默认设置,"Tag Parser"是一种后备解决方案.如您所料,两者均在c_cpp_properties.json中进行配置. browse中的路径是递归搜索的,并且仅由Tag Parser使用,而includePath中的路径不是递归搜索的,而是由IntelliSense引擎使用.

鉴于标题MyFooClass.h不是直接位于根文件夹中,而是位于子文件夹include中,则您必须在includePath中添加"${workspaceRoot}/include"才能使IntelliSense代码正常工作. /p>

如今,他们在以下方面有更好的文档: https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/c_cpp_properties.json.md

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

{
    "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. The problem that I'm facing is that when I type in my .cpp files intellisense for headers are not working.

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

#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. Thank you very much.

解决方案

In case you are still interested or anyone stumbles across this thread using Google:

VSC has to two different engines for auto-completion.1. The legacy "Tag Parser"2. The IntelliSense engine

The latter is the default one at this point, "Tag Parser" is a fallback solution. As you assumed, both are configured in 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.

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.

Nowadays they have a better documentation on this:https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/c_cpp_properties.json.md

这篇关于带有C ++头的VSCode智能感知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 17:23