Skip to content

Commit e6f4857

Browse files
Merge branch 'main' into crd
2 parents af900c9 + e5dcce0 commit e6f4857

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/languageservice/services/yamlCompletion.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,8 @@ export class YamlCompletion {
925925
if (propertySchema) {
926926
this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types, 'value');
927927
}
928-
} else if (s.schema.additionalProperties) {
928+
}
929+
if (s.schema.additionalProperties) {
929930
this.addSchemaValueCompletions(s.schema.additionalProperties, separatorAfter, collector, types, 'value');
930931
}
931932
}
@@ -1205,7 +1206,7 @@ export class YamlCompletion {
12051206
insertText = `\${${insertIndex++}:0}`;
12061207
break;
12071208
case 'string':
1208-
insertText = `\${${insertIndex++}:""}`;
1209+
insertText = `\${${insertIndex++}}`;
12091210
break;
12101211
case 'object':
12111212
{

test/autoCompletion.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ describe('Auto Completion Tests', () => {
10471047
const completion = parseSetup(content, content.lastIndexOf('Ba') + 2); // pos: 3+2
10481048
completion
10491049
.then(function (result) {
1050-
assert.strictEqual('fooBar:\n - ${1:""}', result.items[0].insertText);
1050+
assert.strictEqual('fooBar:\n - ${1}', result.items[0].insertText);
10511051
})
10521052
.then(done, done);
10531053
});

test/autoCompletionFix.test.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ objB:
482482

483483
expect(completion.items.length).equal(1);
484484
expect(completion.items[0]).to.be.deep.equal(
485-
createExpectedCompletion('objectWithArray', 'objectWithArray:\n - ${1:""}', 1, 4, 1, 4, 10, 2, {
485+
createExpectedCompletion('objectWithArray', 'objectWithArray:\n - ${1}', 1, 4, 1, 4, 10, 2, {
486486
documentation: '',
487487
})
488488
);
@@ -1183,6 +1183,30 @@ objB:
11831183
expect(completion.items[0].insertText).to.be.equal('test1');
11841184
});
11851185

1186+
it('should suggest defaultSnippets from additionalProperties', async () => {
1187+
const schema: JSONSchema = {
1188+
type: 'object',
1189+
properties: {
1190+
id: {
1191+
type: 'string',
1192+
},
1193+
},
1194+
additionalProperties: {
1195+
anyOf: [
1196+
{
1197+
type: 'string',
1198+
defaultSnippets: [{ label: 'snippet', body: 'snippetBody' }],
1199+
},
1200+
],
1201+
},
1202+
};
1203+
schemaProvider.addSchema(SCHEMA_ID, schema);
1204+
const content = 'value: |\n|';
1205+
const completion = await parseCaret(content);
1206+
1207+
expect(completion.items.map((i) => i.insertText)).to.be.deep.equal(['snippetBody']);
1208+
});
1209+
11861210
describe('should suggest prop of the object (based on not completed prop name)', () => {
11871211
const schema: JSONSchema = {
11881212
definitions: {

0 commit comments

Comments
 (0)