refactor(language-service): stop tracking lastKwownProgram in CompilerFactory (#41517)
With the work done in #41291, the compiler always tracks the last known program, so there's no need to track the program in the compiler factory anymore. PR Close #41517
This commit is contained in:
parent
7a40d8cefd
commit
25e46c1fe4
|
@ -10,10 +10,8 @@ import {CompilationTicket, freshCompilationTicket, incrementalFromCompilerTicket
|
|||
import {NgCompilerOptions} from '@angular/compiler-cli/src/ngtsc/core/api';
|
||||
import {TrackedIncrementalBuildStrategy} from '@angular/compiler-cli/src/ngtsc/incremental';
|
||||
import {ProgramDriver} from '@angular/compiler-cli/src/ngtsc/program_driver';
|
||||
import * as ts from 'typescript/lib/tsserverlibrary';
|
||||
|
||||
import {LanguageServiceAdapter} from './adapters';
|
||||
import {isExternalTemplate} from './utils';
|
||||
|
||||
/**
|
||||
* Manages the `NgCompiler` instance which backs the language service, updating or replacing it as
|
||||
|
@ -27,7 +25,6 @@ import {isExternalTemplate} from './utils';
|
|||
export class CompilerFactory {
|
||||
private readonly incrementalStrategy = new TrackedIncrementalBuildStrategy();
|
||||
private compiler: NgCompiler|null = null;
|
||||
private lastKnownProgram: ts.Program|null = null;
|
||||
|
||||
constructor(
|
||||
private readonly adapter: LanguageServiceAdapter,
|
||||
|
@ -39,7 +36,7 @@ export class CompilerFactory {
|
|||
const program = this.programStrategy.getProgram();
|
||||
const modifiedResourceFiles = this.adapter.getModifiedResourceFiles() ?? new Set();
|
||||
|
||||
if (this.compiler !== null && program === this.lastKnownProgram) {
|
||||
if (this.compiler !== null && program === this.compiler.getCurrentProgram()) {
|
||||
if (modifiedResourceFiles.size > 0) {
|
||||
// Only resource files have changed since the last NgCompiler was created.
|
||||
const ticket = resourceChangeTicket(this.compiler, modifiedResourceFiles);
|
||||
|
@ -54,7 +51,7 @@ export class CompilerFactory {
|
|||
}
|
||||
|
||||
let ticket: CompilationTicket;
|
||||
if (this.compiler === null || this.lastKnownProgram === null) {
|
||||
if (this.compiler === null) {
|
||||
ticket = freshCompilationTicket(
|
||||
program, this.options, this.incrementalStrategy, this.programStrategy,
|
||||
/* perfRecorder */ null, true, true);
|
||||
|
@ -64,11 +61,6 @@ export class CompilerFactory {
|
|||
modifiedResourceFiles, /* perfRecorder */ null);
|
||||
}
|
||||
this.compiler = NgCompiler.fromTicket(ticket, this.adapter);
|
||||
this.lastKnownProgram = program;
|
||||
return this.compiler;
|
||||
}
|
||||
|
||||
registerLastKnownProgram() {
|
||||
this.lastKnownProgram = this.programStrategy.getProgram();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -266,7 +266,6 @@ export class LanguageService {
|
|||
return undefined;
|
||||
}
|
||||
const result = builder.getCompletionEntrySymbol(entryName);
|
||||
this.compilerFactory.registerLastKnownProgram();
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
@ -360,8 +359,6 @@ export class LanguageService {
|
|||
private withCompilerAndPerfTracing<T>(phase: PerfPhase, p: (compiler: NgCompiler) => T): T {
|
||||
const compiler = this.compilerFactory.getOrCreate();
|
||||
const result = compiler.perfRecorder.inPhase(phase, () => p(compiler));
|
||||
this.compilerFactory.registerLastKnownProgram();
|
||||
|
||||
const logger = this.project.projectService.logger;
|
||||
if (logger.hasLevel(ts.server.LogLevel.verbose)) {
|
||||
logger.perftrc(`LanguageService#${PerfPhase[phase]}: ${
|
||||
|
|
|
@ -207,7 +207,7 @@ describe('language service adapter', () => {
|
|||
});
|
||||
|
||||
function getLastKnownProgram(ngLS: LanguageService): ts.Program {
|
||||
const program = ngLS['compilerFactory']['lastKnownProgram'];
|
||||
const program = ngLS['compilerFactory']['compiler']?.getCurrentProgram();
|
||||
expect(program).toBeDefined();
|
||||
return program!;
|
||||
}
|
||||
|
|
|
@ -158,8 +158,6 @@ export class Project {
|
|||
const ngDiagnostics = ngCompiler.getDiagnosticsForFile(sf, OptimizeFor.WholeProgram);
|
||||
expect(ngDiagnostics.map(diag => diag.messageText)).toEqual([]);
|
||||
}
|
||||
|
||||
this.ngLS.compilerFactory.registerLastKnownProgram();
|
||||
}
|
||||
|
||||
expectNoTemplateDiagnostics(projectFileName: string, className: string): void {
|
||||
|
@ -172,7 +170,6 @@ export class Project {
|
|||
const component = getClassOrError(sf, className);
|
||||
|
||||
const diags = this.getTemplateTypeChecker().getDiagnosticsForComponent(component);
|
||||
this.ngLS.compilerFactory.registerLastKnownProgram();
|
||||
expect(diags.map(diag => diag.messageText)).toEqual([]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue