Skip to content

Commit

Permalink
[IDE] make replace.bodies.with.fatalError an internal refactoring.
Browse files Browse the repository at this point in the history
This shouldn't be exposed to general users.
  • Loading branch information
huonw committed Apr 16, 2018
1 parent fac1a52 commit 75313cf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
11 changes: 10 additions & 1 deletion include/swift/IDE/RefactoringKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#define RANGE_REFACTORING(KIND, NAME, ID) SEMANTIC_REFACTORING(KIND, NAME, ID)
#endif

#ifndef INTERNAL_RANGE_REFACTORING
#define INTERNAL_RANGE_REFACTORING(KIND, NAME, ID) RANGE_REFACTORING(KIND, NAME, ID)
#endif

#ifndef CURSOR_REFACTORING
#define CURSOR_REFACTORING(KIND, NAME, ID) SEMANTIC_REFACTORING(KIND, NAME, ID)
#endif
Expand Down Expand Up @@ -60,9 +64,14 @@ RANGE_REFACTORING(ExpandTernaryExpr, "Expand Ternary Expression", expand.ternary

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

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

INTERNAL_RANGE_REFACTORING(ReplaceBodiesWithFatalError, "Replace Function Bodies With 'fatalError()'", replace.bodies.with.fatalError)

#undef CURSOR_REFACTORING
#undef INTERNAL_RANGE_REFACTORING
#undef RANGE_REFACTORING
#undef SEMANTIC_REFACTORING
#undef REFACTORING
5 changes: 5 additions & 0 deletions lib/IDE/Refactoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3099,9 +3099,14 @@ collectAvailableRefactorings(SourceFile *SF, RangeConfig Range,
Range.getEnd(SF->getASTContext().SourceMgr));
ResolvedRangeInfo Result = Resolver.resolve();

bool enableInternalRefactoring = getenv("SWIFT_ENABLE_INTERNAL_REFACTORING_ACTIONS");

#define RANGE_REFACTORING(KIND, NAME, ID) \
if (RefactoringAction##KIND::isApplicable(Result, DiagEngine)) \
Scratch.push_back(RefactoringKind::KIND);
#define INTERNAL_RANGE_REFACTORING(KIND, NAME, ID) \
if (enableInternalRefactoring) \
RANGE_REFACTORING(KIND, NAME, ID)
#include "swift/IDE/RefactoringKinds.def"

RangeStartMayNeedRename = rangeStartMayNeedRename(Result);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var bar: Int {
return 0
}
// CHECK-NO-ENV-LABEL: Action begins
// CHECK-NO-ENV-NEXT: Action ends

// CHECK-ENV-LABEL: Action begins
// CHECK-ENV-NEXT: Replace Function Bodies With 'fatalError()'
// CHECK-ENV-NEXT: Action ends

// replace.bodies.with.fatalError/-replace-bodies-with-fatalError should only be
// found if the appropriate environment variable is set.

// RUN: %refactor -actions -source-filename %s -pos=1:1 -end-pos=3:2 | %FileCheck %s -check-prefix CHECK-NO-ENV

// 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 comments on commit 75313cf

Please sign in to comment.