[PATCH] D63481: [clangd] Parse files without extensions if we don't have a compile command.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 18 02:59:45 PDT 2019


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

This would enable clangd for C++ standard library files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63481

Files:
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp


Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -36,6 +36,10 @@
   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) {
Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===================================================================
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -58,9 +58,11 @@
 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),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63481.205290.patch
Type: text/x-patch
Size: 1754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190618/30144158/attachment.bin>


More information about the cfe-commits mailing list