File tree Expand file tree Collapse file tree 2 files changed +43
-8
lines changed Expand file tree Collapse file tree 2 files changed +43
-8
lines changed Original file line number Diff line number Diff line change @@ -21,11 +21,15 @@ export default (
21
21
const objType = typeChecker . getContextualType ( node )
22
22
if ( ! objType ) return
23
23
const types = objType . isUnion ( ) ? objType . types : [ objType ]
24
- const properties = types . flatMap ( type => {
25
- if ( isFunctionType ( type , typeChecker ) ) return [ ]
26
- if ( isObjectCompletion ( type , typeChecker ) ) return typeChecker . getPropertiesOfType ( type )
27
- return [ ]
28
- } )
24
+ const properties = types
25
+ . flatMap ( type => {
26
+ if ( isFunctionType ( type , typeChecker ) ) return [ ]
27
+ if ( isObjectCompletion ( type , typeChecker ) ) return typeChecker . getPropertiesOfType ( type )
28
+ return [ ]
29
+ } )
30
+ . filter ( ( property , i , arr ) => {
31
+ return ! arr . find ( ( { name } , k ) => name === property . name && i !== k )
32
+ } )
29
33
for ( const property of properties ) {
30
34
const entry = entries . find ( ( { name } ) => name === property . name )
31
35
if ( ! entry ) continue
Original file line number Diff line number Diff line change @@ -314,13 +314,16 @@ test('Object Literal Completions', () => {
314
314
usedOption,
315
315
/*1*/
316
316
})
317
+
318
+ const somethingWithUntions: { a: string } | { a: any[], b: string } = {/*2*/}
317
319
` )
318
- const { entriesSorted } = getCompletionsAtPosition ( numPositions [ 1 ] ! ) ?? { }
320
+ const { entriesSorted : pos1 } = getCompletionsAtPosition ( numPositions [ 1 ] ! ) !
321
+ const { entriesSorted : pos2 } = getCompletionsAtPosition ( numPositions [ 2 ] ! ) !
319
322
// todo resolve sorting problem + add tests with other keepOriginal (it was tested manually)
320
- for ( const entry of entriesSorted ?? [ ] ) {
323
+ for ( const entry of [ ... pos1 , ... pos2 ] ) {
321
324
entry . insertText = entry . insertText ?. replaceAll ( '\n' , '\\n' )
322
325
}
323
- expect ( entriesSorted ) . toMatchInlineSnapshot ( `
326
+ expect ( pos1 ) . toMatchInlineSnapshot ( /* json */ `
324
327
[
325
328
{
326
329
"insertText": "plugins",
@@ -389,6 +392,34 @@ test('Object Literal Completions', () => {
389
392
},
390
393
]
391
394
` )
395
+ expect ( pos2 ) . toMatchInlineSnapshot ( `
396
+ [
397
+ {
398
+ "insertText": "a",
399
+ "isSnippet": true,
400
+ "kind": "property",
401
+ "kindModifiers": "",
402
+ "name": "a",
403
+ },
404
+ {
405
+ "insertText": "b",
406
+ "isSnippet": true,
407
+ "kind": "property",
408
+ "kindModifiers": "",
409
+ "name": "b",
410
+ },
411
+ {
412
+ "insertText": "b: \\"$1\\",$0",
413
+ "isSnippet": true,
414
+ "kind": "property",
415
+ "kindModifiers": "",
416
+ "labelDetails": {
417
+ "detail": ": \\"\\",",
418
+ },
419
+ "name": "b",
420
+ },
421
+ ]
422
+ ` )
392
423
} )
393
424
394
425
// TODO move/remove this test from here
You can’t perform that action at this time.
0 commit comments