Skip to content

Commit 75313cf

Browse files
committed
[IDE] make replace.bodies.with.fatalError an internal refactoring.
This shouldn't be exposed to general users.
1 parent fac1a52 commit 75313cf

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

include/swift/IDE/RefactoringKinds.def

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#define RANGE_REFACTORING(KIND, NAME, ID) SEMANTIC_REFACTORING(KIND, NAME, ID)
1111
#endif
1212

13+
#ifndef INTERNAL_RANGE_REFACTORING
14+
#define INTERNAL_RANGE_REFACTORING(KIND, NAME, ID) RANGE_REFACTORING(KIND, NAME, ID)
15+
#endif
16+
1317
#ifndef CURSOR_REFACTORING
1418
#define CURSOR_REFACTORING(KIND, NAME, ID) SEMANTIC_REFACTORING(KIND, NAME, ID)
1519
#endif
@@ -60,9 +64,14 @@ RANGE_REFACTORING(ExpandTernaryExpr, "Expand Ternary Expression", expand.ternary
6064

6165
RANGE_REFACTORING(ConvertToTernaryExpr, "Convert To Ternary Expression", convert.ternary.expr)
6266

63-
RANGE_REFACTORING(ReplaceBodiesWithFatalError, "Replace Function Bodies With 'fatalError()'", replace.bodies.with.fatalError)
67+
// These internal refactorings are designed to be helpful for working on
68+
// the compiler/standard library, etc., but are likely to be just confusing and
69+
// noise for general development.
70+
71+
INTERNAL_RANGE_REFACTORING(ReplaceBodiesWithFatalError, "Replace Function Bodies With 'fatalError()'", replace.bodies.with.fatalError)
6472

6573
#undef CURSOR_REFACTORING
74+
#undef INTERNAL_RANGE_REFACTORING
6675
#undef RANGE_REFACTORING
6776
#undef SEMANTIC_REFACTORING
6877
#undef REFACTORING

lib/IDE/Refactoring.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,9 +3099,14 @@ collectAvailableRefactorings(SourceFile *SF, RangeConfig Range,
30993099
Range.getEnd(SF->getASTContext().SourceMgr));
31003100
ResolvedRangeInfo Result = Resolver.resolve();
31013101

3102+
bool enableInternalRefactoring = getenv("SWIFT_ENABLE_INTERNAL_REFACTORING_ACTIONS");
3103+
31023104
#define RANGE_REFACTORING(KIND, NAME, ID) \
31033105
if (RefactoringAction##KIND::isApplicable(Result, DiagEngine)) \
31043106
Scratch.push_back(RefactoringKind::KIND);
3107+
#define INTERNAL_RANGE_REFACTORING(KIND, NAME, ID) \
3108+
if (enableInternalRefactoring) \
3109+
RANGE_REFACTORING(KIND, NAME, ID)
31053110
#include "swift/IDE/RefactoringKinds.def"
31063111

31073112
RangeStartMayNeedRename = rangeStartMayNeedRename(Result);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var bar: Int {
2+
return 0
3+
}
4+
// CHECK-NO-ENV-LABEL: Action begins
5+
// CHECK-NO-ENV-NEXT: Action ends
6+
7+
// CHECK-ENV-LABEL: Action begins
8+
// CHECK-ENV-NEXT: Replace Function Bodies With 'fatalError()'
9+
// CHECK-ENV-NEXT: Action ends
10+
11+
// replace.bodies.with.fatalError/-replace-bodies-with-fatalError should only be
12+
// found if the appropriate environment variable is set.
13+
14+
// RUN: %refactor -actions -source-filename %s -pos=1:1 -end-pos=3:2 | %FileCheck %s -check-prefix CHECK-NO-ENV
15+
16+
// RUN: env SWIFT_ENABLE_INTERNAL_REFACTORING_ACTIONS=1 %refactor -actions -source-filename %s -pos=1:1 -end-pos=3:2 | %FileCheck %s -check-prefix CHECK-ENV

0 commit comments

Comments
 (0)