[PATCH] D62999: [clangd] Return 'RequestCancelled' on spurious completion triggers

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 7 01:48:39 PDT 2019


ilya-biryukov created this revision.
ilya-biryukov added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

We currently return 'UnknownErrorCode' and it causes `coc.nvim` to
show an error message to the user, which we want to avoid.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62999

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/test/completion-auto-trigger.test


Index: clang-tools-extra/clangd/test/completion-auto-trigger.test
===================================================================
--- clang-tools-extra/clangd/test/completion-auto-trigger.test
+++ clang-tools-extra/clangd/test/completion-auto-trigger.test
@@ -5,7 +5,7 @@
 ---
 {"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":2,"character":9},"context":{"triggerKind":2,"triggerCharacter":">"}}}
 #      CHECK:  "error": {
-# CHECK-NEXT:    "code": -32001,
+# CHECK-NEXT:    "code": -32800,
 # CHECK-NEXT:    "message": "ignored auto-triggered completion, preceding char did not match"
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "id": 1,
@@ -65,7 +65,7 @@
 ---
 {"jsonrpc":"2.0","id":3,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":5,"character":9},"context":{"triggerKind":2,"triggerCharacter":":"}}}
 #      CHECK:  "error": {
-# CHECK-NEXT:    "code": -32001,
+# CHECK-NEXT:    "code": -32800,
 # CHECK-NEXT:    "message": "ignored auto-triggered completion, preceding char did not match"
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "id": 3,
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -25,16 +25,6 @@
 namespace clang {
 namespace clangd {
 namespace {
-class IgnoreCompletionError : public llvm::ErrorInfo<CancelledError> {
-public:
-  void log(llvm::raw_ostream &OS) const override {
-    OS << "ignored auto-triggered completion, preceding char did not match";
-  }
-  std::error_code convertToErrorCode() const override {
-    return std::make_error_code(std::errc::operation_canceled);
-  }
-};
-
 /// Transforms a tweak into a code action that would apply it if executed.
 /// EXPECTS: T.prepare() was called and returned true.
 CodeAction toCodeAction(const ClangdServer::TweakRef &T, const URIForFile &File,
@@ -739,7 +729,9 @@
 void ClangdLSPServer::onCompletion(const CompletionParams &Params,
                                    Callback<CompletionList> Reply) {
   if (!shouldRunCompletion(Params))
-    return Reply(llvm::make_error<IgnoreCompletionError>());
+    return Reply(llvm::make_error<LSPError>(
+        "ignored auto-triggered completion, preceding char did not match",
+        ErrorCode::RequestCancelled));
   Server->codeComplete(Params.textDocument.uri.file(), Params.position, CCOpts,
                        Bind(
                            [this](decltype(Reply) Reply,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62999.203514.patch
Type: text/x-patch
Size: 2614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190607/e9c6968a/attachment.bin>


More information about the cfe-commits mailing list