[clang-tools-extra] d6da8a1 - [clangd] don't rename on protobuf symbols.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 6 06:40:26 PST 2020
Author: Haojian Wu
Date: 2020-02-06T15:40:14+01:00
New Revision: d6da8a1d945361327b8da79195dbfccc2e533e87
URL: https://github.com/llvm/llvm-project/commit/d6da8a1d945361327b8da79195dbfccc2e533e87
DIFF: https://github.com/llvm/llvm-project/commit/d6da8a1d945361327b8da79195dbfccc2e533e87.diff
LOG: [clangd] don't rename on protobuf symbols.
Reviewers: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D74036
Added:
Modified:
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/refactor/Rename.cpp b/clang-tools-extra/clangd/refactor/Rename.cpp
index 31fabc787625..44ebdbce628d 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -96,7 +96,13 @@ llvm::DenseSet<const NamedDecl *> locateDeclAt(ParsedAST &AST,
return Result;
}
+// By default, we blacklist C++ standard symbols and protobuf symbols as rename
+// these symbols would change system/generated files which are unlikely to be
+// modified.
bool isBlacklisted(const NamedDecl &RenameDecl) {
+ if (isProtoFile(RenameDecl.getLocation(),
+ RenameDecl.getASTContext().getSourceManager()))
+ return true;
static const auto *StdSymbols = new llvm::DenseSet<llvm::StringRef>({
#define SYMBOL(Name, NameSpace, Header) {#NameSpace #Name},
#include "StdSymbolMap.inc"
diff --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp b/clang-tools-extra/clangd/unittests/RenameTests.cpp
index 2aaf45eb7563..a9446865e664 100644
--- a/clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -630,6 +630,21 @@ TEST(RenameTest, MainFileReferencesOnly) {
expectedResult(Code, NewName));
}
+TEST(RenameTest, ProtobufSymbolIsBlacklisted) {
+ Annotations Code("Prot^obuf buf;");
+ auto TU = TestTU::withCode(Code.code());
+ TU.HeaderCode =
+ R"cpp(// Generated by the protocol buffer compiler. DO NOT EDIT!
+ class Protobuf {};
+ )cpp";
+ TU.HeaderFilename = "protobuf.pb.h";
+ auto AST = TU.build();
+ auto Results = rename({Code.point(), "newName", AST, testPath(TU.Filename)});
+ EXPECT_FALSE(Results);
+ EXPECT_THAT(llvm::toString(Results.takeError()),
+ testing::HasSubstr("not a supported kind"));
+}
+
TEST(CrossFileRenameTests, DirtyBuffer) {
Annotations FooCode("class [[Foo]] {};");
std::string FooPath = testPath("foo.cc");
More information about the cfe-commits
mailing list