Author: hokein
Date: Tue Jun 18 04:54:17 2019
New Revision: 363663

URL: http://llvm.org/viewvc/llvm-project?rev=363663&view=rev
Log:
[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

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

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp?rev=363663&r1=363662&r2=363663&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp Tue Jun 18 
04:54:17 2019
@@ -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),

Modified: 
clang-tools-extra/trunk/clangd/unittests/GlobalCompilationDatabaseTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/GlobalCompilationDatabaseTests.cpp?rev=363663&r1=363662&r2=363663&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/GlobalCompilationDatabaseTests.cpp 
(original)
+++ clang-tools-extra/trunk/clangd/unittests/GlobalCompilationDatabaseTests.cpp 
Tue Jun 18 04:54:17 2019
@@ -36,6 +36,10 @@ TEST(GlobalCompilationDatabaseTest, Fall
   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) {


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to