Skip to content

Commit

Permalink
Skip generateAutoImportCompletion when typeCheckOnly is true
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Aug 22, 2024
1 parent 32c6838 commit 66dc70f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/language-core/lib/codegen/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface ScriptCodegenOptions {
scriptSetupRanges: ScriptSetupRanges | undefined;
templateCodegen: TemplateCodegenContext & { codes: Code[]; } | undefined;
globalTypes: boolean;
typeCheckOnly: boolean;
getGeneratedLength: () => number;
linkedCodeMappings: Mapping[];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/script/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions packages/language-core/lib/codegen/template/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const _codeFeatures = {

export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenContext>;

export function createTemplateCodegenContext(scriptSetupBindingNames: TemplateCodegenOptions['scriptSetupBindingNames']) {
export function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames' | 'typeCheckOnly'>) {
let ignoredError = false;
let expectErrorToken: {
errors: number;
Expand Down Expand Up @@ -184,6 +184,9 @@ export function createTemplateCodegenContext(scriptSetupBindingNames: TemplateCo
}
},
generateAutoImportCompletion: function* (): Generator<Code> {
if (options.typeCheckOnly) {
return;
}
const all = [...accessExternalVariables.entries()];
if (!all.some(([_, offsets]) => offsets.size)) {
return;
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface TemplateCodegenOptions {
}

export function* generateTemplate(options: TemplateCodegenOptions): Generator<Code, TemplateCodegenContext> {
const ctx = createTemplateCodegenContext(options.scriptSetupBindingNames);
const ctx = createTemplateCodegenContext(options);

if (options.slotsAssignName) {
ctx.addLocalVariable(options.slotsAssignName);
Expand Down
1 change: 1 addition & 0 deletions packages/language-core/lib/plugins/vue-tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ function createTsx(
templateCodegen: _template,
compilerOptions: ctx.compilerOptions,
vueCompilerOptions: ctx.vueCompilerOptions,
typeCheckOnly: ctx.typeCheckOnly,
getGeneratedLength: () => generatedLength,
linkedCodeMappings,
});
Expand Down

0 comments on commit 66dc70f

Please sign in to comment.