[clang-tools-extra] r300991 - [Clangd] Failed to decode params using 1.x-compatible request message

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 21 08:51:23 PDT 2017


Author: d0k
Date: Fri Apr 21 10:51:23 2017
New Revision: 300991

URL: http://llvm.org/viewvc/llvm-project?rev=300991&view=rev
Log:
[Clangd] Failed to decode params using 1.x-compatible request message

textDocument/completion sends a TextDocumentPositionParams message in the 2.x
and 3.x. But in 1.x it was instead a TextDocumentPosition with inlined
parameters. This means that the "uri" field is at the top level and not in
textDocument. Because of this, some clients that maintain compability with 1.x
have both uri and textDocument.uri. Clangd, however, early returns in the
presence of anything but 'textDocument' or 'position' which prevents a client
compatible with both 3.x and 1.x to work correctly. If Clangd was a bit more
permissive (no early return), clients implementing all the versions of the
protocol would work.

Patch by Marc-Andre Laperle!

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

Modified:
    clang-tools-extra/trunk/clangd/Protocol.cpp
    clang-tools-extra/trunk/test/clangd/completion.test

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=300991&r1=300990&r2=300991&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Fri Apr 21 10:51:23 2017
@@ -648,7 +648,7 @@ TextDocumentPositionParams::parse(llvm::
     auto *Value =
         dyn_cast_or_null<llvm::yaml::MappingNode>(NextKeyValue.getValue());
     if (!Value)
-      return llvm::None;
+      continue;
 
     llvm::SmallString<10> Storage;
     if (KeyValue == "textDocument") {

Modified: clang-tools-extra/trunk/test/clangd/completion.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/completion.test?rev=300991&r1=300990&r2=300991&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clangd/completion.test (original)
+++ clang-tools-extra/trunk/test/clangd/completion.test Fri Apr 21 10:51:23 2017
@@ -30,6 +30,17 @@ Content-Length: 146
 # CHECK-DAG: {"label":"bb","kind":5}
 # CHECK-DAG: {"label":"ccc","kind":5}
 # CHECK: ]}
+
+Content-Length: 172
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"uri":"file:///main.cpp","position":{"line":3,"character":5}}}
+# Test params parsing in the presence of a 1.x-compatible client (inlined "uri")
+#
+# CHECK: {"jsonrpc":"2.0","id":1,"result":[
+# CHECK-DAG: {"label":"a","kind":5}
+# CHECK-DAG: {"label":"bb","kind":5}
+# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK: ]}
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":3,"method":"shutdown"}




More information about the cfe-commits mailing list