<div dir="ltr"><div class="gmail_quote"><div>Thanks for trying things out, and sorry for the bad header-file experience.</div><div dir="ltr"><br></div><div dir="ltr">On Mon, Mar 26, 2018 at 4:05 AM Jan Včelák via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello list,<br>
<br>
thank you for all the work on clangd. I tried it for the first time<br>
with VSCode and I'm really impressed how useful it is just out of the<br>
box.<br>
<br>
I however encountered a problem with code completion in header files<br>
and I would like to know if it's a bug in clangd or a problem in my<br>
setup.</blockquote><div>Yeah, this is a known missing feature - guessing the right compile flags for headers.</div><div>If you have a compilation database (e.g. compile_commands.json) that provides compile commands for headers, then clangd works as expected. However most build systems don't provide this information. (Bazel, for one, does).</div><div><br></div><div>When there's no compile command provided, we fall back to 'clang $filename'. Clang treats .h files as C.</div><div>But it's also missing a bunch of other information: include paths, defines etc that are likely required to get useful results.</div><div>So I don't think just diverging from clang here will actually help many projects (feel free to try this out by editing compile_commands.json - if this works for you it'd be good to know).</div><div><br></div><div>What can we do then? A few ideas:</div><div> - we can preprocess all the files from compile_commands.json on startup (<a href="https://reviews.llvm.org/D41911">https://reviews.llvm.org/D41911</a> is the start of this). But we can't guarantee we get to the file you care about in time, so behavior will be erratic.</div><div> - we can pick a compile command arbitrarily and take its flags, which will get include paths and defines right if they're uniform across the project</div><div> - we can just refuse to provide any diagnostics/completions where we don't have a known-good set of flags.</div><div><br></div><div>I've dumped these thoughts into <a href="https://bugs.llvm.org/show_bug.cgi?id=36899">https://bugs.llvm.org/show_bug.cgi?id=36899</a> - I also want to solicit some thoughts on this problem at the BoF session at the next LLVM dev meeting.<br></div><div>I'd like to find time to work on this in the next quarter, but I'm not certain - if anyone is interested in attacking this problem, let me know!</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> I work on a C++ project which has headers with .h extension and<br>
clangd incorrectly assumes it's a C code because it emits (besides<br>
other things) "unknown type name 'namespace'" diagnostics message for<br>
the namespace definition.<br>
<br>
I run clangd -input-mirror-file for a while and I can see<br>
textDocument/didOpen calls for the .h headers with "languageId" set to<br>
"cpp". If I rename a header to .hpp, the problem disappears. I also<br>
tried configuring custom file extension association for C++ in VSCode<br>
and it worked as well. So I believe there must be something wrong just<br>
with .h (i.e. clangd seems not to respect languageId for .h files).<br>
<br>
Please, can you guide me how to diagnose the problem better so I can<br>
eventually fill a bug report?<br></blockquote><div>I think you've diagnosed it pretty well, but you can get a bit of extra information from the logs clangd writes to stderr. In VSCode, these are visible in the "output" pane, under "clang language server". This will include the command used to build each file.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I also wonder how the completion is supposed to work in headers in<br>
general. Is there some heuristics to guess the compilation flags<br>
because the headers are not in the compilation database (at least when<br>
generated by cmake)?<br>
<br>
Regards,<br>
<br>
Jan<br></blockquote><div><br></div><div>Cheers, Sam </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>