[clangd] Fix missing "message" key when responding with unsupported method
authorBenjamin Kramer <benny.kra@googlemail.com>
Mon, 25 Sep 2017 17:16:47 +0000 (17:16 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Mon, 25 Sep 2017 17:16:47 +0000 (17:16 +0000)
The language server protocol dictates that a ResponseError should have a
[message string][1] describing the error. This adds a simple message to the
error and a simple test.

[1]: https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#response-message

Patch by Raoul Wols!

Differential Revision: https://reviews.llvm.org/D38225

llvm-svn: 314119

clang-tools-extra/clangd/JSONRPCDispatcher.cpp
clang-tools-extra/test/clangd/unsupported-method.test [new file with mode: 0644]

index 2f38e9c..6641aae 100644 (file)
@@ -42,7 +42,7 @@ void Handler::handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) {
   // Return that this method is unsupported.
   writeMessage(
       R"({"jsonrpc":"2.0","id":)" + ID +
-      R"(,"error":{"code":-32601}})");
+      R"(,"error":{"code":-32601,"message":"method not found"}})");
 }
 
 void Handler::handleNotification(llvm::yaml::MappingNode *Params) {
diff --git a/clang-tools-extra/test/clangd/unsupported-method.test b/clang-tools-extra/test/clangd/unsupported-method.test
new file mode 100644 (file)
index 0000000..200bae0
--- /dev/null
@@ -0,0 +1,19 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s\r
+# It is absolutely vital that this file has CRLF line endings.\r
+#\r
+Content-Length: 125\r
+\r
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}\r
+\r
+Content-Length: 143\r
+\r
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":""}}}\r
+\r
+Content-Length: 92\r
+\r
+{"jsonrpc":"2.0","id":1,"method":"textDocument/jumpInTheAirLikeYouJustDontCare","params":{}}\r
+# CHECK: {"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"method not found"}}\r
+\r
+Content-Length: 44\r
+\r
+{"jsonrpc":"2.0","id":2,"method":"shutdown"}\r