Skip to content

Commit

Permalink
fix: default 非 string 时的报错
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 committed Sep 5, 2024
1 parent a45a635 commit a69cf6b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ function getEffectWord(preText: string) {
function getHoverAttribute(attributeList: any[], attr: string) {
return attributeList.filter(a =>
toCamel(a?.params?.[1]?.replace('v-model:', '') || '') === toCamel(attr),
).map(i => `- ${i.label}`).join('\n\n')
).map(i => `- ${i.details}`).join('\n\n')
}

const IMPORT_UI_REG = /import\s+\{([^}]+)\}\s+from\s+['"]([^"']+)['"]/g
Expand Down
11 changes: 8 additions & 3 deletions src/ui/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export function propsReducer(options: PropsOptions) {

detail.push(`## ${uiName} [${item.name}]`)

if (value.default !== undefined && value.default !== '')
detail.push(`#### 💎 ${isZh ? '默认值' : 'default'}: ***\`${value.default.toString().replace(/[`\n]/g, '')}\`***`)
if (value.default !== undefined && value.default !== '') {
value.default = String(value.default)
detail.push(`#### 💎 ${isZh ? '默认值' : 'default'}: ***\`${value.default.replace(/[`\n]/g, '')}\`***`)
}

if (value.description) {
if (isZh)
Expand Down Expand Up @@ -120,9 +122,11 @@ export function propsReducer(options: PropsOptions) {
else
snippet = `${key}="\${1}"`
}
content += `\n- ${isZh ? (value.description_zh || value.description) : value.description}\n- ${value.default ? ` ${isZh ? '默认' : 'default'}${value.default.replace(/\n/g, '')}` : ''}`
const details = `${content}\n- ${isZh ? (value.description_zh || value.description) : value.description}\n- ${value.default ? ` ${isZh ? '默认' : 'default'}${value.default.replace(/\n/g, '')}` : ''}`
content += ` ${isZh ? (value.description_zh || value.description) : value.description} ${value.default ? ` ${isZh ? '默认' : 'default'}${value.default.replace(/\n/g, '')}` : ''}`
data.push(createCompletionItem({
content,
details,
snippet,
type,
documentation,
Expand Down Expand Up @@ -199,6 +203,7 @@ export function propsReducer(options: PropsOptions) {
snippet = `${_name}={\${1:${_name}}}`
content = `${_name}={${_name}}`
}

content += ` ${isZh ? (description_zh || description) : description}${params ? ` ${isZh ? '参数' : 'params'}${params}` : ''}`
const documentation = new vscode.MarkdownString()
documentation.isTrusted = true
Expand Down

0 comments on commit a69cf6b

Please sign in to comment.