summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
diff options
context:
space:
mode:
authorKadir Cetinkaya <kadircet@google.com>2020-01-09 16:54:22 +0100
committerKadir Cetinkaya <kadircet@google.com>2020-01-09 18:02:33 +0100
commit189aa5b7a4584677ad628ecc2c369db61d4d2515 (patch)
treedbc31577b9895c308b8f96ec646225eb040649c9 /clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
parent6498aff249a1c3c6bad33137df3b90e2973722d6 (diff)
downloadbcm5719-llvm-189aa5b7a4584677ad628ecc2c369db61d4d2515.tar.gz
bcm5719-llvm-189aa5b7a4584677ad628ecc2c369db61d4d2515.zip
[clangd] Adjust diagnostic range to be inside main file
Summary: LSP requires diagnostics to lay inside main file. In clangd we keep diagnostics in three different cases: - already in main file - adjusted to a header included in main file - has a note covering some range in main file In the last case, we were not adjusting the diagnostics range to be in main file, therefore these diagnostics ended up pointing some arbitrary locations. This patch fixes that issue by adjusting the range of diagnostics to be the first note inside main file when converting to LSP. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72458
Diffstat (limited to 'clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp')
-rw-r--r--clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 0941af25213..ef73519ef13 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1014,6 +1014,29 @@ TEST(IgnoreDiags, FromNonWrittenInclude) {
EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre());
}
+TEST(ToLSPDiag, RangeIsInMain) {
+ ClangdDiagnosticOptions Opts;
+ clangd::Diag D;
+ D.Range = {pos(1, 2), pos(3, 4)};
+ D.Notes.emplace_back();
+ Note &N = D.Notes.back();
+ N.Range = {pos(2, 3), pos(3, 4)};
+
+ D.InsideMainFile = true;
+ N.InsideMainFile = false;
+ toLSPDiags(D, {}, Opts,
+ [&](clangd::Diagnostic LSPDiag, ArrayRef<clangd::Fix>) {
+ EXPECT_EQ(LSPDiag.range, D.Range);
+ });
+
+ D.InsideMainFile = false;
+ N.InsideMainFile = true;
+ toLSPDiags(D, {}, Opts,
+ [&](clangd::Diagnostic LSPDiag, ArrayRef<clangd::Fix>) {
+ EXPECT_EQ(LSPDiag.range, N.Range);
+ });
+}
+
} // namespace
} // namespace clangd
} // namespace clang
OpenPOWER on IntegriCloud