summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clangd/JSONExprTests.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clangd] Remove JSON library in favor of llvm/Support/JSONSam McCall2018-07-091-293/+0
| | | | | | | | | | | | | | | | | | | | Summary: The library has graduated from clangd to llvm/Support. This is a mechanical change to move to the new API and remove the old one. Main API changes: - namespace clang::clangd::json --> llvm::json - json::Expr --> json::Value - Expr::asString() etc --> Value::getAsString() etc - unsigned longs need a cast (due to r336541 adding lossless integer support) Reviewers: ilya-biryukov Subscribers: mgorny, ioeric, MaskRay, jkorous, omtcyfz, cfe-commits Differential Revision: https://reviews.llvm.org/D49077 llvm-svn: 336549
* [clangd] Hover should return null when not hovering over anything.Sam McCall2018-06-041-0/+2
| | | | | | | | | | | | Summary: Also made JSON serialize Optional<T> to simplify this. Reviewers: ioeric Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47701 llvm-svn: 333881
* [clangd] Use operator<< to prevent printers issues in GtestMarc-Andre Laperle2018-04-101-3/+1
| | | | | | | | | | | | | | | | | | | | | | | Summary: It is possible that there will be two different instantiations of the printer template for a given type and some tests could end up calling the wrong (default) one. For example, it was seen in CodeCompleteTests.cpp when printing CompletionItems that it would use the wrong printer because the default is also instantiated in ClangdTests.cpp. With this change, objects that were previously printed with a custom Printer now get printed through the operator<< which is declared alongside the class. This rule of the thumb should make it less error-prone. Reviewers: simark, ilya-biryukov, sammccall Reviewed By: simark, ilya-biryukov, sammccall Subscribers: bkramer, hokein, sammccall, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits Differential Revision: https://reviews.llvm.org/D44764 llvm-svn: 329725
* [clangd] New conventions for JSON-marshalling functions, centralize machinerySam McCall2017-11-301-0/+58
| | | | | | | | | | | | | | | | | | Summary: - JSON<->Obj interface is now ADL functions, so they play nicely with enums - recursive vector/map parsing and ObjectMapper moved to JSONExpr and tested - renamed (un)parse to (de)serialize, since text -> JSON is called parse - Protocol.cpp gets a bit shorter Sorry for the giant patch, it's prety mechanical though Reviewers: ilya-biryukov Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D40596 llvm-svn: 319478
* [clangd] Switch from YAMLParser to JSONExprSam McCall2017-11-281-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 319159
* [clangd] Add missing (but documented!) JSONExpr typed accessorsSam McCall2017-11-281-1/+43
| | | | | | | | | | | | | | Summary: Noticed this when I tried to port the Protocol.h parsers. And tests for the inspect API, which caught a small bug. Reviewers: ioeric Subscribers: ilya-biryukov Differential Revision: https://reviews.llvm.org/D40399 llvm-svn: 319157
* [clangd] avoid divide by literal zero to satisfy msvcSam McCall2017-11-211-1/+1
| | | | llvm-svn: 318798
* [clangd] use u8 strings in tests to avoid problems on windowsSam McCall2017-11-211-4/+4
| | | | llvm-svn: 318793
* [clangd] Add JSON tests with invalid unicodeSam McCall2017-11-211-1/+4
| | | | llvm-svn: 318791
* [clangd] Add parsing and value inspection to JSONExpr.Sam McCall2017-11-211-0/+74
| | | | | | | | | | | | | | | | | | | | | Summary: This will replace the places where we're using YAMLParser to parse JSON now: - the new marshalling code (T::parse()) should handle fewer cases and require fewer explicit casts - we'll early-reject invalid JSON that YAMLParser accepts - we'll be able to fix protocol-parsing bugs caused by the fact that YAML can only parse forward I plan to do the conversion as soon as this lands, but I don't want it in one patch as the protocol.cpp changes are conflict-prone. Reviewers: ioeric Subscribers: ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D40182 llvm-svn: 318774
* [clangd] clang-format the source code. NFC.Ilya Biryukov2017-11-151-14/+12
| | | | llvm-svn: 318317
* Fix compile issue on MSVC.Douglas Yung2017-11-081-3/+5
| | | | llvm-svn: 317642
* [clangd] MSVC - third time's the charmSam McCall2017-11-071-1/+1
| | | | llvm-svn: 317581
* [clangd] another try at fixing MSVCSam McCall2017-11-071-1/+1
| | | | llvm-svn: 317575
* ClangdTests/JSONExprTests.cpp: Appease g++-4.8 to move raw string literal ↵NAKAMURA Takumi2017-11-071-3/+5
| | | | | | out of macro arg. llvm-svn: 317538
* Adds a json::Expr type to represent intermediate JSON expressions.Sam McCall2017-11-061-0/+112
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
OpenPOWER on IntegriCloud