Skip to content

Commit 44b6815

Browse files
authored
fix(language-service): handle internal item key with leading slash correctly (#4894)
1 parent 4efc6fa commit 44b6815

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

packages/language-service/lib/plugins/vue-template.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ export function create(
761761
}
762762
}
763763

764-
completionList.items = completionList.items.filter(item => !specialTags.has(item.label));
764+
completionList.items = completionList.items.filter(item => !specialTags.has(parseLabel(item.label).name));
765765

766766
const htmlDocumentations = new Map<string, string>();
767767

@@ -773,12 +773,11 @@ export function create(
773773
}
774774

775775
for (const item of completionList.items) {
776-
777776
const resolvedLabelKey = resolveItemKey(item.label);
778777

779778
if (resolvedLabelKey) {
780779
const name = resolvedLabelKey.tag;
781-
item.label = name;
780+
item.label = resolvedLabelKey.leadingSlash ? '/' + name : name;
782781
if (item.textEdit) {
783782
item.textEdit.newText = name;
784783
};
@@ -838,6 +837,7 @@ export function create(
838837
type: 'componentProp',
839838
tag: '^',
840839
prop: propName,
840+
leadingSlash: false
841841
};
842842
}
843843

@@ -988,6 +988,15 @@ export function create(
988988
}
989989
};
990990

991+
function parseLabel(label: string) {
992+
const leadingSlash = label.startsWith('/');
993+
const name = label.slice(leadingSlash ? 1 : 0);
994+
return {
995+
name,
996+
leadingSlash
997+
}
998+
}
999+
9911000
function parseItemKey(type: InternalItemId, tag: string, prop: string) {
9921001
return '__VLS_data=' + type + ',' + tag + ',' + prop;
9931002
}
@@ -997,12 +1006,14 @@ function isItemKey(key: string) {
9971006
}
9981007

9991008
function resolveItemKey(key: string) {
1000-
if (isItemKey(key)) {
1001-
const strs = key.slice('__VLS_data='.length).split(',');
1009+
const { leadingSlash, name } = parseLabel(key);
1010+
if (isItemKey(name)) {
1011+
const strs = name.slice('__VLS_data='.length).split(',');
10021012
return {
10031013
type: strs[0] as InternalItemId,
10041014
tag: strs[1],
10051015
prop: strs[2],
1016+
leadingSlash
10061017
};
10071018
}
10081019
}

0 commit comments

Comments
 (0)