@@ -277,7 +277,7 @@ export function getConfigCompletions(
277
277
278
278
const content = document . getText ( ) ;
279
279
const offset = document . offsetAt ( position ) ;
280
-
280
+
281
281
// Parse the document with jsonc-parser (handles incomplete JSON)
282
282
const errors : jsoncParser . ParseError [ ] = [ ] ;
283
283
const root = jsoncParser . parseTree ( content , errors ) ;
@@ -287,7 +287,7 @@ export function getConfigCompletions(
287
287
288
288
// Get the location at the cursor
289
289
const location = jsoncParser . getLocation ( content , offset ) ;
290
-
290
+
291
291
// Find the nearest object node that contains the cursor
292
292
const currentObjectNode = findContainingObjectNode ( root , offset ) ;
293
293
if ( ! currentObjectNode ) {
@@ -331,20 +331,29 @@ export function getConfigCompletions(
331
331
return item ;
332
332
} ) ;
333
333
334
- return completions . length > 0 ? completions : getTopLevelCompletions ( schemaInfo ) ;
334
+ return completions . length > 0
335
+ ? completions
336
+ : getTopLevelCompletions ( schemaInfo ) ;
335
337
}
336
338
337
339
// Helper functions for jsonc-parser based completion
338
340
339
- function findContainingObjectNode ( node : jsoncParser . Node | undefined , offset : number ) : jsoncParser . Node | undefined {
341
+ function findContainingObjectNode (
342
+ node : jsoncParser . Node | undefined ,
343
+ offset : number ,
344
+ ) : jsoncParser . Node | undefined {
340
345
if ( ! node ) {
341
346
return undefined ;
342
347
}
343
348
344
349
let bestMatch : jsoncParser . Node | undefined = undefined ;
345
350
346
351
// If this node is an object and contains the offset, it's a potential match
347
- if ( node . type === 'object' && node . offset <= offset && node . offset + node . length >= offset ) {
352
+ if (
353
+ node . type === "object" &&
354
+ node . offset <= offset &&
355
+ node . offset + node . length >= offset
356
+ ) {
348
357
bestMatch = node ;
349
358
}
350
359
@@ -354,7 +363,10 @@ function findContainingObjectNode(node: jsoncParser.Node | undefined, offset: nu
354
363
const result = findContainingObjectNode ( child , offset ) ;
355
364
if ( result ) {
356
365
// Prefer deeper/more specific matches
357
- if ( ! bestMatch || ( result . offset > bestMatch . offset && result . length < bestMatch . length ) ) {
366
+ if (
367
+ ! bestMatch ||
368
+ ( result . offset > bestMatch . offset && result . length < bestMatch . length )
369
+ ) {
358
370
bestMatch = result ;
359
371
}
360
372
}
@@ -364,22 +376,32 @@ function findContainingObjectNode(node: jsoncParser.Node | undefined, offset: nu
364
376
return bestMatch ;
365
377
}
366
378
367
- function getPathToNode ( root : jsoncParser . Node , targetNode : jsoncParser . Node ) : string [ ] | undefined {
368
- function buildPath ( node : jsoncParser . Node , currentPath : string [ ] ) : string [ ] | undefined {
379
+ function getPathToNode (
380
+ root : jsoncParser . Node ,
381
+ targetNode : jsoncParser . Node ,
382
+ ) : string [ ] | undefined {
383
+ function buildPath (
384
+ node : jsoncParser . Node ,
385
+ currentPath : string [ ] ,
386
+ ) : string [ ] | undefined {
369
387
if ( node === targetNode ) {
370
388
return currentPath ;
371
389
}
372
390
373
391
if ( node . children ) {
374
392
for ( const child of node . children ) {
375
393
let newPath = [ ...currentPath ] ;
376
-
394
+
377
395
// If this child is a property node, add its key to the path
378
- if ( child . type === 'property' && child . children && child . children . length >= 2 ) {
396
+ if (
397
+ child . type === "property" &&
398
+ child . children &&
399
+ child . children . length >= 2
400
+ ) {
379
401
const keyNode = child . children [ 0 ] ;
380
- if ( keyNode . type === ' string' ) {
402
+ if ( keyNode . type === " string" ) {
381
403
const key = jsoncParser . getNodeValue ( keyNode ) ;
382
- if ( typeof key === ' string' ) {
404
+ if ( typeof key === " string" ) {
383
405
newPath = [ ...newPath , key ] ;
384
406
}
385
407
}
@@ -400,14 +422,18 @@ function getPathToNode(root: jsoncParser.Node, targetNode: jsoncParser.Node): st
400
422
401
423
function getExistingKeys ( objectNode : jsoncParser . Node ) : string [ ] {
402
424
const keys : string [ ] = [ ] ;
403
-
404
- if ( objectNode . type === ' object' && objectNode . children ) {
425
+
426
+ if ( objectNode . type === " object" && objectNode . children ) {
405
427
for ( const child of objectNode . children ) {
406
- if ( child . type === 'property' && child . children && child . children . length >= 1 ) {
428
+ if (
429
+ child . type === "property" &&
430
+ child . children &&
431
+ child . children . length >= 1
432
+ ) {
407
433
const keyNode = child . children [ 0 ] ;
408
- if ( keyNode . type === ' string' ) {
434
+ if ( keyNode . type === " string" ) {
409
435
const key = jsoncParser . getNodeValue ( keyNode ) ;
410
- if ( typeof key === ' string' ) {
436
+ if ( typeof key === " string" ) {
411
437
keys . push ( key ) ;
412
438
}
413
439
}
@@ -420,11 +446,11 @@ function getExistingKeys(objectNode: jsoncParser.Node): string[] {
420
446
421
447
function resolveSchemaForPath ( schema : any , path : string [ ] ) : any {
422
448
let current = schema ;
423
-
449
+
424
450
for ( const segment of path ) {
425
451
if ( current . properties && current . properties [ segment ] ) {
426
452
const prop = current . properties [ segment ] ;
427
-
453
+
428
454
// Handle $ref
429
455
if ( prop . $ref ) {
430
456
const refPath = prop . $ref . replace ( "#/" , "" ) . split ( "/" ) ;
@@ -445,7 +471,7 @@ function resolveSchemaForPath(schema: any, path: string[]): any {
445
471
return null ;
446
472
}
447
473
}
448
-
474
+
449
475
return current ;
450
476
}
451
477
0 commit comments