@@ -335,6 +335,8 @@ export default class MongoDBService {
335335 {
336336 label : 'use' ,
337337 kind : CompletionItemKind . Function ,
338+ documentation : 'Switch current database.' ,
339+ detail : 'use(<databaseName>)' ,
338340 preselect : true ,
339341 } ,
340342 ] ;
@@ -431,6 +433,56 @@ export default class MongoDBService {
431433 }
432434 }
433435
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+
434486 /**
435487 * Get and cache collection and field names based on the namespace.
436488 */
@@ -489,11 +541,14 @@ export default class MongoDBService {
489541
490542 return {
491543 label : item . value ,
544+ kind : CompletionItemKind . Keyword ,
492545 insertText : snippet ,
493546 insertTextFormat : InsertTextFormat . Snippet ,
494- kind : CompletionItemKind . Keyword ,
547+ documentation : this . _getAggregationDocumentation ( {
548+ operator : item . value ,
549+ description : item . description ,
550+ } ) ,
495551 preselect : true ,
496- detail : item . description ,
497552 } ;
498553 } ) ;
499554 }
@@ -530,8 +585,11 @@ export default class MongoDBService {
530585 item . meta === 'field:identifier'
531586 ? CompletionItemKind . Field
532587 : CompletionItemKind . Keyword ,
588+ documentation : this . _getAggregationDocumentation ( {
589+ operator : item . value ,
590+ description : item . description ,
591+ } ) ,
533592 preselect : true ,
534- detail : item . description ,
535593 } ;
536594 } ) ;
537595 }
@@ -577,8 +635,11 @@ export default class MongoDBService {
577635 item . meta === 'field:identifier'
578636 ? CompletionItemKind . Field
579637 : CompletionItemKind . Keyword ,
638+ documentation : this . _getAggregationDocumentation ( {
639+ operator : item . value ,
640+ description : item . description ,
641+ } ) ,
580642 preselect : true ,
581- detail : item . description ,
582643 } ;
583644 } ) ;
584645 }
@@ -600,11 +661,14 @@ export default class MongoDBService {
600661
601662 return {
602663 label : item . value ,
664+ kind : CompletionItemKind . Constructor ,
603665 insertText : snippet ,
604666 insertTextFormat : InsertTextFormat . Snippet ,
605- kind : CompletionItemKind . Constructor ,
667+ documentation : this . _getBsonDocumentation ( {
668+ bsonType : item . value ,
669+ description : item . description ,
670+ } ) ,
606671 preselect : true ,
607- detail : item . description ,
608672 } ;
609673 } ) ;
610674 }
@@ -629,8 +693,14 @@ export default class MongoDBService {
629693 item . meta === 'field:reference'
630694 ? CompletionItemKind . Reference
631695 : CompletionItemKind . Variable ,
696+ documentation :
697+ item . meta === 'variable:system'
698+ ? this . _getSystemVariableDocumentation ( {
699+ variable : item . value ,
700+ description : item . description ,
701+ } )
702+ : item . description ,
632703 preselect : true ,
633- detail : item . description ,
634704 } ;
635705 } ) ;
636706 }
0 commit comments