Skip to content

Commit

Permalink
Merge branch 'main' into 807-custom-tags-null-check
Browse files Browse the repository at this point in the history
  • Loading branch information
msivasubramaniaan authored May 28, 2024
2 parents 75bf3ae + e5dcce0 commit f50b521
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -1205,7 +1206,7 @@ export class YamlCompletion {
insertText = `\${${insertIndex++}:0}`;
break;
case 'string':
insertText = `\${${insertIndex++}:""}`;
insertText = `\${${insertIndex++}}`;
break;
case 'object':
{
Expand Down
2 changes: 1 addition & 1 deletion test/autoCompletion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ describe('Auto Completion Tests', () => {
const completion = parseSetup(content, content.lastIndexOf('Ba') + 2); // pos: 3+2
completion
.then(function (result) {
assert.strictEqual('fooBar:\n - ${1:""}', result.items[0].insertText);
assert.strictEqual('fooBar:\n - ${1}', result.items[0].insertText);
})
.then(done, done);
});
Expand Down
26 changes: 25 additions & 1 deletion test/autoCompletionFix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ objB:

expect(completion.items.length).equal(1);
expect(completion.items[0]).to.be.deep.equal(
createExpectedCompletion('objectWithArray', 'objectWithArray:\n - ${1:""}', 1, 4, 1, 4, 10, 2, {
createExpectedCompletion('objectWithArray', 'objectWithArray:\n - ${1}', 1, 4, 1, 4, 10, 2, {
documentation: '',
})
);
Expand Down 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 f50b521

Please sign in to comment.