Skip to content

fix: do not suggest propertyNames if doNotSuggest is true #1045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -823,14 +823,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 @@ -1329,6 +1329,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