Skip to content

Commit e5dcce0

Browse files
fix: snippets in additionalProperties (#951)
Co-authored-by: Muthurajan Sivasubramanian <[email protected]>
1 parent 4b91dd3 commit e5dcce0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/languageservice/services/yamlCompletion.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,8 @@ export class YamlCompletion {
925925
if (propertySchema) {
926926
this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types, 'value');
927927
}
928-
} else if (s.schema.additionalProperties) {
928+
}
929+
if (s.schema.additionalProperties) {
929930
this.addSchemaValueCompletions(s.schema.additionalProperties, separatorAfter, collector, types, 'value');
930931
}
931932
}

test/autoCompletionFix.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,30 @@ objB:
11831183
expect(completion.items[0].insertText).to.be.equal('test1');
11841184
});
11851185

1186+
it('should suggest defaultSnippets from additionalProperties', async () => {
1187+
const schema: JSONSchema = {
1188+
type: 'object',
1189+
properties: {
1190+
id: {
1191+
type: 'string',
1192+
},
1193+
},
1194+
additionalProperties: {
1195+
anyOf: [
1196+
{
1197+
type: 'string',
1198+
defaultSnippets: [{ label: 'snippet', body: 'snippetBody' }],
1199+
},
1200+
],
1201+
},
1202+
};
1203+
schemaProvider.addSchema(SCHEMA_ID, schema);
1204+
const content = 'value: |\n|';
1205+
const completion = await parseCaret(content);
1206+
1207+
expect(completion.items.map((i) => i.insertText)).to.be.deep.equal(['snippetBody']);
1208+
});
1209+
11861210
describe('should suggest prop of the object (based on not completed prop name)', () => {
11871211
const schema: JSONSchema = {
11881212
definitions: {

0 commit comments

Comments
 (0)