From 6e69a357ffcc653b5a2981051220f0f223fef3a4 Mon Sep 17 00:00:00 2001 From: Jiayin Pei Date: Wed, 29 Aug 2018 16:38:27 +0800 Subject: [PATCH] support intellisense default value --- .../services/yamlCompletion.ts | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/languageservice/services/yamlCompletion.ts b/src/languageservice/services/yamlCompletion.ts index 704426cb..8a3e5e74 100644 --- a/src/languageservice/services/yamlCompletion.ts +++ b/src/languageservice/services/yamlCompletion.ts @@ -528,37 +528,42 @@ export class YAMLCompletion { let value; let nValueProposals = 0; if (propertySchema) { - if (nValueProposals === 0) { - var type = Array.isArray(propertySchema.type) ? propertySchema.type[0] : propertySchema.type; - if (!type) { - if (propertySchema.properties) { - type = 'object'; - } else if (propertySchema.items) { - type = 'array'; + if (propertySchema.default !== undefined) { + value = ` \${1:${propertySchema.default}}` + } + else { + if (nValueProposals === 0) { + var type = Array.isArray(propertySchema.type) ? propertySchema.type[0] : propertySchema.type; + if (!type) { + if (propertySchema.properties) { + type = 'object'; + } else if (propertySchema.items) { + type = 'array'; + } + } + switch (type) { + case 'boolean': + value = ' $1'; + break; + case 'string': + value = ' $1'; + break; + case 'object': + value = '\n\t'; + break; + case 'array': + value = '\n\t- '; + break; + case 'number': + case 'integer': + value = ' ${1:0}'; + break; + case 'null': + value = ' ${1:null}'; + break; + default: + return propertyText; } - } - switch (type) { - case 'boolean': - value = ' $1'; - break; - case 'string': - value = ' $1'; - break; - case 'object': - value = '\n\t'; - break; - case 'array': - value = '\n\t- '; - break; - case 'number': - case 'integer': - value = ' ${1:0}'; - break; - case 'null': - value = ' ${1:null}'; - break; - default: - return propertyText; } } }