Skip to content

Commit 66920c8

Browse files
authored
fix(language-core): correct inlay hints for v-bind with modifier (#4721)
1 parent 333d73e commit 66920c8

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/language-core/lib/codegen/template/elementProps.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export function* generateElementProps(
143143
...genereatePropExp(
144144
options,
145145
ctx,
146+
prop,
146147
prop.exp,
147148
ctx.codeFeatures.all,
148149
prop.arg?.loc.start.offset === prop.exp?.loc.start.offset,
@@ -266,6 +267,7 @@ export function* generateElementProps(
266267
function* genereatePropExp(
267268
options: TemplateCodegenOptions,
268269
ctx: TemplateCodegenContext,
270+
prop: CompilerDOM.DirectiveNode,
269271
exp: CompilerDOM.SimpleExpressionNode | undefined,
270272
features: VueCodeInformation,
271273
isShorthand: boolean,
@@ -299,11 +301,11 @@ function* genereatePropExp(
299301
if (enableCodeFeatures) {
300302
ctx.inlayHints.push({
301303
blockName: 'template',
302-
offset: exp.loc.end.offset,
304+
offset: prop.loc.end.offset,
303305
setting: 'vue.inlayHints.vBindShorthand',
304306
label: `="${propVariableName}"`,
305307
tooltip: [
306-
`This is a shorthand for \`${exp.loc.source}="${propVariableName}"\`.`,
308+
`This is a shorthand for \`${prop.loc.source}="${propVariableName}"\`.`,
307309
'To hide this hint, set `vue.inlayHints.vBindShorthand` to `false` in IDE settings.',
308310
'[More info](https://github.com/vuejs/core/pull/9451)',
309311
].join('\n\n'),

packages/language-server/tests/inlayHints.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@ describe('Definitions', async () => {
174174
`);
175175
});
176176

177+
it('#4720', async () => {
178+
expect(
179+
await requestInlayHintsResult('fixture.vue', 'vue', `
180+
<template>
181+
<div :foo.attr></div>
182+
</template>
183+
`)
184+
).toMatchInlineSnapshot(`
185+
"
186+
<template>
187+
<div :foo.attr/* ="foo" */></div>
188+
</template>
189+
"
190+
`);
191+
});
192+
177193
const openedDocuments: TextDocument[] = [];
178194

179195
afterEach(async () => {

0 commit comments

Comments
 (0)