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,8 +986,8 @@ // Now enumerate the semantic code actions. auto ConsumeActions = - [Reply = std::move(Reply), File, Selection = Params.range, - FixIts = std::move(FixIts), this]( + [Diags = Params.context.diagnostics, Reply = std::move(Reply), File, + Selection = Params.range, FixIts = std::move(FixIts), this]( llvm::Expected> Tweaks) mutable { if (!Tweaks) return Reply(Tweaks.takeError()); @@ -1003,13 +1003,17 @@ for (auto &Action : Actions) { if (Action.kind && *Action.kind == CodeAction::QUICKFIX_KIND) { if (OnlyFix) { - OnlyFix->isPreferred = false; + OnlyFix = nullptr; break; } - Action.isPreferred = true; OnlyFix = &Action; } } + if (OnlyFix) { + OnlyFix->isPreferred = true; + if (Diags.size() == 1 && Diags.front().range == Selection) + OnlyFix->diagnostics = {Diags.front()}; + } if (SupportsCodeAction) return Reply(llvm::json::Array(Actions));