Skip to content

Commit

Permalink
fix(language-core): correct inlay hints for v-bind with modifier (#4721)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX authored Aug 26, 2024
1 parent 333d73e commit 66920c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/language-core/lib/codegen/template/elementProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export function* generateElementProps(
...genereatePropExp(
options,
ctx,
prop,
prop.exp,
ctx.codeFeatures.all,
prop.arg?.loc.start.offset === prop.exp?.loc.start.offset,
Expand Down Expand Up @@ -266,6 +267,7 @@ export function* generateElementProps(
function* genereatePropExp(
options: TemplateCodegenOptions,
ctx: TemplateCodegenContext,
prop: CompilerDOM.DirectiveNode,
exp: CompilerDOM.SimpleExpressionNode | undefined,
features: VueCodeInformation,
isShorthand: boolean,
Expand Down Expand Up @@ -299,11 +301,11 @@ function* genereatePropExp(
if (enableCodeFeatures) {
ctx.inlayHints.push({
blockName: 'template',
offset: exp.loc.end.offset,
offset: prop.loc.end.offset,
setting: 'vue.inlayHints.vBindShorthand',
label: `="${propVariableName}"`,
tooltip: [
`This is a shorthand for \`${exp.loc.source}="${propVariableName}"\`.`,
`This is a shorthand for \`${prop.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
16 changes: 16 additions & 0 deletions packages/language-server/tests/inlayHints.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ describe('Definitions', async () => {
`);
});

it('#4720', async () => {
expect(
await requestInlayHintsResult('fixture.vue', 'vue', `
<template>
<div :foo.attr></div>
</template>
`)
).toMatchInlineSnapshot(`
"
<template>
<div :foo.attr/* ="foo" */></div>
</template>
"
`);
});

const openedDocuments: TextDocument[] = [];

afterEach(async () => {
Expand Down

0 comments on commit 66920c8

Please sign in to comment.