summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2017-11-28 09:37:43 +0000
committerSam McCall <sam.mccall@gmail.com>2017-11-28 09:37:43 +0000
commit9140412c9103f709cbf4e608e70d5eb83a8376bf (patch)
tree4e829bc42be23528a4ee25ffbd7d934a96b9da17 /test
parent2b0a5d888a3fa3c9c779463728a8d409785ea1d4 (diff)
[clangd] Switch from YAMLParser to JSONExpr
Summary: - Converted Protocol.h parse() functions to take JSON::Expr. These no longer detect and log unknown fields, as this is not that useful and no longer free. I haven't changed the error handling too much: fields that were treated as optional before are still optional, even when it's wrong. Exception: object properties with the wrong type are now ignored. - Made JSONRPCDispatcher parse using json::parse - The bug where 'method' must come before 'params' in the stream is fixed as a side-effect. (And the same bug in executeCommand). - Some parser crashers fixed as a side effect. e.g. https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3890 - The debug stream now prettyprints the input messages with --pretty. - Request params are attached to traces when tracing is enabled. - Fixed some bugs in tests (errors tolerated by YAMLParser, and off-by-ones in Content-Length that our null-termination was masking) - Fixed a random double-escape bug in ClangdLSPServer (it was our last use of YAMLParser!) Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D40406 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@319159 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/clangd/authority-less-uri.test4
-rw-r--r--test/clangd/definitions.test18
-rw-r--r--test/clangd/diagnostics.test2
-rw-r--r--test/clangd/did-change-watch-files.test53
-rw-r--r--test/clangd/protocol.test2
5 files changed, 13 insertions, 66 deletions
diff --git a/test/clangd/authority-less-uri.test b/test/clangd/authority-less-uri.test
index 8d9b138d..500e0e02 100644
--- a/test/clangd/authority-less-uri.test
+++ b/test/clangd/authority-less-uri.test
@@ -28,7 +28,7 @@ Content-Length: 146
# CHECK-NEXT: "sortText": "{{.*}}fake"
# CHECK: ]
# CHECK-NEXT: }
-Content-Length: 172
+Content-Length: 173
{"jsonrpc":"2.0","id":2,"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")
@@ -51,4 +51,4 @@ Content-Length: 44
{"jsonrpc":"2.0","id":3,"method":"shutdown"}
Content-Length: 33
-{"jsonrpc":"2.0":"method":"exit"}
+{"jsonrpc":"2.0","method":"exit"}
diff --git a/test/clangd/definitions.test b/test/clangd/definitions.test
index a50f058f..9cc26109 100644
--- a/test/clangd/definitions.test
+++ b/test/clangd/definitions.test
@@ -101,7 +101,7 @@ Content-Length: 149
# CHECK-NEXT: "uri": "file:///{{([A-Z]:/)?}}main.cpp"
# CHECK-NEXT: }
# CHECK-NEXT: ]
-Content-Length: 187
+Content-Length: 188
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp","version":4},"contentChanges":[{"text":"int main() {\n main();\n return 0;\n}"}]}}
@@ -126,7 +126,7 @@ Content-Length: 148
# CHECK-NEXT: "uri": "file:///{{([A-Z]:/)?}}main.cpp"
# CHECK-NEXT: }
# CHECK-NEXT: ]
-Content-Length: 208
+Content-Length: 209
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp","version":5},"contentChanges":[{"text":"struct Foo {\n};\nint main() {\n Foo bar;\n return 0;\n}\n"}]}}
@@ -151,7 +151,7 @@ Content-Length: 148
# CHECK-NEXT: "uri": "file:///{{([A-Z]:/)?}}main.cpp"
# CHECK-NEXT: }
# CHECK-NEXT: ]
-Content-Length: 231
+Content-Length: 232
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp","version":5},"contentChanges":[{"text":"namespace n1 {\nstruct Foo {\n};\n}\nint main() {\n n1::Foo bar;\n return 0;\n}\n"}]}}
@@ -176,7 +176,7 @@ Content-Length: 148
# CHECK-NEXT: "uri": "file:///{{([A-Z]:/)?}}main.cpp"
# CHECK-NEXT: }
# CHECK-NEXT: ]
-Content-Length: 215
+Content-Length: 216
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp","version":6},"contentChanges":[{"text":"struct Foo {\n int x;\n};\nint main() {\n Foo bar;\n bar.x;\n}\n"}]}}
@@ -201,7 +201,7 @@ Content-Length: 148
# CHECK-NEXT: "uri": "file:///{{([A-Z]:/)?}}main.cpp"
# CHECK-NEXT: }
# CHECK-NEXT: ]
-Content-Length: 220
+Content-Length: 221
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp","version":7},"contentChanges":[{"text":"struct Foo {\n void x();\n};\nint main() {\n Foo bar;\n bar.x();\n}\n"}]}}
@@ -226,7 +226,7 @@ Content-Length: 148
# CHECK-NEXT: "uri": "file:///{{([A-Z]:/)?}}main.cpp"
# CHECK-NEXT: }
# CHECK-NEXT: ]
-Content-Length: 240
+Content-Length: 241
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp","version":7},"contentChanges":[{"text":"struct Foo {\n};\ntypedef Foo TypedefFoo;\nint main() {\n TypedefFoo bar;\n return 0;\n}\n"}]}}
@@ -251,7 +251,7 @@ Content-Length: 149
# CHECK-NEXT: "uri": "file:///{{([A-Z]:/)?}}main.cpp"
# CHECK-NEXT: }
# CHECK-NEXT: ]
-Content-Length: 254
+Content-Length: 253
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp","version":7},"contentChanges":[{"text":"template <typename MyTemplateParam>\nvoid foo() {\n MyTemplateParam a;\n}\nint main() {\n return 0;\n}\n"}]}}
@@ -262,7 +262,7 @@ Content-Length: 149
# CHECK: "id": 1,
# CHECK-NEXT: "jsonrpc": "2.0",
# CHECK-NEXT: "result": []
-Content-Length: 256
+Content-Length: 257
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp","version":7},"contentChanges":[{"text":"namespace ns {\nstruct Foo {\nstatic void bar() {}\n};\n}\nint main() {\n ns::Foo::bar();\n return 0;\n}\n"}]}}
@@ -418,4 +418,4 @@ Content-Length: 48
{"jsonrpc":"2.0","id":10000,"method":"shutdown"}
Content-Length: 33
-{"jsonrpc":"2.0":"method":"exit"}
+{"jsonrpc":"2.0","method":"exit"}
diff --git a/test/clangd/diagnostics.test b/test/clangd/diagnostics.test
index 99c222d8..85bbf984 100644
--- a/test/clangd/diagnostics.test
+++ b/test/clangd/diagnostics.test
@@ -47,4 +47,4 @@ Content-Length: 44
{"jsonrpc":"2.0","id":5,"method":"shutdown"}
Content-Length: 33
-{"jsonrpc":"2.0":"method":"exit"}
+{"jsonrpc":"2.0","method":"exit"}
diff --git a/test/clangd/did-change-watch-files.test b/test/clangd/did-change-watch-files.test
deleted file mode 100644
index 717a6dd5..00000000
--- a/test/clangd/did-change-watch-files.test
+++ /dev/null
@@ -1,53 +0,0 @@
-# RUN: clangd -run-synchronously < %s 2>&1 | FileCheck -check-prefix=STDERR %s
-# It is absolutely vital that this file has CRLF line endings.
-#
-# Test initialize request parameters with rootUri
-Content-Length: 143
-
-{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootUri":"file:///path/to/workspace","capabilities":{},"trace":"off"}}
-# Normal case.
-Content-Length: 217
-
-{"jsonrpc":"2.0","method":"workspace/didChangeWatchedFiles","params":{"changes":[{"uri":"file:///path/to/file.cpp","type":1},{"uri":"file:///path/to/file2.cpp","type":2},{"uri":"file:///path/to/file3.cpp","type":3}]}}
-
-# Wrong event type, integer
-Content-Length: 173
-
-{"jsonrpc":"2.0","method":"workspace/didChangeWatchedFiles","params":{"changes":[{"uri":"file:///path/to/file2.cpp","type":0},{"uri":"file:///path/to/file3.cpp","type":4}]}}
-# STDERR: Failed to decode a FileEvent.
-# Wrong event type, string
-Content-Length: 132
-
-{"jsonrpc":"2.0","method":"workspace/didChangeWatchedFiles","params":{"changes":[{"uri":"file:///path/to/file2.cpp","type":"foo"}]}}
-# STDERR: Failed to decode a FileEvent.
-#Custom event field
-Content-Length: 143
-
-{"jsonrpc":"2.0","method":"workspace/didChangeWatchedFiles","params":{"changes":[{"uri":"file:///path/to/file2.cpp","type":1,"custom":"foo"}]}}
-# STDERR: Failed to decode a FileEvent.
-#Event field with object
-Content-Length: 140
-
-{"jsonrpc":"2.0","method":"workspace/didChangeWatchedFiles","params":{"changes":[{"uri":"file:///path/to/file2.cpp","type":{"foo":"bar"}}]}}
-# STDERR: Failed to decode a FileEvent.
-# Changes field with sequence but no object
-Content-Length: 86
-
-{"jsonrpc":"2.0","method":"workspace/didChangeWatchedFiles","params":{"changes":[""]}}
-# STDERR: Failed to decode workspace/didChangeWatchedFiles request.
-# Changes field with no sequence
-Content-Length: 84
-
-{"jsonrpc":"2.0","method":"workspace/didChangeWatchedFiles","params":{"changes":""}}
-# STDERR: Failed to decode workspace/didChangeWatchedFiles request.
-# Custom field
-Content-Length: 86
-
-{"jsonrpc":"2.0","method":"workspace/didChangeWatchedFiles","params":{"custom":"foo"}}
-# STDERR: Ignored unknown field "custom"
-Content-Length: 44
-
-{"jsonrpc":"2.0","id":3,"method":"shutdown"}
-Content-Length: 33
-
-{"jsonrpc":"2.0":"method":"exit"}
diff --git a/test/clangd/protocol.test b/test/clangd/protocol.test
index 49b2d77c..d4c7da52 100644
--- a/test/clangd/protocol.test
+++ b/test/clangd/protocol.test
@@ -79,7 +79,7 @@ Content-Length: 10
{"jsonrpc":"2.0","id":4,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:/main.cpp"},"position":{"line":3,"character":5}}}
# Test message with malformed Content-Length
#
-# STDERR: JSON dispatch failed!
+# STDERR: JSON parse error
# Ensure we recover by sending another (valid) message
Content-Length: 146