Skip to content

Commit

Permalink
feat: exclude deprecated schema from autocompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
p-spacek committed Jan 17, 2023
1 parent f7407e2 commit f4335f9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down
34 changes: 34 additions & 0 deletions test/autoCompletionFix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

0 comments on commit f4335f9

Please sign in to comment.