From f4335f900bdce94ea35a664a9f57c9fa45cb7536 Mon Sep 17 00:00:00 2001
From: Petr Spacek
Date: Tue, 17 Jan 2023 13:35:37 +0100
Subject: [PATCH] feat: exclude deprecated schema from autocompletion
---
.../services/yamlCompletion.ts | 4 +++
test/autoCompletionFix.test.ts | 34 +++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/src/languageservice/services/yamlCompletion.ts b/src/languageservice/services/yamlCompletion.ts
index 95d53bc8..62e578b8 100644
--- a/src/languageservice/services/yamlCompletion.ts
+++ b/src/languageservice/services/yamlCompletion.ts
@@ -697,6 +697,10 @@ export class YamlCompletion {
});
}
for (const schema of matchingSchemas) {
+ if (schema.schema.deprecationMessage) {
+ continue;
+ }
+
if (
((schema.node.internalNode === node && !matchOriginal) ||
(schema.node.internalNode === originalNode && !hasColon) ||
diff --git a/test/autoCompletionFix.test.ts b/test/autoCompletionFix.test.ts
index f947d594..6e5b846c 100644
--- a/test/autoCompletionFix.test.ts
+++ b/test/autoCompletionFix.test.ts
@@ -1206,4 +1206,38 @@ test1:
expect(completion.items[0].insertText).to.be.equal('${1:property}: ');
expect(completion.items[0].documentation).to.be.equal('Property Description');
});
+
+ describe('Deprecated schema', () => {
+ it('should not autocomplete deprecated schema', async () => {
+ const schema: JSONSchema = {
+ properties: {
+ prop1: { type: 'string' },
+ },
+ deprecationMessage: 'Deprecated',
+ };
+ languageService.addSchema(SCHEMA_ID, schema);
+ const content = '';
+ const completion = await parseSetup(content, 0, 1);
+
+ expect(completion.items.length).equal(0);
+ });
+ it('should autocomplete inside deprecated schema', async () => {
+ const schema: JSONSchema = {
+ properties: {
+ obj1: {
+ properties: {
+ item1: { type: 'string' },
+ },
+ },
+ },
+ deprecationMessage: 'Deprecated',
+ };
+ languageService.addSchema(SCHEMA_ID, schema);
+ const content = 'obj1:\n | |';
+ const completion = await parseCaret(content);
+
+ expect(completion.items.length).equal(1);
+ expect(completion.items[0].label).equal('item1');
+ });
+ });
});