File tree Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -159,13 +159,17 @@ llvm::DenseSet<const NamedDecl *> locateDeclAt(ParsedAST &AST,
159
159
return Result;
160
160
}
161
161
162
- // By default, we exclude C++ standard symbols and protobuf symbols as rename
163
- // these symbols would change system/generated files which are unlikely to be
164
- // modified .
162
+ // By default, we exclude symbols from system headers and protobuf symbols as
163
+ // renaming these symbols would change system/generated files which are unlikely
164
+ // to be good candidates for modification .
165
165
bool isExcluded (const NamedDecl &RenameDecl) {
166
- if ( isProtoFile ( RenameDecl.getLocation (),
167
- RenameDecl. getASTContext (). getSourceManager ()))
166
+ const auto &SM = RenameDecl.getASTContext (). getSourceManager ();
167
+ if (SM. isInSystemHeader (RenameDecl. getLocation ()))
168
168
return true ;
169
+ if (isProtoFile (RenameDecl.getLocation (), SM))
170
+ return true ;
171
+ // FIXME: Remove this std symbol list, as they should be covered by the
172
+ // above isInSystemHeader check.
169
173
static const auto *StdSymbols = new llvm::DenseSet<llvm::StringRef>({
170
174
#define SYMBOL (Name, NameSpace, Header ) {#NameSpace #Name},
171
175
#include " StdSymbolMap.inc"
Original file line number Diff line number Diff line change @@ -1198,6 +1198,29 @@ TEST(RenameTest, MainFileReferencesOnly) {
1198
1198
expectedResult (Code, NewName));
1199
1199
}
1200
1200
1201
+ TEST (RenameTest, NoRenameOnSymbolsFromSystemHeaders) {
1202
+ // filter out references not from main file.
1203
+ llvm::StringRef Test =
1204
+ R"cpp(
1205
+ #include <system>
1206
+ SystemSym^bol abc;
1207
+ )cpp" ;
1208
+
1209
+ Annotations Code (Test);
1210
+ auto TU = TestTU::withCode (Code.code ());
1211
+ TU.AdditionalFiles [" system" ] = R"cpp(
1212
+ class SystemSymbol {};
1213
+ )cpp" ;
1214
+ TU.ExtraArgs = {" -isystem" , testRoot ()};
1215
+ auto AST = TU.build ();
1216
+ llvm::StringRef NewName = " abcde" ;
1217
+
1218
+ auto Results = rename ({Code.point (), NewName, AST, testPath (TU.Filename )});
1219
+ EXPECT_FALSE (Results) << " expected rename returned an error: " << Code.code ();
1220
+ auto ActualMessage = llvm::toString (Results.takeError ());
1221
+ EXPECT_THAT (ActualMessage, testing::HasSubstr (" not a supported kind" ));
1222
+ }
1223
+
1201
1224
TEST (RenameTest, ProtobufSymbolIsExcluded) {
1202
1225
Annotations Code (" Prot^obuf buf;" );
1203
1226
auto TU = TestTU::withCode (Code.code ());
You can’t perform that action at this time.
0 commit comments