Skip to content

Commit 67ce9eb

Browse files
committed
Handle default booleans and integers properly in required properties completion
Before, default values that were falsey would complete to the empty string (specifically when using the complete all required properties feature; single property completion was already working). Now, they should complete to the correct string value. Fixes redhat-developer#1205 Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent ce38c3b commit 67ce9eb

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/languageservice/services/yamlCompletion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,8 @@ export class YamlCompletion {
11641164
case 'number':
11651165
case 'integer':
11661166
case 'anyOf': {
1167-
let value = propertySchema.default || propertySchema.const;
1168-
if (value) {
1167+
let value = propertySchema.default !== undefined ? propertySchema.default : propertySchema.const;
1168+
if (value !== undefined) {
11691169
if (type === 'string') {
11701170
value = toYamlStringScalar(value);
11711171
}

test/autoCompletion.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,6 +3185,43 @@ describe('Auto Completion Tests', () => {
31853185
})
31863186
);
31873187
});
3188+
it('object completion with default boolean and default integer', async () => {
3189+
schemaProvider.addSchema(SCHEMA_ID, {
3190+
type: 'object',
3191+
properties: {
3192+
env: {
3193+
type: 'object',
3194+
properties: {
3195+
val: {
3196+
type: 'boolean',
3197+
default: false,
3198+
},
3199+
},
3200+
required: ['val'],
3201+
},
3202+
salad: {
3203+
type: 'integer',
3204+
default: 0,
3205+
},
3206+
},
3207+
required: ['env', 'salad'],
3208+
});
3209+
3210+
const content = '';
3211+
const result = await parseSetup(content, 0);
3212+
3213+
assert.equal(result.items.length, 3);
3214+
assert.deepEqual(
3215+
result.items[1],
3216+
createExpectedCompletion('object', 'env:\n val: ${1:false}\nsalad: 0', 0, 0, 0, 0, 7, 2, {
3217+
sortText: '_object',
3218+
documentation: {
3219+
kind: 'markdown',
3220+
value: '```yaml\nenv:\n val: false\nsalad: 0\n```',
3221+
},
3222+
})
3223+
);
3224+
});
31883225
describe('Select parent skeleton first', () => {
31893226
beforeEach(() => {
31903227
const languageSettingsSetup = new ServiceSetup().withCompletion();

0 commit comments

Comments
 (0)