Skip to content

Commit 5801a14

Browse files
committed
better deal with converting fixes to rename while avoiding NoLint fixes
1 parent 2e7f6ea commit 5801a14

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "Format.h"
1616
#include "HeaderSourceSwitch.h"
1717
#include "InlayHints.h"
18+
#include "NoLintFixes.h"
1819
#include "ParsedAST.h"
1920
#include "Preamble.h"
2021
#include "Protocol.h"
@@ -62,8 +63,8 @@ namespace clangd {
6263
namespace {
6364

6465
// Tracks number of times a tweak has been offered.
65-
static constexpr trace::Metric TweakAvailable(
66-
"tweak_available", trace::Metric::Counter, "tweak_id");
66+
static constexpr trace::Metric
67+
TweakAvailable("tweak_available", trace::Metric::Counter, "tweak_id");
6768

6869
// Update the FileIndex with new ASTs and plumb the diagnostics responses.
6970
struct UpdateIndexCallbacks : public ParsingCallbacks {
@@ -661,7 +662,7 @@ tryConvertToRename(const Diag *Diag, const Fix &Fix) {
661662
bool IsClangTidyRename = Diag->Source == Diag::ClangTidy &&
662663
Diag->Name == "readability-identifier-naming" &&
663664
!Fix.Edits.empty();
664-
if (IsClangTidyRename && Diag->InsideMainFile) {
665+
if (IsClangTidyRename && !isNoLintFixes(Fix) && Diag->InsideMainFile) {
665666
ClangdServer::CodeActionResult::Rename R;
666667
R.NewName = Fix.Edits.front().newText;
667668
R.FixMessage = Fix.Message;
@@ -701,21 +702,14 @@ void ClangdServer::codeAction(const CodeActionInputs &Params,
701702
return nullptr;
702703
};
703704
for (const auto &DiagRef : Params.Diagnostics) {
704-
if (const auto *Diag = FindMatchedDiag(DiagRef)) {
705-
auto It = Diag->Fixes.begin();
706-
if (It != Diag->Fixes.end()) {
707-
if (auto Rename = tryConvertToRename(Diag, *It)) {
708-
// Only try to convert the first Fix to rename as subsequent Fixes
709-
// might be "ignore [readability-identifier-naming] for this
710-
// line".
705+
if (const auto *Diag = FindMatchedDiag(DiagRef))
706+
for (const auto &Fix : Diag->Fixes) {
707+
if (auto Rename = tryConvertToRename(Diag, Fix)) {
711708
Result.Renames.emplace_back(std::move(*Rename));
712-
It++;
709+
} else {
710+
Result.QuickFixes.push_back({DiagRef, Fix});
713711
}
714712
}
715-
for (; It != Diag->Fixes.end(); It++) {
716-
Result.QuickFixes.push_back({DiagRef, *It});
717-
}
718-
}
719713
}
720714
}
721715

clang-tools-extra/clangd/ParsedAST.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,16 +660,17 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
660660
&CTContext](const Diag &Diag,
661661
const clang::Diagnostic &Info) {
662662
auto Fixes = std::vector<Fix>();
663-
auto IncludeFixes = FixIncludes->fix(Diag.Severity, Info);
664663

664+
auto IncludeFixes = FixIncludes->fix(Diag.Severity, Info);
665665
// Ensures that if clang later introduces its own fix-it for includes it
666666
// will get on our radar.
667667
assert((IncludeFixes.empty() || Info.getNumFixItHints() == 0) &&
668668
"Include-fixer replaced a note with clang fix-its attached!");
669-
670669
Fixes.insert(Fixes.end(), IncludeFixes.begin(), IncludeFixes.end());
670+
671671
auto NoLintFixes = noLintFixes(*CTContext, Info, Diag);
672672
Fixes.insert(Fixes.end(), NoLintFixes.begin(), NoLintFixes.end());
673+
673674
return Fixes;
674675
});
675676
Clang->setExternalSemaSource(FixIncludes->unresolvedNameRecorder());

0 commit comments

Comments
 (0)