Skip to content

[SourceKit] Refactor collection of available refactorings #64663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 14 additions & 26 deletions include/swift/Refactoring/Refactoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct RenameRangeDetail {
Optional<unsigned> Index;
};

enum class RenameAvailableKind {
enum class RefactorAvailableKind {
Available,
Unavailable_system_symbol,
Unavailable_has_no_location,
Expand All @@ -81,14 +81,14 @@ enum class RenameAvailableKind {
Unavailable_decl_from_clang,
};

struct RenameAvailabilityInfo {
struct RefactorAvailabilityInfo {
RefactoringKind Kind;
RenameAvailableKind AvailableKind;
RenameAvailabilityInfo(RefactoringKind Kind,
RenameAvailableKind AvailableKind)
RefactorAvailableKind AvailableKind;
RefactorAvailabilityInfo(RefactoringKind Kind,
RefactorAvailableKind AvailableKind)
: Kind(Kind), AvailableKind(AvailableKind) {}
RenameAvailabilityInfo(RefactoringKind Kind)
: RenameAvailabilityInfo(Kind, RenameAvailableKind::Available) {}
RefactorAvailabilityInfo(RefactoringKind Kind)
: RefactorAvailabilityInfo(Kind, RefactorAvailableKind::Available) {}
};

class FindRenameRangesConsumer {
Expand All @@ -112,7 +112,7 @@ class FindRenameRangesAnnotatingConsumer : public FindRenameRangesConsumer {

StringRef getDescriptiveRefactoringKindName(RefactoringKind Kind);

StringRef getDescriptiveRenameUnavailableReason(RenameAvailableKind Kind);
StringRef getDescriptiveRenameUnavailableReason(RefactorAvailableKind Kind);

bool refactorSwiftModule(ModuleDecl *M, RefactoringOptions Opts,
SourceEditConsumer &EditConsumer,
Expand All @@ -131,25 +131,13 @@ int findLocalRenameRanges(SourceFile *SF, RangeConfig Range,
FindRenameRangesConsumer &RenameConsumer,
DiagnosticConsumer &DiagConsumer);

void collectAvailableRefactorings(
SourceFile *SF, RangeConfig Range, bool &RangeStartMayNeedRename,
llvm::SmallVectorImpl<RefactoringKind> &Kinds,
llvm::ArrayRef<DiagnosticConsumer *> DiagConsumers);

void collectAvailableRefactorings(ResolvedCursorInfoPtr CursorInfo,
llvm::SmallVectorImpl<RefactoringKind> &Kinds,
bool ExcludeRename);

/// Stores information about the reference that rename availability is being
/// queried on.
struct RenameRefInfo {
SourceFile *SF; ///< The source file containing the reference.
SourceLoc Loc; ///< The reference's source location.
bool IsArgLabel; ///< Whether Loc is on an arg label, rather than base name.
};
SmallVector<RefactorAvailabilityInfo, 0>
collectRefactorings(SourceFile *SF, RangeConfig Range,
bool &RangeStartMayNeedRename,
llvm::ArrayRef<DiagnosticConsumer *> DiagConsumers);

Optional<RenameAvailabilityInfo>
renameAvailabilityInfo(const ValueDecl *VD, Optional<RenameRefInfo> RefInfo);
SmallVector<RefactorAvailabilityInfo, 0>
collectRefactorings(ResolvedCursorInfoPtr CursorInfo, bool ExcludeRename);

} // namespace ide
} // namespace swift
Expand Down
Loading