@@ -335,6 +335,8 @@ export default class MongoDBService {
335
335
{
336
336
label : 'use' ,
337
337
kind : CompletionItemKind . Function ,
338
+ documentation : 'Switch current database.' ,
339
+ detail : 'use(<databaseName>)' ,
338
340
preselect : true ,
339
341
} ,
340
342
] ;
@@ -431,6 +433,56 @@ export default class MongoDBService {
431
433
}
432
434
}
433
435
436
+ _getAggregationDocumentation ( {
437
+ operator,
438
+ description,
439
+ } : {
440
+ operator : string ;
441
+ description ?: string ;
442
+ } ) {
443
+ const title = operator . replace ( / [ $ ] / g, '' ) ;
444
+ const link = `https://www.mongodb.com/docs/manual/reference/operator/aggregation/${ title } /` ;
445
+ return {
446
+ kind : MarkupKind . Markdown ,
447
+ value : description
448
+ ? `${ description } \n\n[Read More](${ link } )`
449
+ : `[Documentation](${ link } )` ,
450
+ } ;
451
+ }
452
+
453
+ _getBsonDocumentation ( {
454
+ bsonType,
455
+ description,
456
+ } : {
457
+ bsonType : string ;
458
+ description ?: string ;
459
+ } ) {
460
+ const link = `https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#${ bsonType } ` ;
461
+ return {
462
+ kind : MarkupKind . Markdown ,
463
+ value : description
464
+ ? `${ description } \n\n[Read More](${ link } )`
465
+ : `[Documentation](${ link } )` ,
466
+ } ;
467
+ }
468
+
469
+ _getSystemVariableDocumentation ( {
470
+ variable,
471
+ description,
472
+ } : {
473
+ variable : string ;
474
+ description ?: string ;
475
+ } ) {
476
+ const title = variable . replace ( / [ $ ] / g, '' ) ;
477
+ const link = `https://www.mongodb.com/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.${ title } ` ;
478
+ return {
479
+ kind : MarkupKind . Markdown ,
480
+ value : description
481
+ ? `${ description } \n\n[Read More](${ link } )`
482
+ : `[Documentation](${ link } )` ,
483
+ } ;
484
+ }
485
+
434
486
/**
435
487
* Get and cache collection and field names based on the namespace.
436
488
*/
@@ -489,11 +541,14 @@ export default class MongoDBService {
489
541
490
542
return {
491
543
label : item . value ,
544
+ kind : CompletionItemKind . Keyword ,
492
545
insertText : snippet ,
493
546
insertTextFormat : InsertTextFormat . Snippet ,
494
- kind : CompletionItemKind . Keyword ,
547
+ documentation : this . _getAggregationDocumentation ( {
548
+ operator : item . value ,
549
+ description : item . description ,
550
+ } ) ,
495
551
preselect : true ,
496
- detail : item . description ,
497
552
} ;
498
553
} ) ;
499
554
}
@@ -530,8 +585,11 @@ export default class MongoDBService {
530
585
item . meta === 'field:identifier'
531
586
? CompletionItemKind . Field
532
587
: CompletionItemKind . Keyword ,
588
+ documentation : this . _getAggregationDocumentation ( {
589
+ operator : item . value ,
590
+ description : item . description ,
591
+ } ) ,
533
592
preselect : true ,
534
- detail : item . description ,
535
593
} ;
536
594
} ) ;
537
595
}
@@ -577,8 +635,11 @@ export default class MongoDBService {
577
635
item . meta === 'field:identifier'
578
636
? CompletionItemKind . Field
579
637
: CompletionItemKind . Keyword ,
638
+ documentation : this . _getAggregationDocumentation ( {
639
+ operator : item . value ,
640
+ description : item . description ,
641
+ } ) ,
580
642
preselect : true ,
581
- detail : item . description ,
582
643
} ;
583
644
} ) ;
584
645
}
@@ -600,11 +661,14 @@ export default class MongoDBService {
600
661
601
662
return {
602
663
label : item . value ,
664
+ kind : CompletionItemKind . Constructor ,
603
665
insertText : snippet ,
604
666
insertTextFormat : InsertTextFormat . Snippet ,
605
- kind : CompletionItemKind . Constructor ,
667
+ documentation : this . _getBsonDocumentation ( {
668
+ bsonType : item . value ,
669
+ description : item . description ,
670
+ } ) ,
606
671
preselect : true ,
607
- detail : item . description ,
608
672
} ;
609
673
} ) ;
610
674
}
@@ -629,8 +693,14 @@ export default class MongoDBService {
629
693
item . meta === 'field:reference'
630
694
? CompletionItemKind . Reference
631
695
: CompletionItemKind . Variable ,
696
+ documentation :
697
+ item . meta === 'variable:system'
698
+ ? this . _getSystemVariableDocumentation ( {
699
+ variable : item . value ,
700
+ description : item . description ,
701
+ } )
702
+ : item . description ,
632
703
preselect : true ,
633
- detail : item . description ,
634
704
} ;
635
705
} ) ;
636
706
}
0 commit comments