ckandeler created this revision.
ckandeler added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
ckandeler requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

... 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.


Repository:
  rG LLVM Github Monorepo

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,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<std::vector<ClangdServer::TweakRef>> Tweaks) mutable {
         if (!Tweaks)
@@ -994,8 +994,17 @@
 
         std::vector<CodeAction> 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.


Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ 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<std::vector<ClangdServer::TweakRef>> Tweaks) mutable {
         if (!Tweaks)
@@ -994,8 +994,17 @@
 
         std::vector<CodeAction> 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.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to