Skip to content

Only provide suggestion for outermost async fix #29214

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 3 commits into from
Jan 1, 2019

Conversation

uniqueiniquity
Copy link
Contributor

Fixes #27488.

Currently, if getCombinedCodeFix is triggered in a file with nested functions that can be converted to async functions, the call fails since our text change mechanism cannot handle overlapping changes.
This PR makes it so that only the outermost suggestion diagnostic for nested convertible functions is provided so that such a conflict is not encountered. Note that if getCodeActions is triggered at the location of an inner convertible function, it will return the action, since we do not inspect the surrounding context of a given function.

This PR also removes unnecessary trailing spaces from several tests.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some naming, spelling and minimalism questions.

@@ -167,16 +174,24 @@ namespace ts {
}

// should be kept up to date with getTransformationBody in convertToAsyncFunction.ts
function isFixablePromiseArgument(arg: Expression): boolean {
function isFixablePromiseArgument(arg: Expression, checker: TypeChecker): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this only called on nested functions? Or is visitedNestedConvertibleFunctions a misnomer and should just be visitedConvertibleFunctions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's only called on arguments of promise handlers (e.g., then or catch).

@uniqueiniquity uniqueiniquity merged commit 799656a into microsoft:master Jan 1, 2019
@uniqueiniquity uniqueiniquity deleted the nestedAsyncCodeFix branch January 1, 2019 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants