Skip to content

Commit edf161a

Browse files
committed
fix(language-core): do not generate useTemplateRef parameter repeatedly
fixes #5009 (comment)
1 parent b38a8db commit edf161a

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

packages/language-core/lib/codegen/globalTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
1515
const __VLS_intrinsicElements: __VLS_IntrinsicElements;
1616
const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
1717
const __VLS_unref: typeof import('${lib}').unref;
18+
const __VLS_placeholder: any;
1819
1920
const __VLS_nativeElements = {
2021
...{} as SVGElementTagNameMap,

packages/language-core/lib/codegen/script/scriptSetup.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,19 @@ function* generateSetupFunction(
226226
}
227227
const isTs = options.lang !== 'js' && options.lang !== 'jsx';
228228
for (const { callExp, exp, arg } of scriptSetupRanges.useTemplateRef) {
229-
const templateRefType = arg ? [
230-
`__VLS_TemplateResult['refs'][`,
231-
generateSfcBlockSection(scriptSetup, arg.start, arg.end, codeFeatures.navigation),
232-
`]`
233-
] : [`unknown`];
229+
const templateRefType = arg
230+
? [
231+
`__VLS_TemplateResult['refs'][`,
232+
generateSfcBlockSection(scriptSetup, arg.start, arg.end, codeFeatures.all),
233+
`]`
234+
]
235+
: [`unknown`];
234236
if (isTs) {
235237
setupCodeModifies.push([
236238
[
237239
`<`,
238240
...templateRefType,
239-
`, keyof __VLS_TemplateResult['refs']>`
241+
`>`
240242
],
241243
exp.end,
242244
exp.end
@@ -257,6 +259,13 @@ function* generateSetupFunction(
257259
callExp.end
258260
]);
259261
}
262+
if (arg) {
263+
setupCodeModifies.push([
264+
[`(__VLS_placeholder)`],
265+
arg.start,
266+
arg.end
267+
]);
268+
}
260269
}
261270
setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
262271

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -939,25 +939,25 @@ describe('Renaming', async () => {
939939
"newText": "bar",
940940
"range": {
941941
"end": {
942-
"character": 34,
943-
"line": 7,
942+
"character": 16,
943+
"line": 2,
944944
},
945945
"start": {
946-
"character": 31,
947-
"line": 7,
946+
"character": 13,
947+
"line": 2,
948948
},
949949
},
950950
},
951951
{
952952
"newText": "bar",
953953
"range": {
954954
"end": {
955-
"character": 16,
956-
"line": 2,
955+
"character": 34,
956+
"line": 7,
957957
},
958958
"start": {
959-
"character": 13,
960-
"line": 2,
959+
"character": 31,
960+
"line": 7,
961961
},
962962
},
963963
},

0 commit comments

Comments
 (0)