From 44b6815c64eef6227681a5c3870153328a794ee4 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, 25 Oct 2024 01:07:44 +0800 Subject: [PATCH] fix(language-service): handle internal item key with leading slash correctly (#4894) --- .../lib/plugins/vue-template.ts | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/language-service/lib/plugins/vue-template.ts b/packages/language-service/lib/plugins/vue-template.ts index c81ac7a5e0..78f7d7b11a 100644 --- a/packages/language-service/lib/plugins/vue-template.ts +++ b/packages/language-service/lib/plugins/vue-template.ts @@ -761,7 +761,7 @@ export function create( } } - completionList.items = completionList.items.filter(item => !specialTags.has(item.label)); + completionList.items = completionList.items.filter(item => !specialTags.has(parseLabel(item.label).name)); const htmlDocumentations = new Map(); @@ -773,12 +773,11 @@ export function create( } for (const item of completionList.items) { - const resolvedLabelKey = resolveItemKey(item.label); if (resolvedLabelKey) { const name = resolvedLabelKey.tag; - item.label = name; + item.label = resolvedLabelKey.leadingSlash ? '/' + name : name; if (item.textEdit) { item.textEdit.newText = name; }; @@ -838,6 +837,7 @@ export function create( type: 'componentProp', tag: '^', prop: propName, + leadingSlash: false }; } @@ -988,6 +988,15 @@ export function create( } }; +function parseLabel(label: string) { + const leadingSlash = label.startsWith('/'); + const name = label.slice(leadingSlash ? 1 : 0); + return { + name, + leadingSlash + } +} + function parseItemKey(type: InternalItemId, tag: string, prop: string) { return '__VLS_data=' + type + ',' + tag + ',' + prop; } @@ -997,12 +1006,14 @@ function isItemKey(key: string) { } function resolveItemKey(key: string) { - if (isItemKey(key)) { - const strs = key.slice('__VLS_data='.length).split(','); + const { leadingSlash, name } = parseLabel(key); + if (isItemKey(name)) { + const strs = name.slice('__VLS_data='.length).split(','); return { type: strs[0] as InternalItemId, tag: strs[1], prop: strs[2], + leadingSlash }; } }