[clangd] Add ClangdUnit diagnostics tests using annotated code.
Summary:
This adds checks that our diagnostics emit correct ranges in a bunch of cases,
as promised in D41118.
The diagnostics-preamble test is also converted and extended to be a little more
precise.
diagnostics.test stays around as the smoke test for this feature.
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D41454
llvm-svn: 323448
diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp
index 4c7c69c..7629fac 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -137,6 +137,12 @@
};
}
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const TextEdit &TE) {
+ OS << TE.range << " => \"";
+ PrintEscapedString(TE.newText, OS);
+ return OS << '"';
+}
+
bool fromJSON(const json::Expr &E, TraceLevel &Out) {
if (auto S = E.asString()) {
if (*S == "off") {
@@ -255,6 +261,28 @@
return O && O.map("diagnostics", R.diagnostics);
}
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Diagnostic &D) {
+ OS << D.range << " [";
+ switch (D.severity) {
+ case 1:
+ OS << "error";
+ break;
+ case 2:
+ OS << "warning";
+ break;
+ case 3:
+ OS << "note";
+ break;
+ case 4:
+ OS << "remark";
+ break;
+ default:
+ OS << "diagnostic";
+ break;
+ }
+ return OS << '(' << D.severity << "): " << D.message << "]";
+}
+
bool fromJSON(const json::Expr &Params, CodeActionParams &R) {
json::ObjectMapper O(Params);
return O && O.map("textDocument", R.textDocument) &&