diff --git a/packages/language-core/lib/codegen/script/index.ts b/packages/language-core/lib/codegen/script/index.ts index ec48ad0a81..dd6f4093ef 100644 --- a/packages/language-core/lib/codegen/script/index.ts +++ b/packages/language-core/lib/codegen/script/index.ts @@ -45,6 +45,7 @@ export interface ScriptCodegenOptions { scriptSetupRanges: ScriptSetupRanges | undefined; templateCodegen: TemplateCodegenContext & { codes: Code[]; } | undefined; globalTypes: boolean; + typeCheckOnly: boolean; getGeneratedLength: () => number; linkedCodeMappings: Mapping[]; } diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts index 8d0dbc85a3..d742be2e59 100644 --- a/packages/language-core/lib/codegen/script/template.ts +++ b/packages/language-core/lib/codegen/script/template.ts @@ -22,7 +22,7 @@ export function* generateTemplate( else { yield `function __VLS_template() {${newLine}`; } - const templateCodegenCtx = createTemplateCodegenContext(new Set()); + const templateCodegenCtx = createTemplateCodegenContext({ scriptSetupBindingNames: new Set(), typeCheckOnly: options.typeCheckOnly }); yield* generateCtx(options, ctx, isClassComponent); yield* generateTemplateContext(options, templateCodegenCtx); yield* generateExportOptions(options); diff --git a/packages/language-core/lib/codegen/template/context.ts b/packages/language-core/lib/codegen/template/context.ts index 54b3c5ef03..5ef1666545 100644 --- a/packages/language-core/lib/codegen/template/context.ts +++ b/packages/language-core/lib/codegen/template/context.ts @@ -57,7 +57,7 @@ const _codeFeatures = { export type TemplateCodegenContext = ReturnType; -export function createTemplateCodegenContext(scriptSetupBindingNames: TemplateCodegenOptions['scriptSetupBindingNames']) { +export function createTemplateCodegenContext(options: Pick) { let ignoredError = false; let expectErrorToken: { errors: number; @@ -184,6 +184,9 @@ export function createTemplateCodegenContext(scriptSetupBindingNames: TemplateCo } }, generateAutoImportCompletion: function* (): Generator { + if (options.typeCheckOnly) { + return; + } const all = [...accessExternalVariables.entries()]; if (!all.some(([_, offsets]) => offsets.size)) { return; @@ -192,7 +195,7 @@ export function createTemplateCodegenContext(scriptSetupBindingNames: TemplateCo yield `[`; for (const [varName, offsets] of all) { for (const offset of offsets) { - if (scriptSetupBindingNames.has(varName)) { + if (options.scriptSetupBindingNames.has(varName)) { // #3409 yield [ varName, diff --git a/packages/language-core/lib/codegen/template/index.ts b/packages/language-core/lib/codegen/template/index.ts index aad7c0a914..cba801ccb6 100644 --- a/packages/language-core/lib/codegen/template/index.ts +++ b/packages/language-core/lib/codegen/template/index.ts @@ -21,7 +21,7 @@ export interface TemplateCodegenOptions { } export function* generateTemplate(options: TemplateCodegenOptions): Generator { - const ctx = createTemplateCodegenContext(options.scriptSetupBindingNames); + const ctx = createTemplateCodegenContext(options); if (options.slotsAssignName) { ctx.addLocalVariable(options.slotsAssignName); diff --git a/packages/language-core/lib/plugins/vue-tsx.ts b/packages/language-core/lib/plugins/vue-tsx.ts index b8a641ff23..dd99302a86 100644 --- a/packages/language-core/lib/plugins/vue-tsx.ts +++ b/packages/language-core/lib/plugins/vue-tsx.ts @@ -152,6 +152,7 @@ function createTsx( templateCodegen: _template, compilerOptions: ctx.compilerOptions, vueCompilerOptions: ctx.vueCompilerOptions, + typeCheckOnly: ctx.typeCheckOnly, getGeneratedLength: () => generatedLength, linkedCodeMappings, });