Add Inline temp variable code action#2547
Closed
william-laverty wants to merge 1 commit intoswiftlang:mainfrom
Closed
Add Inline temp variable code action#2547william-laverty wants to merge 1 commit intoswiftlang:mainfrom
william-laverty wants to merge 1 commit intoswiftlang:mainfrom
Conversation
Add a syntactic code action that inlines a temporary variable by replacing all references to it with its initializer expression, then removing the declaration. The action is offered when the cursor is on a let/var declaration with a single binding that has an initializer, no type annotation, and the variable is referenced in subsequent statements. Smart parenthesization is applied when the initializer is a binary expression, ternary, try/await, or cast to avoid changing precedence. The action is not offered when the variable is unused, used as an inout argument, or is reassigned. Resolves #2507
Member
|
@william-laverty I appreciate your enthusiasm but you now have 7 open PRs. I would encourage you to leave it at that for now so that you have the time and energy to address review feedback on those. |
Member
|
Here, again, we already have a PR that implements this. #2529 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add a syntactic code action that inlines a temporary variable by replacing all references to it with its initializer expression, then removing the declaration.
Changes
InlineTempVariablecode action inSources/SwiftLanguageService/CodeActions/allSyntaxCodeActionsBehavior
The action is offered when the cursor is on a
let/vardeclaration that:inoutargument or reassignedSmart parenthesization wraps the inlined expression when it's a binary operation, ternary,
try/await, or cast expression to preserve precedence.Before:
After:
Resolves #2507