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),
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),
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits