From d3326a04e061f082798790f6befb097ddf4ffde3 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 21 Apr 2017 15:51:23 +0000 Subject: [PATCH] [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 llvm-svn: 300991 --- clang-tools-extra/clangd/Protocol.cpp | 2 +- clang-tools-extra/test/clangd/completion.test | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp index 5a2f2ae..016d8fd 100644 --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -648,7 +648,7 @@ TextDocumentPositionParams::parse(llvm::yaml::MappingNode *Params) { auto *Value = dyn_cast_or_null(NextKeyValue.getValue()); if (!Value) - return llvm::None; + continue; llvm::SmallString<10> Storage; if (KeyValue == "textDocument") { diff --git a/clang-tools-extra/test/clangd/completion.test b/clang-tools-extra/test/clangd/completion.test index 57189ad..e3f3ffa 100644 --- a/clang-tools-extra/test/clangd/completion.test +++ b/clang-tools-extra/test/clangd/completion.test @@ -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"} -- 2.7.4