@@ -2,13 +2,17 @@ import type tslib from 'typescript/lib/tsserverlibrary'
22import { findChildContainingPosition , findChildContainingPositionMaxDepth } from './utils'
33
44export const isGoodPositionBuiltinMethodCompletion = ( ts : typeof tslib , sourceFile : tslib . SourceFile , position : number ) => {
5- const importClauseCandidate = findChildContainingPositionMaxDepth ( ts , sourceFile , position , 2 )
6- console . log ( sourceFile . getFullText ( ) . slice ( 0 , position ) )
7- if ( importClauseCandidate ?. kind === 266 ) return false
8- const currentNode = findChildContainingPosition ( ts , sourceFile , position )
9- // const obj = { method() {}, arrow: () => {} }
10- // type A = typeof obj["|"]
11- if ( currentNode && ts . isStringLiteralLike ( currentNode ) ) return false
5+ const importClauseCandidate = findChildContainingPositionMaxDepth ( ts , sourceFile , position , 3 )
6+ if ( importClauseCandidate && ts . isImportClause ( importClauseCandidate ) ) return false
7+ let currentNode = findChildContainingPosition ( ts , sourceFile , position )
8+ if ( currentNode ) {
9+ // const obj = { method() {}, arrow: () => {} }
10+ // type A = typeof obj["|"]
11+ if ( ts . isStringLiteralLike ( currentNode ) ) return false
12+ if ( ts . isIdentifier ( currentNode ) ) currentNode = currentNode . parent
13+ if ( ts . isShorthandPropertyAssignment ( currentNode ) ) currentNode = currentNode . parent
14+ if ( ts . isObjectBindingPattern ( currentNode ) || ts . isObjectLiteralExpression ( currentNode ) ) return false
15+ }
1216 return true
1317}
1418
0 commit comments