Skip to content

Commit 0c18e95

Browse files
committed
Fixing one error
1 parent 64a22b3 commit 0c18e95

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "llvm/ADT/STLExtras.h"
4545
#include "llvm/ADT/StringRef.h"
4646
#include "llvm/Support/Error.h"
47+
#include "llvm/Support/Format.h"
4748
#include "llvm/Support/Path.h"
4849
#include "llvm/Support/raw_ostream.h"
4950
#include <algorithm>
@@ -672,6 +673,21 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) {
672673
return std::nullopt;
673674
}
674675

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+
675691
} // namespace
676692

677693
void ClangdServer::codeAction(const CodeActionInputs &Params,
@@ -701,14 +717,19 @@ void ClangdServer::codeAction(const CodeActionInputs &Params,
701717
return nullptr;
702718
};
703719
for (const auto &DiagRef : Params.Diagnostics) {
704-
if (const auto *Diag = FindMatchedDiag(DiagRef))
720+
if (const auto *Diag = FindMatchedDiag(DiagRef)) {
705721
for (const auto &Fix : Diag->Fixes) {
706722
if (auto Rename = tryConvertToRename(Diag, Fix)) {
707723
Result.Renames.emplace_back(std::move(*Rename));
708724
} else {
709725
Result.QuickFixes.push_back({DiagRef, Fix});
710726
}
711727
}
728+
729+
if (auto Fix = tryAddClangTidySuppression(Diag)) {
730+
Result.QuickFixes.push_back({DiagRef, std::move(*Fix)});
731+
}
732+
}
712733
}
713734
}
714735

0 commit comments

Comments
 (0)