[clangd] Add debug printers for basic protocol types. NFC
llvm-svn: 321161
This commit is contained in:
parent
030123e8e8
commit
fffa8229e3
|
@ -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) &&
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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, "") {
|
||||
|
|
Loading…
Reference in New Issue