diff options
author | Sam McCall <sam.mccall@gmail.com> | 2017-12-20 10:26:53 +0000 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2017-12-20 10:26:53 +0000 |
commit | 1924bbedccb1c49b0c3c0ba7f695d5a603e998a7 (patch) | |
tree | 638bdea701167638840c136bd1b9ae56c044c581 | |
parent | 44fb880b33ca87bfe34a57145fb1fd3f9b03613d (diff) |
[clangd] Add debug printers for basic protocol types. NFC
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@321161 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | clangd/Protocol.cpp | 16 | ||||
-rw-r--r-- | clangd/Protocol.h | 7 | ||||
-rw-r--r-- | unittests/clangd/SourceCodeTests.cpp | 4 |
3 files changed, 23 insertions, 4 deletions
diff --git a/clangd/Protocol.cpp b/clangd/Protocol.cpp index 2b9bd8e0..f6fc9aff 100644 --- a/clangd/Protocol.cpp +++ b/clangd/Protocol.cpp @@ -59,6 +59,10 @@ bool fromJSON(const json::Expr &E, URI &R) { json::Expr toJSON(const URI &U) { return U.uri; } +llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const URI &U) { + return OS << U.uri; +} + bool fromJSON(const json::Expr &Params, TextDocumentIdentifier &R) { json::ObjectMapper O(Params); return O && O.map("uri", R.uri); @@ -76,6 +80,10 @@ json::Expr toJSON(const Position &P) { }; } +llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Position &P) { + return OS << P.line << ':' << P.character; +} + bool fromJSON(const json::Expr &Params, Range &R) { json::ObjectMapper O(Params); return O && O.map("start", R.start) && O.map("end", R.end); @@ -88,6 +96,10 @@ json::Expr toJSON(const Range &P) { }; } +llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Range &R) { + return OS << R.start << '-' << R.end; +} + json::Expr toJSON(const Location &P) { return json::obj{ {"uri", P.uri}, @@ -95,6 +107,10 @@ json::Expr toJSON(const Location &P) { }; } +llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Location &L) { + return OS << L.range << '@' << L.uri; +} + bool fromJSON(const json::Expr &Params, TextDocumentItem &R) { json::ObjectMapper O(Params); return O && O.map("uri", R.uri) && O.map("languageId", R.languageId) && diff --git a/clangd/Protocol.h b/clangd/Protocol.h index f2ad0db0..1b91b3c1 100644 --- a/clangd/Protocol.h +++ b/clangd/Protocol.h @@ -16,6 +16,9 @@ // Each struct has a toJSON and fromJSON function, that converts between // the struct and a JSON representation. (See JSONExpr.h) // +// Some structs also have operator<< serialization. This is for debugging and +// tests, and is not generally machine-readable. +// //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H @@ -65,6 +68,7 @@ struct URI { }; json::Expr toJSON(const URI &U); bool fromJSON(const json::Expr &, URI &); +llvm::raw_ostream &operator<<(llvm::raw_ostream &, const URI &); struct TextDocumentIdentifier { /// The text document's URI. @@ -90,6 +94,7 @@ struct Position { }; bool fromJSON(const json::Expr &, Position &); json::Expr toJSON(const Position &); +llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Position &); struct Range { /// The range's start position. @@ -107,6 +112,7 @@ struct Range { }; bool fromJSON(const json::Expr &, Range &); json::Expr toJSON(const Range &); +llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Range &); struct Location { /// The text document's URI. @@ -126,6 +132,7 @@ struct Location { } }; json::Expr toJSON(const Location &); +llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Location &); struct Metadata { std::vector<std::string> extraFlags; diff --git a/unittests/clangd/SourceCodeTests.cpp b/unittests/clangd/SourceCodeTests.cpp index bc64276d..8bfae7b9 100644 --- a/unittests/clangd/SourceCodeTests.cpp +++ b/unittests/clangd/SourceCodeTests.cpp @@ -13,10 +13,6 @@ namespace clang{ namespace clangd { -void PrintTo(const Position &P, std::ostream *O) { - llvm::raw_os_ostream OS(*O); - OS << toJSON(P); -} namespace { MATCHER_P2(Pos, Line, Col, "") { |