Skip to content
This repository was archived by the owner on Nov 21, 2025. It is now read-only.

Commit 38bcc46

Browse files
andrius-praKeen Yee Liau
authored andcommitted
share DocumentRegistry instance between all language service instances
1 parent 45417a1 commit 38bcc46

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

server/src/editorServices.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -802,21 +802,22 @@ export class Project {
802802
constructor(
803803
public projectService: ProjectService,
804804
private logger: Logger,
805+
private documentRegistry: ts.DocumentRegistry,
805806
public projectOptions?: ProjectOptions,
806807
public languageServiceDisabled = false) {
807808
if (projectOptions && projectOptions.files) {
808809
// If files are listed explicitly, allow all extensions
809810
projectOptions.compilerOptions['allowNonTsExtensions'] = true;
810811
}
811812
if (!languageServiceDisabled) {
812-
this.compilerService = new CompilerService(this, logger, projectOptions && projectOptions.compilerOptions);
813+
this.compilerService = new CompilerService(this, logger, this.documentRegistry, projectOptions && projectOptions.compilerOptions);
813814
}
814815
}
815816

816817
enableLanguageService() {
817818
// if the language service was disabled, we should re-initiate the compiler service
818819
if (this.languageServiceDisabled) {
819-
this.compilerService = new CompilerService(this, this.logger, this.projectOptions && this.projectOptions.compilerOptions);
820+
this.compilerService = new CompilerService(this, this.logger, this.documentRegistry, this.projectOptions && this.projectOptions.compilerOptions);
820821
}
821822
this.languageServiceDisabled = false;
822823
}
@@ -1043,6 +1044,7 @@ export interface HostConfiguration {
10431044
}
10441045

10451046
export class ProjectService {
1047+
documentRegistry = ts.createDocumentRegistry();
10461048
filenameToScriptInfo = createMap<ScriptInfo>();
10471049
// open, non-configured root files
10481050
openFileRoots: ScriptInfo[] = [];
@@ -1208,7 +1210,7 @@ export class ProjectService {
12081210
}
12091211

12101212
createInferredProject(root: ScriptInfo) {
1211-
const project = new Project(this, this.psLogger);
1213+
const project = new Project(this, this.psLogger, this.documentRegistry);
12121214
project.addRoot(root);
12131215

12141216
project.finishGraph();
@@ -1987,7 +1989,7 @@ export class ProjectService {
19871989
}
19881990

19891991
createProject(projectFilename: string, projectOptions?: ProjectOptions, languageServiceDisabled?: boolean) {
1990-
const project = new Project(this, this.psLogger, projectOptions, languageServiceDisabled);
1992+
const project = new Project(this, this.psLogger, this.documentRegistry, projectOptions, languageServiceDisabled);
19911993
project.projectFilename = projectFilename;
19921994
return project;
19931995
}
@@ -2001,10 +2003,9 @@ export class CompilerService {
20012003
ngService: ng.LanguageService;
20022004
classifier: ts.Classifier;
20032005
settings: ts.CompilerOptions;
2004-
documentRegistry = ts.createDocumentRegistry();
20052006
ng: typeof ng;
20062007

2007-
constructor(public project: Project, private logger: Logger, opt?: ts.CompilerOptions) {
2008+
constructor(public project: Project, private logger: Logger, public documentRegistry: ts.DocumentRegistry, opt?: ts.CompilerOptions) {
20082009
this.host = new LSHost(project.projectService.host, project);
20092010
if (opt) {
20102011
this.setCompilerOptions(opt);

0 commit comments

Comments
 (0)