Skip to content

Commit

Permalink
fix(language-core): do not generate useTemplateRef parameter repeatedly
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Dec 18, 2024
1 parent b38a8db commit edf161a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/language-core/lib/codegen/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
const __VLS_intrinsicElements: __VLS_IntrinsicElements;
const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
const __VLS_unref: typeof import('${lib}').unref;
const __VLS_placeholder: any;
const __VLS_nativeElements = {
...{} as SVGElementTagNameMap,
Expand Down
21 changes: 15 additions & 6 deletions packages/language-core/lib/codegen/script/scriptSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,19 @@ function* generateSetupFunction(
}
const isTs = options.lang !== 'js' && options.lang !== 'jsx';
for (const { callExp, exp, arg } of scriptSetupRanges.useTemplateRef) {
const templateRefType = arg ? [
`__VLS_TemplateResult['refs'][`,
generateSfcBlockSection(scriptSetup, arg.start, arg.end, codeFeatures.navigation),
`]`
] : [`unknown`];
const templateRefType = arg
? [
`__VLS_TemplateResult['refs'][`,
generateSfcBlockSection(scriptSetup, arg.start, arg.end, codeFeatures.all),
`]`
]
: [`unknown`];
if (isTs) {
setupCodeModifies.push([
[
`<`,
...templateRefType,
`, keyof __VLS_TemplateResult['refs']>`
`>`
],
exp.end,
exp.end
Expand All @@ -257,6 +259,13 @@ function* generateSetupFunction(
callExp.end
]);
}
if (arg) {
setupCodeModifies.push([
[`(__VLS_placeholder)`],
arg.start,
arg.end
]);
}
}
setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);

Expand Down
16 changes: 8 additions & 8 deletions packages/language-server/tests/renaming.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,25 +939,25 @@ describe('Renaming', async () => {
"newText": "bar",
"range": {
"end": {
"character": 34,
"line": 7,
"character": 16,
"line": 2,
},
"start": {
"character": 31,
"line": 7,
"character": 13,
"line": 2,
},
},
},
{
"newText": "bar",
"range": {
"end": {
"character": 16,
"line": 2,
"character": 34,
"line": 7,
},
"start": {
"character": 13,
"line": 2,
"character": 31,
"line": 7,
},
},
},
Expand Down

0 comments on commit edf161a

Please sign in to comment.