feat(language-service): [ivy] wrap ngtsc to handle typecheck files (#36930)
This commit adds a Compiler interface that wraps the actual ngtsc compiler. The language-service specific compiler manages multiple typecheck files using the Project interface, creating and adding ScriptInfos as necessary. This commit also adds `overrideInlineTemplate()` method to the mock service so that we could test the Compiler diagnostics feature. PR Close #36930
This commit is contained in:

committed by
Misko Hevery

parent
82a3bd5e8b
commit
1142c378fd
@ -8,17 +8,28 @@
|
||||
|
||||
import {CompilerOptions, createNgCompilerOptions} from '@angular/compiler-cli';
|
||||
import * as ts from 'typescript/lib/tsserverlibrary';
|
||||
import {Compiler} from './compiler/compiler';
|
||||
|
||||
export class LanguageService {
|
||||
private options: CompilerOptions;
|
||||
private readonly compiler: Compiler;
|
||||
|
||||
constructor(project: ts.server.Project, private readonly tsLS: ts.LanguageService) {
|
||||
this.options = parseNgCompilerOptions(project);
|
||||
this.watchConfigFile(project);
|
||||
this.compiler = new Compiler(project, this.options);
|
||||
}
|
||||
|
||||
getSemanticDiagnostics(fileName: string): ts.Diagnostic[] {
|
||||
return [];
|
||||
const program = this.compiler.analyze();
|
||||
if (!program) {
|
||||
return [];
|
||||
}
|
||||
const sourceFile = program.getSourceFile(fileName);
|
||||
if (!sourceFile) {
|
||||
return [];
|
||||
}
|
||||
return this.compiler.getDiagnostics(sourceFile);
|
||||
}
|
||||
|
||||
private watchConfigFile(project: ts.server.Project) {
|
||||
@ -35,6 +46,7 @@ export class LanguageService {
|
||||
project.log(`Config file changed: ${fileName}`);
|
||||
if (eventKind === ts.FileWatcherEventKind.Changed) {
|
||||
this.options = parseNgCompilerOptions(project);
|
||||
this.compiler.setCompilerOptions(this.options);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user