[clang-tools-extra] [clangd] forward clang-tidy's readability-identifier-naming fix to textDocument/rename (PR #78454)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 10 20:44:37 PST 2024


================
@@ -648,6 +649,27 @@ tweakSelection(const Range &Sel, const InputsAndAST &AST,
   return std::move(Result);
 }
 
+// Some fixes may perform local renaming, we want to convert those to clangd
+// rename commands, such that we can leverage the index for more accurate
+// results.
+std::optional<ClangdServer::CodeActionResult::Rename>
+TryConvertToRename(const Diag *Diag, const ClangdServer::DiagRef &DR,
+                   const Fix &Fix) {
+  bool IsClangTidyRename = Diag->Source == Diag::ClangTidy &&
+                           Diag->Name == "readability-identifier-naming" &&
+                           !Fix.Edits.empty();
+  if (IsClangTidyRename) {
----------------
HighCommander4 wrote:

For good measure, we should check `Diag->InsideMainFile` as well. If that's false, then `Diag->Range` (and thus `DR.Range`) may not be a location in the main file, which would be a problem (since we propagate `DR.Range.start` into `RenameParams::position`, where it then gets interpreted as a position in the main file).

https://github.com/llvm/llvm-project/pull/78454


More information about the cfe-commits mailing list