sammccall created this revision. sammccall added a reviewer: kadircet. Herald added a subscriber: arphaman. Herald added a project: All. sammccall requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
This feature relies on Relations in the index being complete. An out-of-tree index implementation is missing some override relations, so such renames end up breaking the code. We plan to fix it, but this flag is a cheap band-aid for now. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D133440 Files: clang-tools-extra/clangd/refactor/Rename.cpp clang-tools-extra/clangd/refactor/Rename.h Index: clang-tools-extra/clangd/refactor/Rename.h =================================================================== --- clang-tools-extra/clangd/refactor/Rename.h +++ clang-tools-extra/clangd/refactor/Rename.h @@ -26,6 +26,8 @@ size_t LimitFiles = 50; /// If true, format the rename edits, only meaningful in ClangdServer layer. bool WantFormat = false; + /// Allow rename of virtual method hierarchies. + bool RenameVirtual = true; }; struct RenameInputs { Index: clang-tools-extra/clangd/refactor/Rename.cpp =================================================================== --- clang-tools-extra/clangd/refactor/Rename.cpp +++ clang-tools-extra/clangd/refactor/Rename.cpp @@ -181,7 +181,8 @@ llvm::Optional<ReasonToReject> renameable(const NamedDecl &RenameDecl, StringRef MainFilePath, - const SymbolIndex *Index) { + const SymbolIndex *Index, + const RenameOptions& Opts) { trace::Span Tracer("Renameable"); // Filter out symbols that are unsupported in both rename modes. if (llvm::isa<NamespaceDecl>(&RenameDecl)) @@ -213,6 +214,12 @@ RenameDecl, RenameDecl.getASTContext(), SymbolCollector::Options(), IsMainFileOnly)) return ReasonToReject::NonIndexable; + if (!Opts.RenameVirtual) { + if (const auto *S = llvm::dyn_cast<CXXMethodDecl>(&RenameDecl)) { + if (S->isVirtual()) + return ReasonToReject::UnsupportedSymbol; + } + } return None; }
Index: clang-tools-extra/clangd/refactor/Rename.h =================================================================== --- clang-tools-extra/clangd/refactor/Rename.h +++ clang-tools-extra/clangd/refactor/Rename.h @@ -26,6 +26,8 @@ size_t LimitFiles = 50; /// If true, format the rename edits, only meaningful in ClangdServer layer. bool WantFormat = false; + /// Allow rename of virtual method hierarchies. + bool RenameVirtual = true; }; struct RenameInputs { Index: clang-tools-extra/clangd/refactor/Rename.cpp =================================================================== --- clang-tools-extra/clangd/refactor/Rename.cpp +++ clang-tools-extra/clangd/refactor/Rename.cpp @@ -181,7 +181,8 @@ llvm::Optional<ReasonToReject> renameable(const NamedDecl &RenameDecl, StringRef MainFilePath, - const SymbolIndex *Index) { + const SymbolIndex *Index, + const RenameOptions& Opts) { trace::Span Tracer("Renameable"); // Filter out symbols that are unsupported in both rename modes. if (llvm::isa<NamespaceDecl>(&RenameDecl)) @@ -213,6 +214,12 @@ RenameDecl, RenameDecl.getASTContext(), SymbolCollector::Options(), IsMainFileOnly)) return ReasonToReject::NonIndexable; + if (!Opts.RenameVirtual) { + if (const auto *S = llvm::dyn_cast<CXXMethodDecl>(&RenameDecl)) { + if (S->isVirtual()) + return ReasonToReject::UnsupportedSymbol; + } + } return None; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits