Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-service): handle internal item key with leading slash correctly #4894

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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