Index: clangd/ClangdServer.h =================================================================== --- clangd/ClangdServer.h +++ clangd/ClangdServer.h @@ -187,13 +187,6 @@ llvm::Optional OverridenContents = llvm::None, IntrusiveRefCntPtr *UsedFS = nullptr); - /// DEPRECATED: Please use the callback-based version of codeComplete. - std::future> - codeComplete(PathRef File, Position Pos, - const clangd::CodeCompleteOptions &Opts, - llvm::Optional OverridenContents = llvm::None, - IntrusiveRefCntPtr *UsedFS = nullptr); - /// Provide signature help for \p File at \p Pos. If \p OverridenContents is /// not None, they will used only for signature help, i.e. no diagnostics /// update will be scheduled and a draft for \p File will not be updated. If Index: clangd/ClangdServer.cpp =================================================================== --- clangd/ClangdServer.cpp +++ clangd/ClangdServer.cpp @@ -166,24 +166,6 @@ std::move(TaggedFS)); } -std::future> -ClangdServer::codeComplete(PathRef File, Position Pos, - const clangd::CodeCompleteOptions &Opts, - llvm::Optional OverridenContents, - IntrusiveRefCntPtr *UsedFS) { - std::promise> ResultPromise; - auto Callback = [](std::promise> ResultPromise, - Tagged Result) -> void { - ResultPromise.set_value(std::move(Result)); - }; - - auto ResultFuture = ResultPromise.get_future(); - codeComplete(File, Pos, Opts, - BindWithForward(Callback, std::move(ResultPromise)), - OverridenContents, UsedFS); - return ResultFuture; -} - void ClangdServer::codeComplete( PathRef File, Position Pos, const clangd::CodeCompleteOptions &Opts, UniqueFunction)> Callback, Index: unittests/clangd/ClangdTests.cpp =================================================================== --- unittests/clangd/ClangdTests.cpp +++ unittests/clangd/ClangdTests.cpp @@ -9,6 +9,7 @@ #include "ClangdLSPServer.h" #include "ClangdServer.h" +#include "SyncAPI.h" #include "TestFS.h" #include "clang/Config/config.h" #include "llvm/ADT/SmallVector.h" @@ -301,14 +302,14 @@ // thread. FS.Tag = "123"; Server.addDocument(FooCpp, SourceContents); - EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}, CCOpts).get().Tag, + EXPECT_EQ(runCodeComplete(Server, FooCpp, Position{0, 0}, CCOpts).Tag, FS.Tag); EXPECT_EQ(DiagConsumer.lastVFSTag(), FS.Tag); FS.Tag = "321"; Server.addDocument(FooCpp, SourceContents); EXPECT_EQ(DiagConsumer.lastVFSTag(), FS.Tag); - EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}, CCOpts).get().Tag, + EXPECT_EQ(runCodeComplete(Server, FooCpp, Position{0, 0}, CCOpts).Tag, FS.Tag); } @@ -637,10 +638,8 @@ // requests as opposed to AddDocument/RemoveDocument, which are implicitly // cancelled by any subsequent AddDocument/RemoveDocument request to the // same file. - Server - .codeComplete(FilePaths[FileIndex], Pos, - clangd::CodeCompleteOptions()) - .wait(); + runCodeComplete(Server, FilePaths[FileIndex], Pos, + clangd::CodeCompleteOptions()); }; auto FindDefinitionsRequest = [&]() { Index: unittests/clangd/CodeCompleteTests.cpp =================================================================== --- unittests/clangd/CodeCompleteTests.cpp +++ unittests/clangd/CodeCompleteTests.cpp @@ -14,6 +14,7 @@ #include "Matchers.h" #include "Protocol.h" #include "SourceCode.h" +#include "SyncAPI.h" #include "TestFS.h" #include "index/MemIndex.h" #include "gmock/gmock.h" @@ -121,8 +122,7 @@ auto File = getVirtualTestFilePath("foo.cpp"); Annotations Test(Text); Server.addDocument(File, Test.code()).wait(); - auto CompletionList = - Server.codeComplete(File, Test.point(), Opts).get().Value; + auto CompletionList = runCodeComplete(Server, File, Test.point(), Opts).Value; // Sanity-check that filterText is valid. EXPECT_THAT(CompletionList.items, Each(NameContainsFilter())); return CompletionList; @@ -348,10 +348,8 @@ Annotations Example("int cbc; int b = ^;"); auto Results = - Server - .codeComplete(File, Example.point(), clangd::CodeCompleteOptions(), - StringRef(Example.code())) - .get() + runCodeComplete(Server, File, Example.point(), + clangd::CodeCompleteOptions(), StringRef(Example.code())) .Value; EXPECT_THAT(Results.items, Contains(Named("cbc"))); } @@ -556,17 +554,17 @@ Server.addDocument(File, Test.code()).wait(); clangd::CodeCompleteOptions Opts = {}; - auto WithoutIndex = Server.codeComplete(File, Test.point(), Opts).get().Value; + 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 = Server.codeComplete(File, Test.point(), Opts).get().Value; + auto WithIndex = runCodeComplete(Server, File, Test.point(), Opts).Value; EXPECT_THAT(WithIndex.items, UnorderedElementsAre(Named("local"), Named("index"))); auto ClassFromPreamble = - Server.codeComplete(File, Test.point("2"), Opts).get().Value; + runCodeComplete(Server, File, Test.point("2"), Opts).Value; EXPECT_THAT(ClassFromPreamble.items, Contains(Named("member"))); } @@ -595,7 +593,7 @@ )cpp"); Server.addDocument(File, Test.code()).wait(); - auto Results = Server.codeComplete(File, Test.point(), {}).get().Value; + auto Results = runCodeComplete(Server, File, Test.point(), {}).Value; // "XYZ" and "foo" are not included in the file being completed but are still // visible through the index. EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class)); Index: unittests/clangd/SyncAPI.h =================================================================== --- /dev/null +++ unittests/clangd/SyncAPI.h @@ -0,0 +1,34 @@ +//===--- SyncAPI.h - Sync version of ClangdServer's API ----------*- C++-*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===---------------------------------------------------------------------===// +#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H +#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H + +#include "ClangdServer.h" +#include + +namespace clang { +namespace clangd { +inline Tagged +runCodeComplete(ClangdServer &Server, PathRef File, Position Pos, + clangd::CodeCompleteOptions Opts, + llvm::Optional OverridenContents = llvm::None) { + std::promise> Promise; + auto Future = Promise.get_future(); + auto SetResult = [](decltype(Promise) Promise, Tagged Value) { + Promise.set_value(std::move(Value)); + }; + Server.codeComplete(File, Pos, Opts, + BindWithForward(SetResult, std::move(Promise)), + OverridenContents); + return Future.get(); +} +} // namespace clangd +} // namespace clang + +#endif