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-core): inlay hints for <component :is> and <slot :name> #4661

Merged
merged 12 commits into from
Oct 23, 2024
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/main' into fix/issue-4294
  • Loading branch information
KazariEX committed Aug 11, 2024
commit 099dc98e2124710581c864236bac7e3134aedba1
14 changes: 12 additions & 2 deletions packages/language-core/lib/codegen/template/elementProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,18 @@ function* genereatePropExp(
exp.loc.start.offset,
features
);
if (inlayHints) {
yield generateVBindShorthandInlayHint(exp.loc, propVariableName);
if (enableCodeFeatures) {
ctx.inlayHints.push({
blockName: 'template',
offset: exp.loc.end.offset,
setting: 'vue.inlayHints.vBindShorthand',
label: `="${propVariableName}"`,
tooltip: [
`This is a shorthand for \`${exp.loc.source}="${propVariableName}"\`.`,
'To hide this hint, set `vue.inlayHints.vBindShorthand` to `false` in IDE settings.',
'[More info](https://github.com/vuejs/core/pull/9451)',
].join('\n\n'),
});
}
}
}
Expand Down
43 changes: 8 additions & 35 deletions packages/language-core/lib/codegen/template/interpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,14 @@ export function* generateInterpolation(
offset = 0;
}
if (start !== undefined && data !== undefined) {
const startOffset = start + offset;
const endOffset = startOffset + section.length;

const filtered = inlayHints.filter(
([, pos]) => pos > startOffset && pos <= endOffset
);

if (filtered.length) {
yield generateSection(section, startOffset, startOffset, filtered[0][1]);
while (filtered.length) {
const [inlayHint, pos] = filtered.shift()!;
yield inlayHint;
if (filtered.length) {
const nextStart = filtered[0][1];
yield generateSection(section, startOffset, pos, nextStart);
}
else {
yield generateSection(section, startOffset, pos, endOffset);
}
}
}
else {
yield generateSection(section, startOffset, startOffset, endOffset);
}

function generateSection(text: string, startOffset: number, from: number, to: number) {
return [
text.slice(from - startOffset, to - startOffset),
'template',
from,
onlyError
? ctx.codeFeatures.verification
: typeof data === 'function' ? data() : data,
] as Code;
}
yield [
section,
'template',
start + offset,
onlyError
? ctx.codeFeatures.verification
: typeof data === 'function' ? data(start + offset) : data,
];
}
else {
yield section;
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.