@@ -199,13 +199,95 @@ describe('Language Service', () => {
199199 position : { line : 0 , character : 0 }
200200 } ) ;
201201
202- expect ( completions . find ( c => c . label === 'numVar' ) ?. detail ) . toBe ( 'number' ) ;
203- expect ( completions . find ( c => c . label === 'strVar' ) ?. detail ) . toBe ( 'string' ) ;
204- expect ( completions . find ( c => c . label === 'arrVar' ) ?. detail ) . toBe ( 'array' ) ;
205- expect ( completions . find ( c => c . label === 'boolVar' ) ?. detail ) . toBe ( 'boolean' ) ;
206- expect ( completions . find ( c => c . label === 'nullVar' ) ?. detail ) . toBe ( 'null' ) ;
202+ expect ( completions . find ( c => c . label === 'numVar' ) ?. detail ) . toBe ( 'number' ) ;
203+ expect ( completions . find ( c => c . label === 'strVar' ) ?. detail ) . toBe ( 'string' ) ;
204+ expect ( completions . find ( c => c . label === 'arrVar' ) ?. detail ) . toBe ( 'array' ) ;
205+ expect ( completions . find ( c => c . label === 'boolVar' ) ?. detail ) . toBe ( 'boolean' ) ;
206+ expect ( completions . find ( c => c . label === 'nullVar' ) ?. detail ) . toBe ( 'null' ) ;
207+ } ) ;
208+
209+ it ( 'should suggest array selector when variable is an array' , ( ) => {
210+ const text = 'arr' ;
211+ const doc = TextDocument . create ( 'file://test' , 'plaintext' , 1 , text ) ;
212+
213+ const completions = ls . getCompletions ( {
214+ textDocument : doc ,
215+ variables : {
216+ arr : [ 10 , 20 , 30 ]
217+ } ,
218+ position : { line : 0 , character : 3 }
219+ } ) ;
220+
221+ const arrayItem = completions . find ( c => c . label === 'arr[]' ) ;
222+ expect ( arrayItem ) . toBeDefined ( ) ;
223+
224+ // Insert only the selector
225+ expect ( arrayItem ?. insertTextFormat ) . toBe ( 2 ) ; // Snippet
226+ expect ( arrayItem ?. textEdit ?. newText ) . toContain ( 'arr[' ) ;
227+ } ) ;
228+
229+ it ( 'should autocomplete children after indexed array access' , ( ) => {
230+ const text = 'arr[0].' ;
231+ const doc = TextDocument . create ( 'file://test' , 'plaintext' , 1 , text ) ;
232+
233+ const completions = ls . getCompletions ( {
234+ textDocument : doc ,
235+ variables : {
236+ arr : [
237+ { foo : 1 , bar : 2 }
238+ ]
239+ } ,
240+ position : { line : 0 , character : text . length }
241+ } ) ;
242+
243+ expect ( completions . length ) . toBeGreaterThan ( 0 ) ;
244+
245+ const fooItem = completions . find ( c => c . label === 'arr[0].foo' ) ;
246+ expect ( fooItem ) . toBeDefined ( ) ;
247+ expect ( fooItem ?. insertText ) . toBe ( 'foo' ) ;
248+ } ) ;
249+
250+ it ( 'should support multi-dimensional array selectors' , ( ) => {
251+ const text = 'matrix[0][1].' ;
252+ const doc = TextDocument . create ( 'file://test' , 'plaintext' , 1 , text ) ;
253+
254+ const completions = ls . getCompletions ( {
255+ textDocument : doc ,
256+ variables : {
257+ matrix : [
258+ [
259+ { value : 42 }
260+ ]
261+ ]
262+ } ,
263+ position : { line : 0 , character : text . length }
264+ } ) ;
265+
266+ const valueItem = completions . find ( c => c . label === 'matrix[0][1].value' ) ;
267+ expect ( valueItem ) . toBeDefined ( ) ;
268+ expect ( valueItem ?. insertText ) . toBe ( 'value' ) ;
269+ } ) ;
270+
271+ it ( 'should place cursor inside array brackets' , ( ) => {
272+ const text = 'arr' ;
273+ const doc = TextDocument . create ( 'file://test' , 'plaintext' , 1 , text ) ;
274+
275+ const completions = ls . getCompletions ( {
276+ textDocument : doc ,
277+ variables : {
278+ arr : [ 1 , 2 , 3 ]
279+ } ,
280+ position : { line : 0 , character : 3 }
281+ } ) ;
282+
283+ const arrayItem = completions . find ( c => c . label === 'arr[]' ) ;
284+ const newText = arrayItem ?. textEdit ?. newText as string | undefined ;
285+
286+ expect ( newText ) . toContain ( '[' ) ;
287+ expect ( newText ) . toContain ( ']' ) ;
288+ expect ( newText ) . toContain ( '${1}' ) ;
289+ } ) ;
207290 } ) ;
208- } ) ;
209291
210292 describe ( 'getHover' , ( ) => {
211293 it ( 'should show type information for variables' , ( ) => {
0 commit comments