[clang-tools-extra] bd6c697 - clangd: Set a diagnostic on a code action resulting from a tweak
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 10 06:58:39 PST 2022
Author: Christian Kandeler
Date: 2022-02-10T15:58:12+01:00
New Revision: bd6c6974f5ea1626a6bb1b6adea59616d70ff3a8
URL: https://github.com/llvm/llvm-project/commit/bd6c6974f5ea1626a6bb1b6adea59616d70ff3a8
DIFF: https://github.com/llvm/llvm-project/commit/bd6c6974f5ea1626a6bb1b6adea59616d70ff3a8.diff
LOG: clangd: Set a diagnostic on a code action resulting from a tweak
... if there is a match.
This is needed to that clients can can make a connection between a
diagnostic and an associated quickfix-tweak.
Ideally, quickfix-kind tweak code actions would be provided inline along
with the non-tweak fixes, but this doesn't seem easily achievable.
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D118976
Added:
Modified:
clang-tools-extra/clangd/ClangdLSPServer.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 8bd95b075fb93..0ec2052d094de 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -986,8 +986,8 @@ void ClangdLSPServer::onCodeAction(const CodeActionParams &Params,
// 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<std::vector<ClangdServer::TweakRef>> Tweaks) mutable {
if (!Tweaks)
return Reply(Tweaks.takeError());
@@ -1003,13 +1003,17 @@ void ClangdLSPServer::onCodeAction(const CodeActionParams &Params,
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));
More information about the cfe-commits
mailing list