@@ -8,11 +8,24 @@ export default (entries: ts.CompletionEntry[], node: ts.Node | undefined, source
8
8
// const type = typeChecker.getTypeAtLocation(node.parent)
9
9
// const callSignatures = type.getCallSignatures()
10
10
// }
11
- if ( ts . isIdentifier ( node ) ) node = node . parent
12
- if ( ! ts . isPropertyAccessExpression ( node ) ) return
11
+ let rightNode : ts . Node | undefined
12
+ const upperNode = ts . isIdentifier ( node ) ? node . parent : node
13
+ if ( ts . isPropertyAccessExpression ( upperNode ) ) rightNode = upperNode . expression
14
+ else if ( ts . isObjectBindingPattern ( node ) ) {
15
+ if ( ts . isVariableDeclaration ( node . parent ) ) {
16
+ const { initializer } = node . parent
17
+ if ( initializer ) {
18
+ if ( ts . isIdentifier ( initializer ) ) rightNode = initializer
19
+ if ( ts . isPropertyAccessExpression ( initializer ) ) rightNode = initializer . name
20
+ }
21
+ }
22
+ if ( ts . isParameter ( node . parent ) ) rightNode = node . parent . type
23
+ } else if ( ts . isObjectLiteralExpression ( node ) && ts . isReturnStatement ( node . parent ) && ts . isArrowFunction ( node . parent . parent . parent ) ) {
24
+ rightNode = node . parent . parent . parent . type
25
+ }
26
+ if ( ! rightNode ) return
13
27
const typeChecker = program . getTypeChecker ( )
14
- const expr = node . expression
15
- const type = typeChecker . getTypeAtLocation ( expr )
28
+ const type = typeChecker . getTypeAtLocation ( rightNode )
16
29
const sourceProps = type . getProperties ?.( ) ?. map ( ( { name } ) => name )
17
30
// languageService.getSignatureHelpItems(fileName, position, {}))
18
31
if ( ! sourceProps ) return
@@ -22,13 +35,13 @@ export default (entries: ts.CompletionEntry[], node: ts.Node | undefined, source
22
35
entries ,
23
36
)
24
37
// if sortText first symbol is not a number, than most probably it was highlighted by IntelliCode, keep them high
25
- const [ sortableEntries , notSortableEntries ] = partition ( entry => ! isNaN ( + entry . sortText ) , interestedEntries )
26
- const lowestSortText = Math . min ( ...sortableEntries . map ( ( { sortText } ) => + sortText ) )
38
+ const [ sortableEntries , notSortableEntries ] = partition ( entry => ! isNaN ( parseInt ( entry . sortText ) ) , interestedEntries )
39
+ const lowestSortText = Math . min ( ...sortableEntries . map ( ( { sortText } ) => parseInt ( sortText ) ) )
27
40
// make sorted
28
- sortableEntries
41
+ const sortedEntries = sortableEntries
29
42
. sort ( ( a , b ) => {
30
43
return sourceProps . indexOf ( a . name ) - sourceProps . indexOf ( b . name )
31
44
} )
32
45
. map ( ( entry , i ) => ( { ...entry , sortText : String ( lowestSortText + i ) } ) )
33
- return [ ...notSortableEntries , ...sortableEntries , ...notInterestedEntries ]
46
+ return [ ...notSortableEntries , ...sortedEntries , ...notInterestedEntries ]
34
47
}
0 commit comments