Skip to content

Commit

Permalink
fix(language-service): handle internal item key with leading slash co…
Browse files Browse the repository at this point in the history
…rrectly (#4894)
  • Loading branch information
KazariEX authored Oct 24, 2024
1 parent 4efc6fa commit 44b6815
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/language-service/lib/plugins/vue-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>();

Expand All @@ -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;
};
Expand Down Expand Up @@ -838,6 +837,7 @@ export function create(
type: 'componentProp',
tag: '^',
prop: propName,
leadingSlash: false
};
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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
};
}
}
Expand Down

0 comments on commit 44b6815

Please sign in to comment.