[cfe-dev] clangd, completion in header files

Jan Včelák via cfe-dev cfe-dev at lists.llvm.org
Sun Mar 25 15:21:26 PDT 2018


Hello list,

thank you for all the work on clangd. I tried it for the first time
with VSCode and I'm really impressed how useful it is just out of the
box.

I however encountered a problem with code completion in header files
and I would like to know if it's a bug in clangd or a problem in my
setup. I work on a C++ project which has headers with .h extension and
clangd incorrectly assumes it's a C code because it emits (besides
other things) "unknown type name 'namespace'" diagnostics message for
the namespace definition.

I run clangd -input-mirror-file for a while and I can see
textDocument/didOpen calls for the .h headers with "languageId" set to
"cpp". If I rename a header to .hpp, the problem disappears. I also
tried configuring custom file extension association for C++ in VSCode
and it worked as well. So I believe there must be something wrong just
with .h (i.e. clangd seems not to respect languageId for .h files).

Please, can you guide me how to diagnose the problem better so I can
eventually fill a bug report?

I also wonder how the completion is supposed to work in headers in
general. Is there some heuristics to guess the compilation flags
because the headers are not in the compilation database (at least when
generated by cmake)?

Regards,

Jan



More information about the cfe-dev mailing list