[PATCH] D74036: [clangd] don't rename on protobuf symbols.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 6 06:44:52 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd6da8a1d9453: [clangd] don't rename on protobuf symbols. (authored by hokein).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74036/new/
https://reviews.llvm.org/D74036
Files:
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -630,6 +630,21 @@
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");
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -96,7 +96,13 @@
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"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74036.242894.patch
Type: text/x-patch
Size: 1772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200206/5dc19273/attachment.bin>
More information about the cfe-commits
mailing list