This revision was automatically updated to reflect the committed changes. Closed by commit rL363663: [clangd] Parse files without extensions if we don't have a compile command. (authored by hokein, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D63481?vs=205290&id=205307#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D63481/new/ https://reviews.llvm.org/D63481 Files: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp clang-tools-extra/trunk/clangd/unittests/GlobalCompilationDatabaseTests.cpp Index: clang-tools-extra/trunk/clangd/unittests/GlobalCompilationDatabaseTests.cpp =================================================================== --- clang-tools-extra/trunk/clangd/unittests/GlobalCompilationDatabaseTests.cpp +++ clang-tools-extra/trunk/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/trunk/clangd/GlobalCompilationDatabase.cpp =================================================================== --- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp +++ clang-tools-extra/trunk/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/trunk/clangd/unittests/GlobalCompilationDatabaseTests.cpp =================================================================== --- clang-tools-extra/trunk/clangd/unittests/GlobalCompilationDatabaseTests.cpp +++ clang-tools-extra/trunk/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/trunk/clangd/GlobalCompilationDatabase.cpp =================================================================== --- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp +++ clang-tools-extra/trunk/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 cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits