Skip to content

Commit

Permalink
fix: snippets in additionalProperties (#951)
Browse files Browse the repository at this point in the history
Co-authored-by: Muthurajan Sivasubramanian <[email protected]>
  • Loading branch information
p-spacek and msivasubramaniaan authored May 28, 2024
1 parent 4b91dd3 commit e5dcce0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,8 @@ export class YamlCompletion {
if (propertySchema) {
this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types, 'value');
}
} else if (s.schema.additionalProperties) {
}
if (s.schema.additionalProperties) {
this.addSchemaValueCompletions(s.schema.additionalProperties, separatorAfter, collector, types, 'value');
}
}
Expand Down
24 changes: 24 additions & 0 deletions test/autoCompletionFix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,30 @@ objB:
expect(completion.items[0].insertText).to.be.equal('test1');
});

it('should suggest defaultSnippets from additionalProperties', async () => {
const schema: JSONSchema = {
type: 'object',
properties: {
id: {
type: 'string',
},
},
additionalProperties: {
anyOf: [
{
type: 'string',
defaultSnippets: [{ label: 'snippet', body: 'snippetBody' }],
},
],
},
};
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = 'value: |\n|';
const completion = await parseCaret(content);

expect(completion.items.map((i) => i.insertText)).to.be.deep.equal(['snippetBody']);
});

describe('should suggest prop of the object (based on not completed prop name)', () => {
const schema: JSONSchema = {
definitions: {
Expand Down

0 comments on commit e5dcce0

Please sign in to comment.