Skip to content
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
19 changes: 18 additions & 1 deletion src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,21 @@ export class YamlCompletion {
node = pair.value;
}
}
} else if (isSeq(node)) {
if (lineContent.charAt(position.character - 1) !== '-') {
const map = this.createTempObjNode(currentWord, node, currentDoc);
map.items = [];
// eslint-disable-next-line no-self-assign
currentDoc.internalDocument = currentDoc.internalDocument;
for (const pair of node.items) {
if (isMap(pair)) {
pair.items.forEach((value) => {
map.items.push(value);
});
}
}
node = map;
}
}
}
}
Expand Down Expand Up @@ -691,7 +706,9 @@ export class YamlCompletion {
}
for (const schema of matchingSchemas) {
if (
((schema.node.internalNode === node && !matchOriginal) || (schema.node.internalNode === originalNode && !hasColon)) &&
((schema.node.internalNode === node && !matchOriginal) ||
(schema.node.internalNode === originalNode && !hasColon) ||
(schema.node.parent?.internalNode === originalNode && !hasColon)) &&
!schema.inverted
) {
this.collectDefaultSnippets(schema.schema, separatorAfter, collector, {
Expand Down
33 changes: 33 additions & 0 deletions test/autoCompletionFix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,39 @@ describe('Auto Completion Fix Tests', () => {
);
});

it('completion with array objects', async () => {
languageService.addSchema(SCHEMA_ID, {
type: 'array',
items: {
type: 'object',
properties: {
prop1: {
type: 'string',
},
prop2: {
type: 'string',
},
prop3: {
type: 'string',
},
},
},
});
const content = '- prop1: a\n | |'; // len: 12, pos: 11
const completion = await parseCaret(content);
expect(completion.items).lengthOf(2);
expect(completion.items[0]).eql(
createExpectedCompletion('prop2', 'prop2: ', 1, 3, 1, 4, 10, 2, {
documentation: '',
})
);
expect(completion.items[1]).eql(
createExpectedCompletion('prop3', 'prop3: ', 1, 3, 1, 4, 10, 2, {
documentation: '',
})
);
});

it('should show completion on array empty array item', async () => {
languageService.addSchema(SCHEMA_ID, {
type: 'array',
Expand Down