@@ -32,7 +32,7 @@ namespace ts.codefix {
32
32
errorCodes,
33
33
getCodeActions : context => {
34
34
const { sourceFile, errorCode, span, cancellationToken, program } = context ;
35
- const expression = getFixableErrorSpanExpression ( sourceFile , errorCode , span , cancellationToken , program ) ;
35
+ const expression = getAwaitErrorSpanExpression ( sourceFile , errorCode , span , cancellationToken , program ) ;
36
36
if ( ! expression ) {
37
37
return ;
38
38
}
@@ -48,7 +48,7 @@ namespace ts.codefix {
48
48
const checker = context . program . getTypeChecker ( ) ;
49
49
const fixedDeclarations = new Set < number > ( ) ;
50
50
return codeFixAll ( context , errorCodes , ( t , diagnostic ) => {
51
- const expression = getFixableErrorSpanExpression ( sourceFile , diagnostic . code , diagnostic , cancellationToken , program ) ;
51
+ const expression = getAwaitErrorSpanExpression ( sourceFile , diagnostic . code , diagnostic , cancellationToken , program ) ;
52
52
if ( ! expression ) {
53
53
return ;
54
54
}
@@ -59,6 +59,13 @@ namespace ts.codefix {
59
59
} ,
60
60
} ) ;
61
61
62
+ function getAwaitErrorSpanExpression ( sourceFile : SourceFile , errorCode : number , span : TextSpan , cancellationToken : CancellationToken , program : Program ) {
63
+ const expression = getFixableErrorSpanExpression ( sourceFile , span )
64
+ return expression
65
+ && isMissingAwaitError ( sourceFile , errorCode , span , cancellationToken , program )
66
+ && isInsideAwaitableBody ( expression ) ? expression : undefined ;
67
+ }
68
+
62
69
function getDeclarationSiteFix ( context : CodeFixContext | CodeFixAllContext , expression : Expression , errorCode : number , checker : TypeChecker , trackChanges : ContextualTrackChangesFunction , fixedDeclarations ?: Set < number > ) {
63
70
const { sourceFile, program, cancellationToken } = context ;
64
71
const awaitableInitializers = findAwaitableInitializers ( expression , sourceFile , cancellationToken , program , checker ) ;
@@ -95,23 +102,6 @@ namespace ts.codefix {
95
102
some ( relatedInformation , related => related . code === Diagnostics . Did_you_forget_to_use_await . code ) ) ;
96
103
}
97
104
98
- function getFixableErrorSpanExpression ( sourceFile : SourceFile , errorCode : number , span : TextSpan , cancellationToken : CancellationToken , program : Program ) : Expression | undefined {
99
- const token = getTokenAtPosition ( sourceFile , span . start ) ;
100
- // Checker has already done work to determine that await might be possible, and has attached
101
- // related info to the node, so start by finding the expression that exactly matches up
102
- // with the diagnostic range.
103
- const expression = findAncestor ( token , node => {
104
- if ( node . getStart ( sourceFile ) < span . start || node . getEnd ( ) > textSpanEnd ( span ) ) {
105
- return "quit" ;
106
- }
107
- return isExpression ( node ) && textSpansEqual ( span , createTextSpanFromNode ( node , sourceFile ) ) ;
108
- } ) as Expression | undefined ;
109
-
110
- return expression
111
- && isMissingAwaitError ( sourceFile , errorCode , span , cancellationToken , program )
112
- && isInsideAwaitableBody ( expression ) ? expression : undefined ;
113
- }
114
-
115
105
interface AwaitableInitializer {
116
106
expression : Expression ;
117
107
declarationSymbol : Symbol ;
0 commit comments