summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2018-02-13 08:59:23 +0000
committerSam McCall <sam.mccall@gmail.com>2018-02-13 08:59:23 +0000
commit0bb24cd4fabb15c4d17adb26db08bc1ef9de9920 (patch)
treec31af4822cc9e55b1a92ea3ac5baf1decbddc5b1 /clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
parentf684c9c83c62b4b7552911f41eddb38552ec62d5 (diff)
downloadbcm5719-llvm-0bb24cd4fabb15c4d17adb26db08bc1ef9de9920.tar.gz
bcm5719-llvm-0bb24cd4fabb15c4d17adb26db08bc1ef9de9920.zip
[clangd] Stop exposing Futures from ClangdServer operations.
Summary: LSP has asynchronous semantics, being able to block on an async operation completing is unneccesary and leads to tighter coupling with the threading. In practice only tests depend on this, so we add a general-purpose "block until idle" function to the scheduler which will work for all operations. To get this working, fix a latent condition-variable bug in ASTWorker, and make AsyncTaskRunner const-correct. Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D43127 llvm-svn: 324990
Diffstat (limited to 'clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp')
-rw-r--r--clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
index 9f456ee75a6..b563761d119 100644
--- a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
+++ b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
@@ -121,7 +121,8 @@ CompletionList completions(StringRef Text,
/*StorePreamblesInMemory=*/true);
auto File = getVirtualTestFilePath("foo.cpp");
Annotations Test(Text);
- Server.addDocument(File, Test.code()).wait();
+ Server.addDocument(File, Test.code());
+ EXPECT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for preamble";
auto CompletionList = runCodeComplete(Server, File, Test.point(), Opts).Value;
// Sanity-check that filterText is valid.
EXPECT_THAT(CompletionList.items, Each(NameContainsFilter()));
@@ -551,13 +552,10 @@ TEST(CompletionTest, IndexSuppressesPreambleCompletions) {
void f() { ns::^; }
void f() { ns::preamble().$2^; }
)cpp");
- Server.addDocument(File, Test.code()).wait();
+ Server.addDocument(File, Test.code());
+ ASSERT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for preamble";
clangd::CodeCompleteOptions Opts = {};
- auto WithoutIndex = runCodeComplete(Server, File, Test.point(), Opts).Value;
- EXPECT_THAT(WithoutIndex.items,
- UnorderedElementsAre(Named("local"), Named("preamble")));
-
auto I = memIndex({var("ns::index")});
Opts.Index = I.get();
auto WithIndex = runCodeComplete(Server, File, Test.point(), Opts).Value;
@@ -566,6 +564,12 @@ TEST(CompletionTest, IndexSuppressesPreambleCompletions) {
auto ClassFromPreamble =
runCodeComplete(Server, File, Test.point("2"), Opts).Value;
EXPECT_THAT(ClassFromPreamble.items, Contains(Named("member")));
+
+ Opts.Index = nullptr;
+ auto WithoutIndex = runCodeComplete(Server, File, Test.point(), Opts).Value;
+ EXPECT_THAT(WithoutIndex.items,
+ UnorderedElementsAre(Named("local"), Named("preamble")));
+
}
TEST(CompletionTest, DynamicIndexMultiFile) {
@@ -576,11 +580,10 @@ TEST(CompletionTest, DynamicIndexMultiFile) {
/*StorePreamblesInMemory=*/true,
/*BuildDynamicSymbolIndex=*/true);
- Server
- .addDocument(getVirtualTestFilePath("foo.cpp"), R"cpp(
+ Server.addDocument(getVirtualTestFilePath("foo.cpp"), R"cpp(
namespace ns { class XYZ {}; void foo(int x) {} }
- )cpp")
- .wait();
+ )cpp");
+ ASSERT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for preamble";
auto File = getVirtualTestFilePath("bar.cpp");
Annotations Test(R"cpp(
@@ -591,7 +594,8 @@ TEST(CompletionTest, DynamicIndexMultiFile) {
}
void f() { ns::^ }
)cpp");
- Server.addDocument(File, Test.code()).wait();
+ Server.addDocument(File, Test.code());
+ ASSERT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for preamble";
auto Results = runCodeComplete(Server, File, Test.point(), {}).Value;
// "XYZ" and "foo" are not included in the file being completed but are still
@@ -621,6 +625,7 @@ SignatureHelp signatures(StringRef Text) {
auto File = getVirtualTestFilePath("foo.cpp");
Annotations Test(Text);
Server.addDocument(File, Test.code());
+ EXPECT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for preamble";
auto R = Server.signatureHelp(File, Test.point());
assert(R);
return R.get().Value;
OpenPOWER on IntegriCloud