@@ -25,11 +25,19 @@ export class YAMLCompletion {
25
25
private schemaService : SchemaService . IJSONSchemaService ;
26
26
private contributions : JSONWorkerContribution [ ] ;
27
27
private promise : PromiseConstructor ;
28
+ private customTags : Array < String > ;
28
29
29
30
constructor ( schemaService : SchemaService . IJSONSchemaService , contributions : JSONWorkerContribution [ ] = [ ] , promiseConstructor ?: PromiseConstructor ) {
30
31
this . schemaService = schemaService ;
31
32
this . contributions = contributions ;
32
33
this . promise = promiseConstructor || Promise ;
34
+ this . customTags = [ ] ;
35
+ }
36
+
37
+ public configure ( customTags : Array < String > ) {
38
+ if ( customTags && customTags . length > 0 ) {
39
+ this . customTags = customTags ;
40
+ }
33
41
}
34
42
35
43
public doResolve ( item : CompletionItem ) : Thenable < CompletionItem > {
@@ -185,6 +193,9 @@ export class YAMLCompletion {
185
193
if ( this . contributions . length > 0 ) {
186
194
this . getContributedValueCompletions ( currentDoc , node , offset , document , collector , collectionPromises ) ;
187
195
}
196
+ if ( this . customTags . length > 0 ) {
197
+ this . getCustomTagValueCompletions ( collector ) ;
198
+ }
188
199
189
200
return this . promise . all ( collectionPromises ) . then ( ( ) => {
190
201
return result ;
@@ -322,6 +333,15 @@ export class YAMLCompletion {
322
333
}
323
334
}
324
335
336
+ private getCustomTagValueCompletions ( collector : CompletionsCollector ) {
337
+ this . customTags . forEach ( ( customTagItem ) => {
338
+ let tagItemSplit = customTagItem . split ( " " ) ;
339
+ if ( tagItemSplit && tagItemSplit [ 0 ] ) {
340
+ this . addCustomTagValueCompletion ( collector , " " , tagItemSplit [ 0 ] ) ;
341
+ }
342
+ } ) ;
343
+ }
344
+
325
345
private addSchemaValueCompletions ( schema : JSONSchema , collector : CompletionsCollector , types : { [ type : string ] : boolean } , separatorAfter : string ) : void {
326
346
this . addDefaultValueCompletions ( schema , collector , separatorAfter ) ;
327
347
this . addEnumValueCompletions ( schema , collector , separatorAfter ) ;
@@ -408,6 +428,16 @@ export class YAMLCompletion {
408
428
} ) ;
409
429
}
410
430
431
+ private addCustomTagValueCompletion ( collector : CompletionsCollector , separatorAfter : string , label : string ) : void {
432
+ collector . add ( {
433
+ kind : this . getSuggestionKind ( 'string' ) ,
434
+ label : label ,
435
+ insertText : label + separatorAfter ,
436
+ insertTextFormat : InsertTextFormat . Snippet ,
437
+ documentation : ''
438
+ } ) ;
439
+ }
440
+
411
441
private getLabelForValue ( value : any ) : string {
412
442
let label = typeof value === "string" ? value : JSON . stringify ( value ) ;
413
443
if ( label . length > 57 ) {
0 commit comments