[clang-tools-extra] r326211 - [clangd] Remove codecomplete override content API. Long live addDocument!

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 27 09:15:50 PST 2018


Author: sammccall
Date: Tue Feb 27 09:15:50 2018
New Revision: 326211

URL: http://llvm.org/viewvc/llvm-project?rev=326211&view=rev
Log:
[clangd] Remove codecomplete override content API. Long live addDocument!

Modified:
    clang-tools-extra/trunk/clangd/ClangdServer.cpp
    clang-tools-extra/trunk/clangd/ClangdServer.h
    clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
    clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
    clang-tools-extra/trunk/unittests/clangd/SyncAPI.h

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=326211&r1=326210&r2=326211&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Feb 27 09:15:50 2018
@@ -141,7 +141,6 @@ void ClangdServer::forceReparse(PathRef
 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 @@ void ClangdServer::codeComplete(
   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 @@ void ClangdServer::codeComplete(
 
   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 @@ void ClangdServer::signatureHelp(
         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>

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=326211&r1=326210&r2=326211&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Tue Feb 27 09:15:50 2018
@@ -171,10 +171,7 @@ public:
   /// 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 @@ public:
   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.

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=326211&r1=326210&r2=326211&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Tue Feb 27 09:15:50 2018
@@ -337,24 +337,6 @@ TEST(CompletionTest, CompletionOptions)
   }
 }
 
-// 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 {

Modified: clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp?rev=326211&r1=326210&r2=326211&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp Tue Feb 27 09:15:50 2018
@@ -61,20 +61,18 @@ template <typename T> CaptureProxy<T> ca
 }
 } // 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);
 }
 

Modified: clang-tools-extra/trunk/unittests/clangd/SyncAPI.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SyncAPI.h?rev=326211&r1=326210&r2=326211&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/SyncAPI.h (original)
+++ clang-tools-extra/trunk/unittests/clangd/SyncAPI.h Tue Feb 27 09:15:50 2018
@@ -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);




More information about the cfe-commits mailing list