Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,14 +840,16 @@ export class YamlCompletion {

if (schema.schema.propertyNames && schema.schema.additionalProperties && schema.schema.type === 'object') {
const propertyNameSchema = asSchema(schema.schema.propertyNames);
const label = propertyNameSchema.title || 'property';
collector.add({
kind: CompletionItemKind.Property,
label,
insertText: '$' + `{1:${label}}: `,
insertTextFormat: InsertTextFormat.Snippet,
documentation: this.fromMarkup(propertyNameSchema.markdownDescription) || propertyNameSchema.description || '',
});
if (!propertyNameSchema.deprecationMessage && !propertyNameSchema.doNotSuggest) {
const label = propertyNameSchema.title || 'property';
collector.add({
kind: CompletionItemKind.Property,
label,
insertText: '$' + `{1:${label}}: `,
insertTextFormat: InsertTextFormat.Snippet,
documentation: this.fromMarkup(propertyNameSchema.markdownDescription) || propertyNameSchema.description || '',
});
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/autoCompletionFix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,22 @@ test1:
expect(completion.items[0].insertText).to.be.equal('${1:property}: ');
expect(completion.items[0].documentation).to.be.equal('Property Description');
});
it('should not suggest propertyNames with doNotSuggest', async () => {
const schema: JSONSchema = {
type: 'object',
additionalProperties: true,
propertyNames: {
title: 'property',
doNotSuggest: true,
},
};
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = '';
const completion = await parseSetup(content, 0, content.length);

expect(completion.items.length).equal(0);
});

it('should suggest enum based on type', async () => {
const schema: JSONSchema = {
type: 'object',
Expand Down