Skip to content

Commit 73c244a

Browse files
committed
Added custom tags to autocompletion
1 parent 5f5d212 commit 73c244a

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/languageservice/services/yamlCompletion.ts

+30
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@ export class YAMLCompletion {
2525
private schemaService: SchemaService.IJSONSchemaService;
2626
private contributions: JSONWorkerContribution[];
2727
private promise: PromiseConstructor;
28+
private customTags: Array<String>;
2829

2930
constructor(schemaService: SchemaService.IJSONSchemaService, contributions: JSONWorkerContribution[] = [], promiseConstructor?: PromiseConstructor) {
3031
this.schemaService = schemaService;
3132
this.contributions = contributions;
3233
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+
}
3341
}
3442

3543
public doResolve(item: CompletionItem): Thenable<CompletionItem> {
@@ -185,6 +193,9 @@ export class YAMLCompletion {
185193
if (this.contributions.length > 0) {
186194
this.getContributedValueCompletions(currentDoc, node, offset, document, collector, collectionPromises);
187195
}
196+
if (this.customTags.length > 0) {
197+
this.getCustomTagValueCompletions(collector);
198+
}
188199

189200
return this.promise.all(collectionPromises).then(() => {
190201
return result;
@@ -322,6 +333,15 @@ export class YAMLCompletion {
322333
}
323334
}
324335

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+
325345
private addSchemaValueCompletions(schema: JSONSchema, collector: CompletionsCollector, types: { [type: string]: boolean }, separatorAfter: string): void {
326346
this.addDefaultValueCompletions(schema, collector, separatorAfter);
327347
this.addEnumValueCompletions(schema, collector, separatorAfter);
@@ -408,6 +428,16 @@ export class YAMLCompletion {
408428
});
409429
}
410430

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+
411441
private getLabelForValue(value: any): string {
412442
let label = typeof value === "string" ? value : JSON.stringify(value);
413443
if (label.length > 57) {

src/languageservice/yamlLanguageService.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import { YAMLDocument, Diagnostic } from 'vscode-yaml-languageservice';
1717
export interface LanguageSettings {
1818
validate?: boolean; //Setting for whether we want to validate the schema
1919
isKubernetes?: boolean; //If true then its validating against kubernetes
20-
schemas?: any[]; //List of schemas
20+
schemas?: any[]; //List of schemas,
21+
customTags?: Array<String>; //Array of Custom Tags
2122
}
2223

2324
export interface PromiseConstructor {
@@ -119,6 +120,7 @@ export function getLanguageService(schemaRequestService, workspaceContext, contr
119120
});
120121
}
121122
yamlValidation.configure(settings);
123+
completer.configure(settings["customTags"]);
122124
},
123125
doComplete: completer.doComplete.bind(completer),
124126
doResolve: completer.doResolve.bind(completer),

src/server.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ connection.onNotification(SchemaAssociationNotification.type, associations => {
297297
function updateConfiguration() {
298298
let languageSettings: LanguageSettings = {
299299
validate: yamlShouldValidate,
300-
schemas: []
300+
schemas: [],
301+
customTags: customTags
301302
};
302303
if (schemaAssociations) {
303304
for (var pattern in schemaAssociations) {

0 commit comments

Comments
 (0)