Skip to content

Commit 07b54f0

Browse files
committed
fix: do not suggest propertyNames if doNotSuggest is true
- PR: redhat-developer#1045
1 parent 022a1b1 commit 07b54f0

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/languageservice/services/yamlCompletion.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -1025,14 +1025,16 @@ export class YamlCompletion {
10251025

10261026
if (schema.schema.propertyNames && schema.schema.additionalProperties && schema.schema.type === 'object') {
10271027
const propertyNameSchema = asSchema(schema.schema.propertyNames);
1028-
const label = propertyNameSchema.title || 'property';
1029-
collector.add({
1030-
kind: CompletionItemKind.Property,
1031-
label,
1032-
insertText: '$' + `{1:${label}}: `,
1033-
insertTextFormat: InsertTextFormat.Snippet,
1034-
documentation: this.fromMarkup(propertyNameSchema.markdownDescription) || propertyNameSchema.description || '',
1035-
});
1028+
if (!propertyNameSchema.deprecationMessage && !propertyNameSchema.doNotSuggest) {
1029+
const label = propertyNameSchema.title || 'property';
1030+
collector.add({
1031+
kind: CompletionItemKind.Property,
1032+
label,
1033+
insertText: '$' + `{1:${label}}: `,
1034+
insertTextFormat: InsertTextFormat.Snippet,
1035+
documentation: this.fromMarkup(propertyNameSchema.markdownDescription) || propertyNameSchema.description || '',
1036+
});
1037+
}
10361038
}
10371039
}
10381040

test/autoCompletionFix.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -2230,6 +2230,22 @@ test1:
22302230
expect(completion.items[0].documentation).to.be.equal('Property Description');
22312231
});
22322232

2233+
it('should not suggest propertyNames with doNotSuggest', async () => {
2234+
const schema: JSONSchema = {
2235+
type: 'object',
2236+
additionalProperties: true,
2237+
propertyNames: {
2238+
title: 'property',
2239+
doNotSuggest: true,
2240+
},
2241+
};
2242+
schemaProvider.addSchema(SCHEMA_ID, schema);
2243+
const content = '';
2244+
const completion = await parseSetup(content, 0, content.length);
2245+
2246+
expect(completion.items.length).equal(0);
2247+
});
2248+
22332249
describe('Deprecated schema', () => {
22342250
it('should not autocomplete deprecated schema - property completion', async () => {
22352251
const schema: JSONSchema = {

0 commit comments

Comments
 (0)