Skip to content

Commit 1513649

Browse files
authored
Don't add redundant await in completions (#52677)
1 parent d79eb02 commit 1513649

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/services/completions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ import {
117117
isAbstractConstructorSymbol,
118118
isArrowFunction,
119119
isAssertionExpression,
120+
isAwaitExpression,
120121
isBigIntLiteral,
121122
isBinaryExpression,
122123
isBindingElement,
@@ -1319,7 +1320,9 @@ function createCompletionEntry(
13191320

13201321
awaitText += `(await ${propertyAccessToConvert.expression.getText()})`;
13211322
insertText = needsConvertPropertyAccess ? `${awaitText}${insertText}` : `${awaitText}${insertQuestionDot ? "?." : "."}${insertText}`;
1322-
replacementSpan = createTextSpanFromBounds(propertyAccessToConvert.getStart(sourceFile), propertyAccessToConvert.end);
1323+
const isInAwaitExpression = tryCast(propertyAccessToConvert.parent, isAwaitExpression);
1324+
const wrapNode = isInAwaitExpression ? propertyAccessToConvert.parent : propertyAccessToConvert.expression;
1325+
replacementSpan = createTextSpanFromBounds(wrapNode.getStart(sourceFile), propertyAccessToConvert.end);
13231326
}
13241327

13251328
if (originIsResolvedExport(origin)) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
//// interface Foo { foo: string }
4+
//// async function foo(x: (a: number) => Promise<Foo>) {
5+
//// [|await x(1)./*1*/|]
6+
//// ;([|await x(1)./*2*/|])
7+
//// ;(await ([|x(1)./*3*/|]))
8+
//// }
9+
10+
for (const marker of [1, 2, 3]) {
11+
verify.completions({
12+
marker: marker.toString(),
13+
includes: [
14+
"then",
15+
{ name: "foo", insertText: '(await x(1)).foo', replacementSpan: test.ranges()[marker - 1] },
16+
],
17+
preferences: {
18+
includeInsertTextCompletions: true,
19+
},
20+
});
21+
}

0 commit comments

Comments
 (0)