clang格式的主要内容包括使用文件夹前缀进行排序

clang格式的主要内容包括使用文件夹前缀进行排序

本文介绍了clang格式的主要内容包括使用文件夹前缀进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下设置中,我试图获取clang格式以识别 foo.cpp 的主要包含内容:

I am trying to get clang-format to recognize the main include for foo.cpp in the following setup:

project/my_lib
├── CMakeLists.txt
├── include
│   └── project
│       └── my_lib
│           └── foo.hpp
├── src
│   └── foo.cpp
└── tests
    └── foo_test.cpp

并且 foo.cpp 具有以下内容:

#include <project/another_lib/bar.hpp>
#include <project/my_lib/foo.hpp>
#include <vector>

// ...

我认为我已经确定的问题如下:clang尝试根据文件名(在本例中为 foo.cpp )识别"main"包含.而且,当它查看 #include< project/my_lib/foo.hpp> 时,不会将其识别为该cpp文件的主要"包含内容.我知道可以为主要包含文件"指定后缀.逻辑,但是这里需要的是前缀正则表达式.

The problem I think I have identified is the following: clang tries to identify the 'main' include based on the file name, in this case foo.cpp. And when it looks at #include <project/my_lib/foo.hpp> it doesn't recognize this as the 'main' include for this cpp file. I know it is possible to specify suffixes for the "main include file" logic, but what would be needed here is a prefix regex.

在上面的示例中,关于如何让clang设置正确的include到优先级0的任何帮助吗?

Any help as to how I could get clang to set the right include to priority 0 in the example above?

参考: Clang格式选项,"IncludeCategories"部分然后

编辑:我使用Visual Studio 2019中集成的 clang-format ,这意味着我无法访问命令行选项.此外,这是一个共享项目,我想解决默认行为.

I am using clang-format as integrated in Visual Studio 2019, which means I do not think I have access to the command line options. Moreover, this being a shared project, I'd like to work off of the default behavior.

推荐答案

作为一种快速更新,哪种解决了我的问题:如果include使用常规引号(" ),则按clang-与Visual Studio捆绑在一起的格式似乎采用了主要"格式,标头并对其进行相应排序.

Just as a quick update, which kind of solved my issue: if the include uses regular quotes (") then clang-format bundled with Visual Studio seems to pick up the "main" header and order it accordingly.

不理想,但仍然是可行的解决方案.

Not ideal, but still a working solution.

这篇关于clang格式的主要内容包括使用文件夹前缀进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 19:00