简体   繁体   English

Clangd:将具有非标准扩展名的文件视为标头

[英]Clangd: treat files with non-standard extensions as headers

I am working with an old C code base where there are header files with non-standard extensions such as .s , .e , etc instead of .h我正在使用旧的 C 代码库,其中有 header 文件具有非标准扩展名,例如.s.e等而不是.h

For compatibility reasons I cannot rename these files.出于兼容性原因,我无法重命名这些文件。

Currently these files are causing the following error message in clangd:目前这些文件在 clangd 中导致以下错误消息:

Unable to handle compilation, expected exactly one compiler job in ''clang(fe_expected_compiler_job)无法处理编译,预计在 ''clang(fe_expected_compiler_job) 中只有一个编译器作业

Which I interpret as meaning "0 compiler job found" ie clangd treats these files as .c source files.我将其解释为“找到 0 个编译器作业”,即 clangd 将这些文件视为.c源文件。

How can I get clangd to treat them as header files?我怎样才能让 clangd 将它们视为 header 文件?

I found that compile_commands.json can be used to instruct clangd to treat a file with an arbitrary name as a header, using the option to generate a precompiled header file (PCH file) :我发现compile_commands.json可用于指示 clangd 将任意名称的文件视为 header,使用选项生成预编译的 header 文件(PCH 文件)

[
    {
        "directory": "path/to/directory",
        "file": "path/to/file.e",
        "arguments": ["clang", "-x", "c-header", "path/to/file.e"]
    }
]

For a C++ header you would have to use c++-header instead of c-header .对于 C++ header 你必须使用c++-header而不是c-header

I tested this on clangd 13.0.0.我在 clangd 13.0.0 上测试了这个。

I got help from this answer .我从这个答案中得到了帮助。

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

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