summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clangd/CodeCompleteTests.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/CodeCompleteTests.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/CodeCompleteTests.cpp')
-rw-r--r--clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
index f60ed1c8426..4118fea325c 100644
--- a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
+++ b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
@@ -20,6 +20,7 @@
#include "TestTU.h"
#include "index/MemIndex.h"
#include "clang/Sema/CodeCompleteConsumer.h"
+#include "clang/Tooling/CompilationDatabase.h"
#include "llvm/Support/Error.h"
#include "llvm/Testing/Support/Error.h"
#include "gmock/gmock.h"
@@ -138,6 +139,25 @@ CodeCompleteResult completions(llvm::StringRef Text,
FilePath);
}
+// Builds a server and runs code completion.
+// If IndexSymbols is non-empty, an index will be built and passed to opts.
+CodeCompleteResult completionsNoCompile(llvm::StringRef Text,
+ std::vector<Symbol> IndexSymbols = {},
+ clangd::CodeCompleteOptions Opts = {},
+ PathRef FilePath = "foo.cpp") {
+ std::unique_ptr<SymbolIndex> OverrideIndex;
+ if (!IndexSymbols.empty()) {
+ assert(!Opts.Index && "both Index and IndexSymbols given!");
+ OverrideIndex = memIndex(std::move(IndexSymbols));
+ Opts.Index = OverrideIndex.get();
+ }
+
+ MockFSProvider FS;
+ Annotations Test(Text);
+ return codeComplete(FilePath, tooling::CompileCommand(), /*Preamble=*/nullptr,
+ Test.code(), Test.point(), FS.getFileSystem(), Opts);
+}
+
Symbol withReferences(int N, Symbol S) {
S.References = N;
return S;
@@ -2401,6 +2421,33 @@ TEST(CompletionTest, NamespaceDoubleInsertion) {
UnorderedElementsAre(AllOf(Qualifier(""), Named("ABCDE"))));
}
+TEST(NoCompileCompletionTest, Basic) {
+ auto Results = completionsNoCompile(R"cpp(
+ void func() {
+ int xyz;
+ int abc;
+ ^
+ }
+ )cpp");
+ EXPECT_THAT(Results.Completions,
+ UnorderedElementsAre(Named("void"), Named("func"), Named("int"),
+ Named("xyz"), Named("abc")));
+}
+
+TEST(NoCompileCompletionTest, WithFilter) {
+ auto Results = completionsNoCompile(R"cpp(
+ void func() {
+ int sym1;
+ int sym2;
+ int xyz1;
+ int xyz2;
+ sy^
+ }
+ )cpp");
+ EXPECT_THAT(Results.Completions,
+ UnorderedElementsAre(Named("sym1"), Named("sym2")));
+}
+
} // namespace
} // namespace clangd
} // namespace clang
OpenPOWER on IntegriCloud