Skip to content

Commit

Permalink
Merge pull request #751 from jigx-com/fix/object-indenting-main
Browse files Browse the repository at this point in the history
fix: autocomplete indent on object within an array
  • Loading branch information
msivasubramaniaan authored Jul 31, 2022
2 parents e564235 + 1fb8ef0 commit 1f1d47d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ export class YamlCompletion {
if (arrayInsertLines.length > 1) {
for (let index = 1; index < arrayInsertLines.length; index++) {
const element = arrayInsertLines[index];
arrayInsertLines[index] = `${indent}${this.indentation} ${element.trimLeft()}`;
arrayInsertLines[index] = ` ${element}`;
}
arrayTemplate = arrayInsertLines.join('\n');
}
Expand Down
48 changes: 48 additions & 0 deletions test/autoCompletionFix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,54 @@ objB:
})
);
});
it('Autocomplete indent on array object when parent is array of an array', async () => {
languageService.addSchema(SCHEMA_ID, {
type: 'object',
properties: {
array1: {
type: 'array',
items: {
type: 'object',
required: ['thing1'],
properties: {
thing1: {
type: 'object',
required: ['array2'],
properties: {
array2: {
type: 'array',
items: {
type: 'object',
required: ['thing2', 'type'],
properties: {
type: {
type: 'string',
},
thing2: {
type: 'object',
required: ['item1', 'item2'],
properties: {
item1: { type: 'string' },
item2: { type: 'string' },
},
},
},
},
},
},
},
},
},
},
},
});
const content = 'array1:\n - ';
const completion = await parseSetup(content, 1, 4);

expect(completion.items[0].insertText).to.be.equal(
'thing1:\n array2:\n - type: $1\n thing2:\n item1: $2\n item2: $3'
);
});
describe('array indent on different index position', () => {
const schema = {
type: 'object',
Expand Down

0 comments on commit 1f1d47d

Please sign in to comment.