Skip to content

Commit 7aef619

Browse files
committed
fix: prevent expanding of builtin method snippets in callback destructure when indentifier
1 parent a7d67f1 commit 7aef619

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

typescript/src/completions/isGoodPositionMethodCompletion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const isGoodPositionBuiltinMethodCompletion = (ts: typeof tslib, sourceFi
1313
if (ts.isStringLiteralLike(currentNode)) return false
1414
if (ts.isIdentifier(currentNode)) currentNode = currentNode.parent
1515
if (ts.isJsxSelfClosingElement(currentNode) || ts.isJsxOpeningElement(currentNode)) return false
16-
if (ts.isShorthandPropertyAssignment(currentNode)) currentNode = currentNode.parent
16+
if (ts.isBindingElement(currentNode) || ts.isShorthandPropertyAssignment(currentNode)) currentNode = currentNode.parent
1717
if (ts.isObjectBindingPattern(currentNode) || ts.isObjectLiteralExpression(currentNode)) return false
1818
if (ts.isJsxAttributes(currentNode) || ts.isJsxAttribute(currentNode)) return false
1919
if (c('disableMethodSnippets.jsxAttributes') && ts.isJsxExpression(currentNode)) return false

typescript/test/completions.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ test('Banned positions for all method snippets', () => {
101101
import {/*|*/} from 'test'
102102
const obj = { m$1e$2thod() {}, arrow: () => {} }
103103
type A = typeof obj["/*|*/"];
104+
a(({ a/*|*/ }) => {})
104105
const test = () => ({ method() {} })
105106
const {/*|*/} = test()
106107
const {something, met/*|*/} = test()
@@ -119,7 +120,7 @@ test('Banned positions for all method snippets', () => {
119120
;<Test a/*|*/ />
120121
`)
121122
for (const [i, pos] of cursorPositions.entries()) {
122-
const result = isGoodPositionBuiltinMethodCompletion(ts, getSourceFile(), pos, defaultConfigFunc)
123+
const result = isGoodPositionBuiltinMethodCompletion(ts, getSourceFile(), pos - 1, defaultConfigFunc)
123124
expect(result, i.toString()).toBeFalsy()
124125
}
125126
const insertTextEscaping = getCompletionsAtPosition(cursorPositions[1]!)!.entries[1]?.insertText!

0 commit comments

Comments
 (0)