2019-05-28 17:20:57 +08:00
# RUN: not clangd -pretty -sync -enable-test-uri-scheme < %s | FileCheck -strict-whitespace %s
# RUN: not clangd -pretty -sync -enable-test-uri-scheme < %s 2>&1 | FileCheck -check-prefix=STDERR %s
2017-09-04 20:28:15 +08:00
# vim: fileformat=dos
# It is absolutely vital that this file has CRLF line endings.
#
2017-10-25 16:45:41 +08:00
# Note that we invert the test because we intent to let clangd exit prematurely.
#
2017-09-04 20:28:15 +08:00
# Test protocol parsing
Content-Length: 125
Content-Type: application/vscode-jsonrpc; charset-utf-8
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
# Test message with Content-Type after Content-Length
#
Adds a json::Expr type to represent intermediate JSON expressions.
Summary:
This form can be created with a nice clang-format-friendly literal syntax,
and gets escaping right. It knows how to call unparse() on our Protocol types.
All the places where we pass around JSON internally now use this type.
Object properties are sorted (stored as std::map) and so serialization is
canonicalized, with optional prettyprinting (triggered by a -pretty flag).
This makes the lit tests much nicer to read and somewhat nicer to debug.
(Unfortunately the completion tests use CHECK-DAG, which only has
line-granularity, so pretty-printing is disabled there. In future we
could make completion ordering deterministic, or switch to unittests).
Compared to the current approach, it has some efficiencies like avoiding copies
of string literals used as object keys, but is probably slower overall.
I think the code/test quality benefits are worth it.
This patch doesn't attempt to do anything about JSON *parsing*.
It takes direction from the proposal in this doc[1], but is limited in scope
and visibility, for now.
I am of half a mind just to use Expr as the target of a parser, and maybe do a
little string deduplication, but not bother with clever memory allocation.
That would be simple, and fast enough for clangd...
[1] https://docs.google.com/document/d/1OEF9IauWwNuSigZzvvbjc1cVS1uGHRyGTXaoy3DjqM4/edit
+cc d0k so he can tell me not to use std::map.
Reviewers: ioeric, malaperle
Subscribers: bkramer, ilya-biryukov, mgorny, klimek
Differential Revision: https://reviews.llvm.org/D39435
llvm-svn: 317486
2017-11-06 23:40:30 +08:00
# CHECK: "jsonrpc": "2.0",
# CHECK-NEXT: "result": {
# CHECK: }
2017-09-04 20:28:15 +08:00
Content-Length: 246
2018-02-01 00:26:27 +08:00
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"struct fake { int a, bb, ccc; int f(int i, const float f) const; };\nint main() {\n fake f;\n f.\n}\n"}}}
2017-09-04 20:28:15 +08:00
2017-10-26 18:36:20 +08:00
Content-Length: 104
2018-02-01 00:26:27 +08:00
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///main.cpp"}}}
2017-10-26 18:36:20 +08:00
2017-09-04 20:28:15 +08:00
Content-Type: application/vscode-jsonrpc; charset-utf-8
Content-Length: 146
2018-02-01 00:26:27 +08:00
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:/main.cpp"},"position":{"line":3,"character":5}}}
2017-09-04 20:28:15 +08:00
# Test message with Content-Type before Content-Length
#
Adds a json::Expr type to represent intermediate JSON expressions.
Summary:
This form can be created with a nice clang-format-friendly literal syntax,
and gets escaping right. It knows how to call unparse() on our Protocol types.
All the places where we pass around JSON internally now use this type.
Object properties are sorted (stored as std::map) and so serialization is
canonicalized, with optional prettyprinting (triggered by a -pretty flag).
This makes the lit tests much nicer to read and somewhat nicer to debug.
(Unfortunately the completion tests use CHECK-DAG, which only has
line-granularity, so pretty-printing is disabled there. In future we
could make completion ordering deterministic, or switch to unittests).
Compared to the current approach, it has some efficiencies like avoiding copies
of string literals used as object keys, but is probably slower overall.
I think the code/test quality benefits are worth it.
This patch doesn't attempt to do anything about JSON *parsing*.
It takes direction from the proposal in this doc[1], but is limited in scope
and visibility, for now.
I am of half a mind just to use Expr as the target of a parser, and maybe do a
little string deduplication, but not bother with clever memory allocation.
That would be simple, and fast enough for clangd...
[1] https://docs.google.com/document/d/1OEF9IauWwNuSigZzvvbjc1cVS1uGHRyGTXaoy3DjqM4/edit
+cc d0k so he can tell me not to use std::map.
Reviewers: ioeric, malaperle
Subscribers: bkramer, ilya-biryukov, mgorny, klimek
Differential Revision: https://reviews.llvm.org/D39435
llvm-svn: 317486
2017-11-06 23:40:30 +08:00
# CHECK: "id": 1,
# CHECK-NEXT: "jsonrpc": "2.0",
2017-11-15 17:16:29 +08:00
# CHECK-NEXT: "result": {
# CHECK-NEXT: "isIncomplete": false,
# CHECK-NEXT: "items": [
2018-06-07 20:49:17 +08:00
# CHECK: "filterText": "a",
# CHECK-NEXT: "insertText": "a",
2017-11-15 17:16:29 +08:00
# CHECK-NEXT: "insertTextFormat": 1,
2018-06-07 20:49:17 +08:00
# CHECK-NEXT: "kind": 5,
2018-06-15 21:34:18 +08:00
# CHECK-NEXT: "label": " a",
2020-02-13 21:17:30 +08:00
# CHECK-NEXT: "score": {{[0-9]+.[0-9]+}},
2017-11-24 01:09:04 +08:00
# CHECK-NEXT: "sortText": "{{.*}}"
2017-11-15 17:16:29 +08:00
# CHECK: ]
# CHECK-NEXT: }
2017-09-04 20:28:15 +08:00
X-Test: Testing
Content-Type: application/vscode-jsonrpc; charset-utf-8
Content-Length: 146
Content-Type: application/vscode-jsonrpc; charset-utf-8
X-Testing: Test
2018-02-01 00:26:27 +08:00
{"jsonrpc":"2.0","id":2,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:/main.cpp"},"position":{"line":3,"character":5}}}
2017-09-04 20:28:15 +08:00
Content-Type: application/vscode-jsonrpc; charset-utf-8
Content-Length: 10
Content-Length: 146
2018-02-01 00:26:27 +08:00
{"jsonrpc":"2.0","id":3,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:/main.cpp"},"position":{"line":3,"character":5}}}
2017-09-04 20:28:15 +08:00
# Test message with duplicate Content-Length headers
#
Adds a json::Expr type to represent intermediate JSON expressions.
Summary:
This form can be created with a nice clang-format-friendly literal syntax,
and gets escaping right. It knows how to call unparse() on our Protocol types.
All the places where we pass around JSON internally now use this type.
Object properties are sorted (stored as std::map) and so serialization is
canonicalized, with optional prettyprinting (triggered by a -pretty flag).
This makes the lit tests much nicer to read and somewhat nicer to debug.
(Unfortunately the completion tests use CHECK-DAG, which only has
line-granularity, so pretty-printing is disabled there. In future we
could make completion ordering deterministic, or switch to unittests).
Compared to the current approach, it has some efficiencies like avoiding copies
of string literals used as object keys, but is probably slower overall.
I think the code/test quality benefits are worth it.
This patch doesn't attempt to do anything about JSON *parsing*.
It takes direction from the proposal in this doc[1], but is limited in scope
and visibility, for now.
I am of half a mind just to use Expr as the target of a parser, and maybe do a
little string deduplication, but not bother with clever memory allocation.
That would be simple, and fast enough for clangd...
[1] https://docs.google.com/document/d/1OEF9IauWwNuSigZzvvbjc1cVS1uGHRyGTXaoy3DjqM4/edit
+cc d0k so he can tell me not to use std::map.
Reviewers: ioeric, malaperle
Subscribers: bkramer, ilya-biryukov, mgorny, klimek
Differential Revision: https://reviews.llvm.org/D39435
llvm-svn: 317486
2017-11-06 23:40:30 +08:00
# CHECK: "id": 3,
# CHECK-NEXT: "jsonrpc": "2.0",
2017-11-15 17:16:29 +08:00
# CHECK-NEXT: "result": {
# CHECK-NEXT: "isIncomplete": false,
# CHECK-NEXT: "items": [
2018-06-07 20:49:17 +08:00
# CHECK: "filterText": "a",
# CHECK-NEXT: "insertText": "a",
2017-11-15 17:16:29 +08:00
# CHECK-NEXT: "insertTextFormat": 1,
2018-06-07 20:49:17 +08:00
# CHECK-NEXT: "kind": 5,
2018-06-15 21:34:18 +08:00
# CHECK-NEXT: "label": " a",
2020-02-13 21:17:30 +08:00
# CHECK-NEXT: "score": {{[0-9]+.[0-9]+}},
2017-11-24 01:09:04 +08:00
# CHECK-NEXT: "sortText": "{{.*}}"
2017-11-15 17:16:29 +08:00
# CHECK: ]
# CHECK-NEXT: }
2017-09-04 20:28:15 +08:00
# STDERR: Warning: Duplicate Content-Length header received. The previous value for this message (10) was ignored.
Content-Type: application/vscode-jsonrpc; charset-utf-8
Content-Length: 10
2018-02-01 00:26:27 +08:00
{"jsonrpc":"2.0","id":4,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:/main.cpp"},"position":{"line":3,"character":5}}}
2017-09-04 20:28:15 +08:00
# Test message with malformed Content-Length
#
2017-11-28 17:37:43 +08:00
# STDERR: JSON parse error
2017-09-04 20:28:15 +08:00
# Ensure we recover by sending another (valid) message
Content-Length: 146
2018-02-01 00:26:27 +08:00
{"jsonrpc":"2.0","id":5,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:/main.cpp"},"position":{"line":3,"character":5}}}
2017-09-04 20:28:15 +08:00
# Test message with Content-Type before Content-Length
#
Adds a json::Expr type to represent intermediate JSON expressions.
Summary:
This form can be created with a nice clang-format-friendly literal syntax,
and gets escaping right. It knows how to call unparse() on our Protocol types.
All the places where we pass around JSON internally now use this type.
Object properties are sorted (stored as std::map) and so serialization is
canonicalized, with optional prettyprinting (triggered by a -pretty flag).
This makes the lit tests much nicer to read and somewhat nicer to debug.
(Unfortunately the completion tests use CHECK-DAG, which only has
line-granularity, so pretty-printing is disabled there. In future we
could make completion ordering deterministic, or switch to unittests).
Compared to the current approach, it has some efficiencies like avoiding copies
of string literals used as object keys, but is probably slower overall.
I think the code/test quality benefits are worth it.
This patch doesn't attempt to do anything about JSON *parsing*.
It takes direction from the proposal in this doc[1], but is limited in scope
and visibility, for now.
I am of half a mind just to use Expr as the target of a parser, and maybe do a
little string deduplication, but not bother with clever memory allocation.
That would be simple, and fast enough for clangd...
[1] https://docs.google.com/document/d/1OEF9IauWwNuSigZzvvbjc1cVS1uGHRyGTXaoy3DjqM4/edit
+cc d0k so he can tell me not to use std::map.
Reviewers: ioeric, malaperle
Subscribers: bkramer, ilya-biryukov, mgorny, klimek
Differential Revision: https://reviews.llvm.org/D39435
llvm-svn: 317486
2017-11-06 23:40:30 +08:00
# CHECK: "id": 5,
# CHECK-NEXT: "jsonrpc": "2.0",
2017-11-15 17:16:29 +08:00
# CHECK-NEXT: "result": {
# CHECK-NEXT: "isIncomplete": false,
# CHECK-NEXT: "items": [
2018-06-07 20:49:17 +08:00
# CHECK: "filterText": "a",
# CHECK-NEXT: "insertText": "a",
2017-11-15 17:16:29 +08:00
# CHECK-NEXT: "insertTextFormat": 1,
2018-06-07 20:49:17 +08:00
# CHECK-NEXT: "kind": 5,
2018-06-15 21:34:18 +08:00
# CHECK-NEXT: "label": " a",
2020-02-13 21:17:30 +08:00
# CHECK-NEXT: "score": {{[0-9]+.[0-9]+}},
2017-11-24 01:09:04 +08:00
# CHECK-NEXT: "sortText": "{{.*}}"
2017-11-15 17:16:29 +08:00
# CHECK: ]
# CHECK-NEXT: }
2017-09-04 20:28:15 +08:00
Content-Length: 1024
2018-02-01 00:26:27 +08:00
{"jsonrpc":"2.0","id":5,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:/main.cpp"},"position":{"line":3,"character":5}}}
2017-09-04 20:28:15 +08:00
# Test message which reads beyond the end of the stream.
#
# Ensure this is the last test in the file!
# STDERR: Input was aborted. Read only {{[0-9]+}} bytes of expected {{[0-9]+}}.