diff options
author | Haojian Wu <hokein@google.com> | 2019-06-18 11:54:17 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2019-06-18 11:54:17 +0000 |
commit | 8ddf31bc33e6c29dca82d640c0c9bab7a67080fa (patch) | |
tree | a815b52fd1c5f5e657991fcb4e29fa86e5474c64 | |
parent | 40fdd7a643b5d02e4bd63ce280a5fe53aa03fdef (diff) | |
download | bcm5719-llvm-8ddf31bc33e6c29dca82d640c0c9bab7a67080fa.tar.gz bcm5719-llvm-8ddf31bc33e6c29dca82d640c0c9bab7a67080fa.zip |
[clangd] Parse files without extensions if we don't have a compile command.
Summary: This would enable clangd for C++ standard library files.
Reviewers: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D63481
llvm-svn: 363663
-rw-r--r-- | clang-tools-extra/clangd/GlobalCompilationDatabase.cpp | 6 | ||||
-rw-r--r-- | clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp | 4 |
2 files changed, 8 insertions, 2 deletions
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp index b40ae26cd3e..9a09482ce39 100644 --- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp +++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp @@ -58,9 +58,11 @@ static std::string getFallbackClangPath() { tooling::CompileCommand GlobalCompilationDatabase::getFallbackCommand(PathRef File) const { std::vector<std::string> Argv = {getFallbackClangPath()}; - // Clang treats .h files as C by default, resulting in unhelpful diagnostics. + // Clang treats .h files as C by default and files without extension as linker + // input, resulting in unhelpful diagnostics. // Parsing as Objective C++ is friendly to more cases. - if (llvm::sys::path::extension(File) == ".h") + auto FileExtension = llvm::sys::path::extension(File); + if (FileExtension.empty() || FileExtension == ".h") Argv.push_back("-xobjective-c++-header"); Argv.push_back(File); tooling::CompileCommand Cmd(llvm::sys::path::parent_path(File), diff --git a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp index 6761deb70ac..6823fc557ee 100644 --- a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp +++ b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp @@ -36,6 +36,10 @@ TEST(GlobalCompilationDatabaseTest, FallbackCommand) { EXPECT_THAT(Cmd.CommandLine, ElementsAre(EndsWith("clang"), "-xobjective-c++-header", testPath("foo/bar.h"))); + Cmd = DB.getFallbackCommand(testPath("foo/bar")); + EXPECT_THAT(Cmd.CommandLine, + ElementsAre(EndsWith("clang"), "-xobjective-c++-header", + testPath("foo/bar"))); } static tooling::CompileCommand cmd(llvm::StringRef File, llvm::StringRef Arg) { |