This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Add isHeaderFile helper.
ClosedPublic

Authored by hokein on Nov 14 2019, 4:59 AM.

Details

Summary

we have a few places using ASTCtx.getLangOpts().IsHeaderFile to
determine a header file, but it relies on "-x c-header" compiler flag,
if the compilation command doesn't have this flag, we will get a false
positive. We are encountering this issue in bazel build system.

To solve this problem, we infer the file from file name, actual changes will
come in follow-ups.

Diff Detail

Event Timeline

hokein created this revision.Nov 14 2019, 4:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 14 2019, 4:59 AM

Build result: pass - 60058 tests passed, 0 failed and 729 were skipped.
Log files: console-log.txt, CMakeCache.txt

As discussed offline, we still want to respect the langopts signal, but we also want to treat *.h as a header if it's not present. So the function needs to take filename and langopts.

hokein updated this revision to Diff 229300.Nov 14 2019, 6:30 AM

take langOpts into account.

Build result: pass - 60058 tests passed, 0 failed and 729 were skipped.
Log files: console-log.txt, CMakeCache.txt

in case you miss this patch, I saw you have stamped the other patch depends on this patch, but this patch still needs approval.

sammccall accepted this revision.Nov 15 2019, 6:18 AM
sammccall added inline comments.
clang-tools-extra/clangd/SourceCode.cpp
1133

This structure seems confusing.

Why not at the top:

if (LangOpts && LangOpts->IsHeaderFile)
  return true;

and then do the extension check and return the result?

This revision is now accepted and ready to land.Nov 15 2019, 6:18 AM
sammccall added inline comments.Nov 15 2019, 6:19 AM
clang-tools-extra/clangd/SourceCode.h
302

nit: = llvm::None

hokein updated this revision to Diff 229545.Nov 15 2019, 7:17 AM
hokein marked an inline comment as done.

Address comments.

This revision was automatically updated to reflect the committed changes.

Build result: pass - 60093 tests passed, 0 failed and 729 were skipped.
Log files: console-log.txt, CMakeCache.txt