@@ -25,6 +25,14 @@ const buildLabel = (context: any, path: string) => {
2525 return label ;
2626} ;
2727
28+ const buildType = ( value : any ) => {
29+ const type = typeof value ;
30+ if ( type === 'object' && Array . isArray ( value ) ) {
31+ return 'array' ;
32+ }
33+ return type ;
34+ } ;
35+
2836/**
2937 * Create a completion provider for Nunjucks templates.
3038 * @param context The context object containing the variables that are available in the template.
@@ -33,7 +41,7 @@ export const createNunjucksCompletionProvider = (context: any): CompletionFuncti
3341 // Context is an object. We want to recursively create a string array with the paths to all the fields in the context object.
3442 // We will use this to easily check if the word at the cursor matches any of the fields.
3543 // Example: [a.b.c, a.b.d, a.e, f]
36- let contextFields : string [ ] = [ ] ;
44+ let contextFields : string [ ] = [ ... Object . keys ( context ) ] ;
3745 let contextFieldPaths = ( context : any , path : string ) => {
3846 if ( typeof context === 'object' ) {
3947 for ( let key in context ) {
@@ -49,7 +57,9 @@ export const createNunjucksCompletionProvider = (context: any): CompletionFuncti
4957 }
5058 }
5159 } else {
52- contextFields . push ( path ) ;
60+ if ( ! contextFields . includes ( path ) ) {
61+ contextFields . push ( path ) ;
62+ }
5363 }
5464 } ;
5565 contextFieldPaths ( context , '' ) ;
@@ -110,7 +120,7 @@ export const createNunjucksCompletionProvider = (context: any): CompletionFuncti
110120 kind : monaco . languages . CompletionItemKind . Field ,
111121 insertText : field ,
112122 range : range ,
113- detail : typeof get ( context , field ) ,
123+ detail : buildType ( get ( context , field ) ) ,
114124 } ) ) ;
115125 } ) ,
116126 ) ;
0 commit comments