Adds a json::Expr type to represent intermediate JSON expressions.
authorSam McCall <sam.mccall@gmail.com>
Mon, 6 Nov 2017 15:40:30 +0000 (15:40 +0000)
committerSam McCall <sam.mccall@gmail.com>
Mon, 6 Nov 2017 15:40:30 +0000 (15:40 +0000)
commitdd0566bb2c50fbe7ee62f940d9d5b19220efb2a7
tree9abe3cd92e7f60ecd813fa329955c835e28f4676
parentad9b9720e8a580f9e544a8906f43a186ae7dedc6
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
31 files changed:
clang-tools-extra/clangd/CMakeLists.txt
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/JSONExpr.cpp [new file with mode: 0644]
clang-tools-extra/clangd/JSONExpr.h [new file with mode: 0644]
clang-tools-extra/clangd/JSONRPCDispatcher.cpp
clang-tools-extra/clangd/JSONRPCDispatcher.h
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/test/clangd/authority-less-uri.test
clang-tools-extra/test/clangd/completion-items-kinds.test
clang-tools-extra/test/clangd/completion-priorities.test
clang-tools-extra/test/clangd/completion-qualifiers.test
clang-tools-extra/test/clangd/completion-snippet.test
clang-tools-extra/test/clangd/completion.test
clang-tools-extra/test/clangd/definitions.test
clang-tools-extra/test/clangd/diagnostics-preamble.test
clang-tools-extra/test/clangd/diagnostics.test
clang-tools-extra/test/clangd/did-change-watch-files.test
clang-tools-extra/test/clangd/execute-command.test
clang-tools-extra/test/clangd/extra-flags.test
clang-tools-extra/test/clangd/fixits.test
clang-tools-extra/test/clangd/formatting.test
clang-tools-extra/test/clangd/initialize-params-invalid.test
clang-tools-extra/test/clangd/initialize-params.test
clang-tools-extra/test/clangd/input-mirror.test
clang-tools-extra/test/clangd/protocol.test
clang-tools-extra/test/clangd/signature-help.test
clang-tools-extra/test/clangd/unsupported-method.test
clang-tools-extra/unittests/clangd/CMakeLists.txt
clang-tools-extra/unittests/clangd/JSONExprTests.cpp [new file with mode: 0644]