[clangd] Remove codecomplete override content API. Long live addDocument!
llvm-svn: 326211
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index a306ed2..abb09a8 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -141,7 +141,6 @@
void ClangdServer::codeComplete(
PathRef File, Position Pos, const clangd::CodeCompleteOptions &Opts,
UniqueFunction<void(Tagged<CompletionList>)> Callback,
- llvm::Optional<StringRef> OverridenContents,
IntrusiveRefCntPtr<vfs::FileSystem> *UsedFS) {
using CallbackType = UniqueFunction<void(Tagged<CompletionList>)>;
@@ -154,14 +153,9 @@
if (!CodeCompleteOpts.Index) // Respect overridden index.
CodeCompleteOpts.Index = Index;
- std::string Contents;
- if (OverridenContents) {
- Contents = OverridenContents->str();
- } else {
- VersionedDraft Latest = DraftMgr.getDraft(File);
- assert(Latest.Draft && "codeComplete called for non-added document");
- Contents = *Latest.Draft;
- }
+ VersionedDraft Latest = DraftMgr.getDraft(File);
+ // FIXME(sammccall): return error for consistency?
+ assert(Latest.Draft && "codeComplete called for non-added document");
// Copy PCHs to avoid accessing this->PCHs concurrently
std::shared_ptr<PCHContainerOperations> PCHs = this->PCHs;
@@ -183,34 +177,27 @@
WorkScheduler.runWithPreamble(
"CodeComplete", File,
- Bind(Task, std::move(Contents), File.str(), std::move(Callback)));
+ Bind(Task, std::move(*Latest.Draft), File.str(), std::move(Callback)));
}
void ClangdServer::signatureHelp(
PathRef File, Position Pos,
UniqueFunction<void(llvm::Expected<Tagged<SignatureHelp>>)> Callback,
- llvm::Optional<StringRef> OverridenContents,
IntrusiveRefCntPtr<vfs::FileSystem> *UsedFS) {
auto TaggedFS = FSProvider.getTaggedFileSystem(File);
if (UsedFS)
*UsedFS = TaggedFS.Value;
- std::string Contents;
- if (OverridenContents) {
- Contents = OverridenContents->str();
- } else {
- VersionedDraft Latest = DraftMgr.getDraft(File);
- if (!Latest.Draft)
- return Callback(llvm::make_error<llvm::StringError>(
- "signatureHelp is called for non-added document",
- llvm::errc::invalid_argument));
- Contents = std::move(*Latest.Draft);
- }
+ VersionedDraft Latest = DraftMgr.getDraft(File);
+ if (!Latest.Draft)
+ return Callback(llvm::make_error<llvm::StringError>(
+ "signatureHelp is called for non-added document",
+ llvm::errc::invalid_argument));
auto PCHs = this->PCHs;
- auto Action = [Contents, Pos, TaggedFS,
- PCHs](Path File, decltype(Callback) Callback,
- llvm::Expected<InputsAndPreamble> IP) {
+ auto Action = [Pos, TaggedFS, PCHs](std::string Contents, Path File,
+ decltype(Callback) Callback,
+ llvm::Expected<InputsAndPreamble> IP) {
if (!IP)
return Callback(IP.takeError());
@@ -223,8 +210,9 @@
TaggedFS.Tag));
};
- WorkScheduler.runWithPreamble("SignatureHelp", File,
- Bind(Action, File.str(), std::move(Callback)));
+ WorkScheduler.runWithPreamble(
+ "SignatureHelp", File,
+ Bind(Action, std::move(*Latest.Draft), File.str(), std::move(Callback)));
}
llvm::Expected<tooling::Replacements>
diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h
index 995e907..16009c6 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -171,10 +171,7 @@
/// Run code completion for \p File at \p Pos.
/// Request is processed asynchronously.
///
- /// If \p OverridenContents is not None, they will used only for code
- /// completion, i.e. no diagnostics update will be scheduled and a draft for
- /// \p File will not be updated. If \p OverridenContents is None, contents of
- /// the current draft for \p File will be used. If \p UsedFS is non-null, it
+ /// The current draft for \p File will be used. If \p UsedFS is non-null, it
/// will be overwritten by vfs::FileSystem used for completion.
///
/// This method should only be called for currently tracked files. However, it
@@ -185,20 +182,16 @@
void codeComplete(PathRef File, Position Pos,
const clangd::CodeCompleteOptions &Opts,
UniqueFunction<void(Tagged<CompletionList>)> Callback,
- llvm::Optional<StringRef> OverridenContents = llvm::None,
IntrusiveRefCntPtr<vfs::FileSystem> *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
- /// \p OverridenContents is None, contents of the current draft for \p File
- /// will be used. If \p UsedFS is non-null, it will be overwritten by
- /// vfs::FileSystem used for signature help. This method should only be called
- /// for currently tracked files.
+ /// If \p UsedFS is non-null, it will be overwritten by vfs::FileSystem used
+ /// for signature help. This method should only be called for tracked files.
void signatureHelp(
PathRef File, Position Pos,
UniqueFunction<void(llvm::Expected<Tagged<SignatureHelp>>)> Callback,
- llvm::Optional<StringRef> OverridenContents = llvm::None,
IntrusiveRefCntPtr<vfs::FileSystem> *UsedFS = nullptr);
/// Get definition of symbol at a specified \p Line and \p Column in \p File.
diff --git a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
index d4c9d7d..ccf2bed 100644
--- a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
+++ b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
@@ -337,24 +337,6 @@
}
}
-// Check code completion works when the file contents are overridden.
-TEST(CompletionTest, CheckContentsOverride) {
- MockFSProvider FS;
- IgnoreDiagnostics DiagConsumer;
- MockCompilationDatabase CDB;
- ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
- /*StorePreamblesInMemory=*/true);
- auto File = testPath("foo.cpp");
- Server.addDocument(File, "ignored text!");
-
- Annotations Example("int cbc; int b = ^;");
- auto Results =
- runCodeComplete(Server, File, Example.point(),
- clangd::CodeCompleteOptions(), StringRef(Example.code()))
- .Value;
- EXPECT_THAT(Results.items, Contains(Named("cbc")));
-}
-
TEST(CompletionTest, Priorities) {
auto Internal = completions(R"cpp(
class Foo {
diff --git a/clang-tools-extra/unittests/clangd/SyncAPI.cpp b/clang-tools-extra/unittests/clangd/SyncAPI.cpp
index 10f4053..75cc781 100644
--- a/clang-tools-extra/unittests/clangd/SyncAPI.cpp
+++ b/clang-tools-extra/unittests/clangd/SyncAPI.cpp
@@ -61,20 +61,18 @@
}
} // namespace
-Tagged<CompletionList>
-runCodeComplete(ClangdServer &Server, PathRef File, Position Pos,
- clangd::CodeCompleteOptions Opts,
- llvm::Optional<StringRef> OverridenContents) {
+Tagged<CompletionList> runCodeComplete(ClangdServer &Server, PathRef File,
+ Position Pos,
+ clangd::CodeCompleteOptions Opts) {
llvm::Optional<Tagged<CompletionList>> Result;
- Server.codeComplete(File, Pos, Opts, capture(Result), OverridenContents);
+ Server.codeComplete(File, Pos, Opts, capture(Result));
return std::move(*Result);
}
llvm::Expected<Tagged<SignatureHelp>>
-runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos,
- llvm::Optional<StringRef> OverridenContents) {
+runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos) {
llvm::Optional<llvm::Expected<Tagged<SignatureHelp>>> Result;
- Server.signatureHelp(File, Pos, capture(Result), OverridenContents);
+ Server.signatureHelp(File, Pos, capture(Result));
return std::move(*Result);
}
diff --git a/clang-tools-extra/unittests/clangd/SyncAPI.h b/clang-tools-extra/unittests/clangd/SyncAPI.h
index 6b8f27d..31d8483 100644
--- a/clang-tools-extra/unittests/clangd/SyncAPI.h
+++ b/clang-tools-extra/unittests/clangd/SyncAPI.h
@@ -18,14 +18,12 @@
namespace clang {
namespace clangd {
-Tagged<CompletionList>
-runCodeComplete(ClangdServer &Server, PathRef File, Position Pos,
- clangd::CodeCompleteOptions Opts,
- llvm::Optional<StringRef> OverridenContents = llvm::None);
+Tagged<CompletionList> runCodeComplete(ClangdServer &Server, PathRef File,
+ Position Pos,
+ clangd::CodeCompleteOptions Opts);
llvm::Expected<Tagged<SignatureHelp>>
-runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos,
- llvm::Optional<StringRef> OverridenContents = llvm::None);
+runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos);
llvm::Expected<Tagged<std::vector<Location>>>
runFindDefinitions(ClangdServer &Server, PathRef File, Position Pos);