Skip to content

Commit

Permalink
Merge pull request #233 from redhat-developer/defaultSnippets-array-fix
Browse files Browse the repository at this point in the history
Fix the way defaultSnippets behaves on array items
  • Loading branch information
JPinkney authored Feb 4, 2020
2 parents 6a534d4 + ad3c8f8 commit be89eea
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ export class YAMLCompletion extends JSONCompletion {
}
}

// Covers the case when we are showing a snippet in an array
if (node.type === 'object' && node.parent && node.parent.type === 'array' && s.schema.type !== 'object') {
if (node.parent && s.node === node.parent && node.type === 'object' && s.schema.defaultSnippets) {
// For some reason the first item in the array needs to be treated differently, otherwise
// the indentation will not be correct
if (node.properties.length === 1) {
Expand Down
10 changes: 0 additions & 10 deletions test/defaultSnippets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ suite('Default Snippet Tests', () => {
}).then(done, done);
});

it('Snippet in array schema should autocomplete on next line with depth', done => {
const content = 'array:\n - item1:\n - ';
const completion = parseSetup(content, 24);
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 after ', done => {
const content = 'array:\n - item1: asd\n item2: asd\n ';
const completion = parseSetup(content, 40);
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/defaultSnippets.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"body": { "item1": "$1", "item2": "$2" }
}
],
"items": {
"items": {
"item1": {
"$ref": "#/properties/array"
"type": "string"
},
"item2": {
"$ref": "#/properties/array"
"type": "string"
}
}
},
Expand Down

0 comments on commit be89eea

Please sign in to comment.