Skip to content

Commit 6ca65b7

Browse files
committed
Refactoring project updates in openFile
1 parent 458c12f commit 6ca65b7

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

src/server/editorServices.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,6 @@ namespace ts.server {
20382038

20392039
openClientFileWithNormalizedPath(fileName: NormalizedPath, fileContent?: string, scriptKind?: ScriptKind, hasMixedContent?: boolean, projectRootPath?: NormalizedPath): OpenConfiguredProjectResult {
20402040
let configFileName: NormalizedPath;
2041-
let sendConfigFileDiagEvent = false;
20422041
let configFileErrors: ReadonlyArray<Diagnostic>;
20432042

20442043
const info = this.getOrCreateScriptInfoOpenedByClientForNormalizedPath(fileName, projectRootPath ? this.getNormalizedAbsolutePath(projectRootPath) : this.currentDirectory, fileContent, scriptKind, hasMixedContent);
@@ -2049,39 +2048,36 @@ namespace ts.server {
20492048
project = this.findConfiguredProjectByProjectName(configFileName);
20502049
if (!project) {
20512050
project = this.createConfiguredProject(configFileName);
2052-
// Send the event only if the project got created as part of this open request
2053-
sendConfigFileDiagEvent = true;
2051+
// Send the event only if the project got created as part of this open request and info is part of the project
2052+
if (info.isOrphan()) {
2053+
// Since the file isnt part of configured project, do not send config file info
2054+
configFileName = undefined;
2055+
}
2056+
else {
2057+
configFileErrors = project.getAllProjectErrors();
2058+
this.sendConfigFileDiagEvent(project as ConfiguredProject, fileName);
2059+
}
20542060
}
20552061
else {
20562062
// Ensure project is ready to check if it contains opened script info
20572063
project.updateGraph();
20582064
}
20592065
}
20602066
}
2061-
if (project && !project.languageServiceEnabled) {
2062-
// if project language service is disabled then we create a program only for open files.
2063-
// this means that project should be marked as dirty to force rebuilding of the program
2064-
// on the next request
2065-
project.markAsDirty();
2066-
}
2067+
2068+
// Project we have at this point is going to be updated since its either found through
2069+
// - external project search, which updates the project before checking if info is present in it
2070+
// - configured project - either created or updated to ensure we know correct status of info
20672071

20682072
// At this point if file is part of any any configured or external project, then it would be present in the containing projects
20692073
// So if it still doesnt have any containing projects, it needs to be part of inferred project
20702074
if (info.isOrphan()) {
2071-
// Since the file isnt part of configured project, do not send config file event
2072-
configFileName = undefined;
2073-
sendConfigFileDiagEvent = false;
2074-
20752075
this.assignOrphanScriptInfoToInferredProject(info, projectRootPath);
20762076
}
2077+
20772078
Debug.assert(!info.isOrphan());
20782079
this.openFiles.set(info.path, projectRootPath);
20792080

2080-
if (sendConfigFileDiagEvent) {
2081-
configFileErrors = project.getAllProjectErrors();
2082-
this.sendConfigFileDiagEvent(project as ConfiguredProject, fileName);
2083-
}
2084-
20852081
// Remove the configured projects that have zero references from open files.
20862082
// This was postponed from closeOpenFile to after opening next file,
20872083
// so that we can reuse the project if we need to right away

0 commit comments

Comments
 (0)