ckandeler updated this revision to Diff 405911. ckandeler added a comment. Formatting & logic.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D118976/new/ https://reviews.llvm.org/D118976 Files: clang-tools-extra/clangd/ClangdLSPServer.cpp Index: clang-tools-extra/clangd/ClangdLSPServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -986,9 +986,9 @@ // Now enumerate the semantic code actions. auto ConsumeActions = - [Reply = std::move(Reply), File, Selection = Params.range, - FixIts = std::move(FixIts), this]( - llvm::Expected<std::vector<ClangdServer::TweakRef>> Tweaks) mutable { + [Diags = Params.context.diagnostics, Reply = std::move(Reply), File, + Selection = Params.range, FixIts = std::move(FixIts), this]( + llvm::Expected<std::vector<ClangdServer::TweakRef>> Tweaks) mutable { if (!Tweaks) return Reply(Tweaks.takeError()); @@ -999,17 +999,21 @@ // If there's exactly one quick-fix, call it "preferred". // We never consider refactorings etc as preferred. - CodeAction *OnlyFix = nullptr; + Optional<CodeAction *> OnlyFix; // nullptr means multiple fixes 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) { + (*OnlyFix)->isPreferred = true; + if (Diags.size() == 1 && Diags.front().range == Selection) + (*OnlyFix)->diagnostics = {Diags.front()}; + } if (SupportsCodeAction) return Reply(llvm::json::Array(Actions));
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -986,9 +986,9 @@ // Now enumerate the semantic code actions. auto ConsumeActions = - [Reply = std::move(Reply), File, Selection = Params.range, - FixIts = std::move(FixIts), this]( - llvm::Expected<std::vector<ClangdServer::TweakRef>> Tweaks) mutable { + [Diags = Params.context.diagnostics, Reply = std::move(Reply), File, + Selection = Params.range, FixIts = std::move(FixIts), this]( + llvm::Expected<std::vector<ClangdServer::TweakRef>> Tweaks) mutable { if (!Tweaks) return Reply(Tweaks.takeError()); @@ -999,17 +999,21 @@ // If there's exactly one quick-fix, call it "preferred". // We never consider refactorings etc as preferred. - CodeAction *OnlyFix = nullptr; + Optional<CodeAction *> OnlyFix; // nullptr means multiple fixes 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) { + (*OnlyFix)->isPreferred = true; + if (Diags.size() == 1 && Diags.front().range == Selection) + (*OnlyFix)->diagnostics = {Diags.front()}; + } if (SupportsCodeAction) return Reply(llvm::json::Array(Actions));
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits