Skip to content

Commit b4642d2

Browse files
committed
fix: snippets in additionalProperties - JIGX
1 parent 9674dc9 commit b4642d2

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/languageservice/services/yamlCompletion.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,8 @@ export class YamlCompletion {
11011101
if (propertySchema) {
11021102
this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types, 'value');
11031103
}
1104-
} else if (s.schema.additionalProperties) {
1104+
}
1105+
if (s.schema.additionalProperties) {
11051106
this.addSchemaValueCompletions(s.schema.additionalProperties, separatorAfter, collector, types, 'value');
11061107
}
11071108
}

test/autoCompletionFix.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,30 @@ test:
13531353
expect(completion.items[0].insertText).to.be.equal('test1');
13541354
});
13551355

1356+
it('should suggest defaultSnippets from additionalProperties', async () => {
1357+
const schema: JSONSchema = {
1358+
type: 'object',
1359+
properties: {
1360+
id: {
1361+
type: 'string',
1362+
},
1363+
},
1364+
additionalProperties: {
1365+
anyOf: [
1366+
{
1367+
type: 'string',
1368+
defaultSnippets: [{ label: 'snippet', body: 'snippetBody' }],
1369+
},
1370+
],
1371+
},
1372+
};
1373+
schemaProvider.addSchema(SCHEMA_ID, schema);
1374+
const content = 'value: |\n|';
1375+
const completion = await parseCaret(content);
1376+
1377+
expect(completion.items.map((i) => i.insertText)).to.be.deep.equal(['snippetBody']);
1378+
});
1379+
13561380
describe('should suggest prop of the object (based on not completed prop name)', () => {
13571381
const schema: JSONSchema = {
13581382
definitions: {

0 commit comments

Comments
 (0)