diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -986,7 +986,7 @@ // Now enumerate the semantic code actions. auto ConsumeActions = - [Reply = std::move(Reply), File, Selection = Params.range, + [Diags = Params.context.diagnostics, Reply = std::move(Reply), File, Selection = Params.range, FixIts = std::move(FixIts), this]( llvm::Expected> Tweaks) mutable { if (!Tweaks) @@ -994,8 +994,17 @@ std::vector Actions = std::move(FixIts); Actions.reserve(Actions.size() + Tweaks->size()); - for (const auto &T : *Tweaks) + for (const auto &T : *Tweaks) { Actions.push_back(toCodeAction(T, File, Selection)); + if (T.Kind != CodeAction::QUICKFIX_KIND) + continue; + for (const Diagnostic &D : Diags) { + if (D.range == Selection) { + Actions.back().diagnostics = {D}; + break; + } + } + } // If there's exactly one quick-fix, call it "preferred". // We never consider refactorings etc as preferred.