@@ -2587,6 +2587,7 @@ describe('CompletionsProcessor', () => {
25872587 } ] ) ;
25882588 } ) ;
25892589 } ) ;
2590+
25902591 describe ( 'incomplete statements' , ( ) => {
25912592
25922593 it ( 'should complete after if' , ( ) => {
@@ -2609,4 +2610,118 @@ describe('CompletionsProcessor', () => {
26092610 expect ( completions . length ) . to . eql ( 1 ) ;
26102611 } ) ;
26112612 } ) ;
2613+
2614+ describe ( 'compound types' , ( ) => {
2615+ it ( 'includes only common members of union types' , ( ) => {
2616+ program . setFile ( 'source/main.bs' , `
2617+ interface Person
2618+ name as string
2619+ age as integer
2620+ end interface
2621+
2622+ interface Employee
2623+ name as string
2624+ employeeId as integer
2625+ end interface
2626+
2627+ sub greet(p as Person or Employee)
2628+ print p.
2629+ end sub
2630+ ` ) ;
2631+ program . validate ( ) ;
2632+ // print p.|
2633+ let completions = program . getCompletions ( 'source/main.bs' , util . createPosition ( 12 , 29 ) ) ;
2634+ expect ( completions . length ) . to . eql ( 1 ) ;
2635+ expectCompletionsIncludes ( completions , [ {
2636+ label : 'name' ,
2637+ kind : CompletionItemKind . Field
2638+ } ] ) ;
2639+ } ) ;
2640+
2641+ it ( 'includes all members of intersection types' , ( ) => {
2642+ program . setFile ( 'source/main.bs' , `
2643+ interface Person
2644+ name as string
2645+ age as integer
2646+ end interface
2647+
2648+ interface Employee
2649+ name as string
2650+ employeeId as integer
2651+ end interface
2652+
2653+ sub greet(p as Person and Employee)
2654+ print p.
2655+ end sub
2656+ ` ) ;
2657+ program . validate ( ) ;
2658+ // print p.|
2659+ let completions = program . getCompletions ( 'source/main.bs' , util . createPosition ( 12 , 29 ) ) ;
2660+ expect ( completions . length ) . to . eql ( 3 ) ;
2661+ expectCompletionsIncludes ( completions , [ {
2662+ label : 'name' ,
2663+ kind : CompletionItemKind . Field
2664+ } , {
2665+ label : 'age' ,
2666+ kind : CompletionItemKind . Field
2667+ } , {
2668+ label : 'employeeId' ,
2669+ kind : CompletionItemKind . Field
2670+ } ] ) ;
2671+ } ) ;
2672+
2673+ it ( 'includes AA members when it is an intersection with an AA' , ( ) => {
2674+ program . setFile ( 'source/main.bs' , `
2675+ interface Person
2676+ name as string
2677+ age as integer
2678+ end interface
2679+
2680+ sub greet(p as Person and roAssociativeArray)
2681+ print p.
2682+ end sub
2683+ ` ) ;
2684+ program . validate ( ) ;
2685+ // print p.|
2686+ let completions = program . getCompletions ( 'source/main.bs' , util . createPosition ( 7 , 29 ) ) ;
2687+ expect ( completions . length ) . to . at . least ( 4 ) ;
2688+ expectCompletionsIncludes ( completions , [ {
2689+ label : 'name' , // from Person
2690+ kind : CompletionItemKind . Field
2691+ } , {
2692+ label : 'age' , // from Person
2693+ kind : CompletionItemKind . Field
2694+ } , {
2695+ label : 'Append' , // from roAssociativeArray
2696+ kind : CompletionItemKind . Method
2697+ } , {
2698+ label : 'Count' , // from roAssociativeArray
2699+ kind : CompletionItemKind . Method
2700+ } ] ) ;
2701+ } ) ;
2702+
2703+ it ( 'includes members from non-dynamic when it is an intersection with dynamic' , ( ) => {
2704+ program . setFile ( 'source/main.bs' , `
2705+ interface Person
2706+ name as string
2707+ age as integer
2708+ end interface
2709+
2710+ sub greet(p as Person and dynamic)
2711+ print p.
2712+ end sub
2713+ ` ) ;
2714+ program . validate ( ) ;
2715+ // print p.|
2716+ let completions = program . getCompletions ( 'source/main.bs' , util . createPosition ( 7 , 29 ) ) ;
2717+ expect ( completions . length ) . to . at . least ( 2 ) ;
2718+ expectCompletionsIncludes ( completions , [ {
2719+ label : 'name' , // from Person
2720+ kind : CompletionItemKind . Field
2721+ } , {
2722+ label : 'age' , // from Person
2723+ kind : CompletionItemKind . Field
2724+ } ] ) ;
2725+ } ) ;
2726+ } ) ;
26122727} ) ;
0 commit comments