From d74373784a9c84e347e47caa7d28d59b5c168f11 Mon Sep 17 00:00:00 2001
From: Petr Spacek
Date: Tue, 25 Mar 2025 21:52:03 +0100
Subject: [PATCH] fix: do not suggest propertyNames if doNotSuggest is true
---
src/languageservice/services/yamlCompletion.ts | 18 ++++++++++--------
test/autoCompletionFix.test.ts | 16 ++++++++++++++++
2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/src/languageservice/services/yamlCompletion.ts b/src/languageservice/services/yamlCompletion.ts
index 41a26549d..305de7e7e 100644
--- a/src/languageservice/services/yamlCompletion.ts
+++ b/src/languageservice/services/yamlCompletion.ts
@@ -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 || '',
+ });
+ }
}
}
diff --git a/test/autoCompletionFix.test.ts b/test/autoCompletionFix.test.ts
index 6b00cf8c3..426a34809 100644
--- a/test/autoCompletionFix.test.ts
+++ b/test/autoCompletionFix.test.ts
@@ -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',