|
44 | 44 | #include "llvm/ADT/STLExtras.h" |
45 | 45 | #include "llvm/ADT/StringRef.h" |
46 | 46 | #include "llvm/Support/Error.h" |
| 47 | +#include "llvm/Support/Format.h" |
47 | 48 | #include "llvm/Support/Path.h" |
48 | 49 | #include "llvm/Support/raw_ostream.h" |
49 | 50 | #include <algorithm> |
@@ -672,6 +673,21 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) { |
672 | 673 | return std::nullopt; |
673 | 674 | } |
674 | 675 |
|
| 676 | +// Add NOLINT insert as code actions |
| 677 | +std::optional<Fix> tryAddClangTidySuppression(const Diag *Diag) { |
| 678 | + if (Diag->Source == Diag::ClangTidy) { |
| 679 | + Fix F; |
| 680 | + F.Message = llvm::formatv("ignore [{0}] for this line", Diag->Name); |
| 681 | + TextEdit &E = F.Edits.emplace_back(); |
| 682 | + E.newText = llvm::formatv("// NOLINTNEXTLINE({0})\n", Diag->Name); |
| 683 | + Position InsertPos = Diag->Range.start; |
| 684 | + InsertPos.character = 0; |
| 685 | + E.range = {InsertPos, InsertPos}; |
| 686 | + return F; |
| 687 | + } |
| 688 | + return std::nullopt; |
| 689 | +} |
| 690 | + |
675 | 691 | } // namespace |
676 | 692 |
|
677 | 693 | void ClangdServer::codeAction(const CodeActionInputs &Params, |
@@ -701,14 +717,19 @@ void ClangdServer::codeAction(const CodeActionInputs &Params, |
701 | 717 | return nullptr; |
702 | 718 | }; |
703 | 719 | for (const auto &DiagRef : Params.Diagnostics) { |
704 | | - if (const auto *Diag = FindMatchedDiag(DiagRef)) |
| 720 | + if (const auto *Diag = FindMatchedDiag(DiagRef)) { |
705 | 721 | for (const auto &Fix : Diag->Fixes) { |
706 | 722 | if (auto Rename = tryConvertToRename(Diag, Fix)) { |
707 | 723 | Result.Renames.emplace_back(std::move(*Rename)); |
708 | 724 | } else { |
709 | 725 | Result.QuickFixes.push_back({DiagRef, Fix}); |
710 | 726 | } |
711 | 727 | } |
| 728 | + |
| 729 | + if (auto Fix = tryAddClangTidySuppression(Diag)) { |
| 730 | + Result.QuickFixes.push_back({DiagRef, std::move(*Fix)}); |
| 731 | + } |
| 732 | + } |
712 | 733 | } |
713 | 734 | } |
714 | 735 |
|
|
0 commit comments