Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: autocomplete indent on object within an array #5

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,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}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two spaces are there because of the standard indentation?
if yes, there should be ${this.indentation} instead
because indentation could be 4 spaces, tabulator, 2 spaces

}
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