diff --git a/src/languageservice/services/yamlCompletion.ts b/src/languageservice/services/yamlCompletion.ts index 31129491..f3e6a129 100644 --- a/src/languageservice/services/yamlCompletion.ts +++ b/src/languageservice/services/yamlCompletion.ts @@ -519,7 +519,7 @@ export class YAMLCompletion extends JSONCompletion { } collector.add({ kind: this.getSuggestionKind(type), - label: value, + label: this.getLabelForValue(value), insertText: this.getInsertTextForValue(value, separatorAfter, type), insertTextFormat: InsertTextFormat.Snippet, }); @@ -967,11 +967,14 @@ export class YAMLCompletion extends JSONCompletion { return this.getInsertTextForValue(value, separatorAfter, type); } - private getLabelForValue(value: string): string { + private getLabelForValue(value: unknown): string { if (value === null) { return 'null'; // return string with 'null' value if schema contains null as possible value } - return value; + if (Array.isArray(value)) { + return JSON.stringify(value); + } + return value as string; } /** diff --git a/test/autoCompletion.test.ts b/test/autoCompletion.test.ts index d0d17516..8306e3d4 100644 --- a/test/autoCompletion.test.ts +++ b/test/autoCompletion.test.ts @@ -1815,6 +1815,26 @@ describe('Auto Completion Tests', () => { expect(trueItem.textEdit.newText).equal('"true"'); }); + it('should provide label as string for examples completion item', async () => { + languageService.addSchema(SCHEMA_ID, { + type: 'object', + properties: { + fooBar: { + type: 'array', + items: { + type: 'string', + examples: ['test'], + }, + }, + }, + }); + + const content = 'fooBar: \n'; + const completion = await parseSetup(content, 8); + + expect(completion.items).length(1); + }); + it('should provide completion for flow map', async () => { languageService.addSchema(SCHEMA_ID, { type: 'object',