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: completion with default snippet when node is array #387

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ export class YAMLCompletion extends JSONCompletion {
const matchingSchemas = doc.getMatchingSchemas(schema.schema);
matchingSchemas.forEach((s) => {
if (s.node === node && !s.inverted && s.schema) {
this.collectDefaultSnippets(s.schema, separatorAfter, collector, {
newLineFirst: false,
indentFirstObject: false,
shouldIndentWithTab: false,
});
if (s.schema.items) {
if (Array.isArray(s.schema.items)) {
const index = super.findItemAtOffset(node, document, offset);
Expand Down
15 changes: 13 additions & 2 deletions test/defaultSnippets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,20 @@ suite('Default Snippet Tests', () => {
.then(done, done);
});

it('Snippet in array schema should autocomplete correctly after ', (done) => {
it('Snippet in array schema should autocomplete correctly on array level ', (done) => {
const content = 'array:\n - item1: asd\n item2: asd\n ';
const completion = parseSetup(content, content.length);
completion
.then(function (result) {
assert.equal(result.items.length, 1);
assert.equal(result.items[0].insertText, '- item1: $1\n item2: $2');
assert.equal(result.items[0].label, 'My array item');
})
.then(done, done);
});
it('Snippet in array schema should autocomplete correctly inside array item ', (done) => {
const content = 'array:\n - item1: asd\n item2: asd\n ';
const completion = parseSetup(content, 40);
const completion = parseSetup(content, content.length);
completion
.then(function (result) {
assert.equal(result.items.length, 1);
Expand Down