summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clangd/HeadersTests.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2019-04-11 09:36:36 +0000
committerEric Liu <ioeric@google.com>2019-04-11 09:36:36 +0000
commit00d99bd1c4ad80dc909c74c39681978f843a44c6 (patch)
treef2bf9490f522f1fccb11a4e65e75a2d6c8db7d1a /clang-tools-extra/unittests/clangd/HeadersTests.cpp
parent6ef53b3bf2fcccfc97e9a47d17c44cbe1f2b4481 (diff)
downloadbcm5719-llvm-00d99bd1c4ad80dc909c74c39681978f843a44c6.tar.gz
bcm5719-llvm-00d99bd1c4ad80dc909c74c39681978f843a44c6.zip
[clangd] Use identifiers in file as completion candidates when build is not ready.
Summary: o Lex the code to get the identifiers and put them into a "symbol" index. o Adds a new completion mode without compilation/sema into code completion workflow. o Make IncludeInserter work even when no compile command is present, by avoiding inserting non-verbatim headers. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60126 llvm-svn: 358159
Diffstat (limited to 'clang-tools-extra/unittests/clangd/HeadersTests.cpp')
-rw-r--r--clang-tools-extra/unittests/clangd/HeadersTests.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/clang-tools-extra/unittests/clangd/HeadersTests.cpp b/clang-tools-extra/unittests/clangd/HeadersTests.cpp
index ab1311e2e60..2c96d40a9d4 100644
--- a/clang-tools-extra/unittests/clangd/HeadersTests.cpp
+++ b/clang-tools-extra/unittests/clangd/HeadersTests.cpp
@@ -90,7 +90,7 @@ protected:
IncludeInserter Inserter(MainFile, /*Code=*/"", format::getLLVMStyle(),
CDB.getCompileCommand(MainFile)->Directory,
- Clang->getPreprocessor().getHeaderSearchInfo());
+ &Clang->getPreprocessor().getHeaderSearchInfo());
for (const auto &Inc : Inclusions)
Inserter.addExisting(Inc);
auto Declaring = ToHeaderFile(Original);
@@ -110,7 +110,7 @@ protected:
IncludeInserter Inserter(MainFile, /*Code=*/"", format::getLLVMStyle(),
CDB.getCompileCommand(MainFile)->Directory,
- Clang->getPreprocessor().getHeaderSearchInfo());
+ &Clang->getPreprocessor().getHeaderSearchInfo());
auto Edit = Inserter.insert(VerbatimHeader);
Action.EndSourceFile();
return Edit;
@@ -252,6 +252,24 @@ TEST_F(HeadersTest, PreferInserted) {
EXPECT_TRUE(StringRef(Edit->newText).contains("<y>"));
}
+TEST(Headers, NoHeaderSearchInfo) {
+ std::string MainFile = testPath("main.cpp");
+ IncludeInserter Inserter(MainFile, /*Code=*/"", format::getLLVMStyle(),
+ /*BuildDir=*/"", /*HeaderSearchInfo=*/nullptr);
+
+ auto HeaderPath = testPath("sub/bar.h");
+ auto Declaring = HeaderFile{HeaderPath, /*Verbatim=*/false};
+ auto Inserting = HeaderFile{HeaderPath, /*Verbatim=*/false};
+ auto Verbatim = HeaderFile{"<x>", /*Verbatim=*/true};
+
+ EXPECT_EQ(Inserter.calculateIncludePath(Declaring, Inserting),
+ "\"" + HeaderPath + "\"");
+ EXPECT_EQ(Inserter.shouldInsertInclude(Declaring, Inserting), false);
+
+ EXPECT_EQ(Inserter.calculateIncludePath(Declaring, Verbatim), "<x>");
+ EXPECT_EQ(Inserter.shouldInsertInclude(Declaring, Verbatim), true);
+}
+
} // namespace
} // namespace clangd
} // namespace clang
OpenPOWER on IntegriCloud