From 98b77590efb06301d2a2d5978ab7515e8637ac40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=B1=E5=90=B9=E8=89=B2=E5=BE=A1=E5=AE=88?= <85992002+KazariEX@users.noreply.github.com> Date: Fri, 9 Aug 2024 13:53:26 +0800 Subject: [PATCH] fix(language-service): completion documentations for binding attributes (#4667) --- packages/language-service/lib/plugins/data.ts | 5 ++++- .../language-service/lib/plugins/vue-template.ts | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/language-service/lib/plugins/data.ts b/packages/language-service/lib/plugins/data.ts index 06a63e33dd..d4f0ffce19 100644 --- a/packages/language-service/lib/plugins/data.ts +++ b/packages/language-service/lib/plugins/data.ts @@ -39,7 +39,10 @@ export function loadTemplateData(lang: string) { for (const attr of [...data.globalAttributes ?? []]) { if (!attr.name.startsWith('v-')) { - data.globalAttributes?.push({ ...attr, name: `:${attr.name}` }); + data.globalAttributes?.push( + { ...attr, name: `:${attr.name}` }, + { ...attr, name: `v-bind:${attr.name}` } + ); } } diff --git a/packages/language-service/lib/plugins/vue-template.ts b/packages/language-service/lib/plugins/vue-template.ts index 7d67146123..57a2c24125 100644 --- a/packages/language-service/lib/plugins/vue-template.ts +++ b/packages/language-service/lib/plugins/vue-template.ts @@ -729,6 +729,8 @@ export function create( } } + const originals = new Map(); + for (const item of completionList.items) { if (specialTags.has(item.label)) { @@ -755,7 +757,18 @@ export function create( const itemId = itemIdKey ? readInternalItemId(itemIdKey) : undefined; if (itemId) { - item.documentation = undefined; + let label = hyphenate(itemId.args[1]); + if (label.startsWith('on-')) { + label = 'on' + label.slice('on-'.length); + } + else if (itemId.type === 'componentEvent') { + label = 'on' + label; + } + const original = originals.get(label); + item.documentation = original?.documentation; + } + else if (!originals.has(item.label)) { + originals.set(item.label, item); } if (item.kind === 10 satisfies typeof vscode.CompletionItemKind.Property && lastCompletionComponentNames.has(hyphenateTag(item.label))) {