diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -526,6 +526,9 @@ } } Main.tags = D.Tags; + // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag. + for (auto &Entry : D.OpaqueData) + Main.data.insert({Entry.first, Entry.second}); OutFn(std::move(Main), D.Fixes); // If we didn't emit the notes as relatedLocations, emit separate diagnostics @@ -540,10 +543,6 @@ Res.message = noteMessage(D, Note, Opts); OutFn(std::move(Res), llvm::ArrayRef()); } - - // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag. - for (auto &Entry : D.OpaqueData) - Main.data.insert({Entry.first, Entry.second}); } int getSeverity(DiagnosticsEngine::Level L) { diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp --- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp @@ -23,6 +23,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticSema.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/JSON.h" #include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/TargetSelect.h" #include "gmock/gmock.h" @@ -1012,6 +1013,7 @@ D.Severity = DiagnosticsEngine::Error; D.File = "foo/bar/main.cpp"; D.AbsFile = std::string(MainFile.file()); + D.OpaqueData["test"] = "bar"; clangd::Note NoteInMain; NoteInMain.Message = "declared somewhere in the main file"; @@ -1050,6 +1052,7 @@ ../foo/baz/header.h:10:11: note: declared somewhere in the header file)"; MainLSP.tags = {DiagnosticTag::Unnecessary}; + MainLSP.data = D.OpaqueData; clangd::Diagnostic NoteInMainLSP; NoteInMainLSP.range = NoteInMain.Range;