Skip to content

Commit e6eede1

Browse files
committed
Update how we get project/script info so that it doesnt start unnecessary update graph
1 parent 0ff160f commit e6eede1

File tree

2 files changed

+111
-107
lines changed

2 files changed

+111
-107
lines changed

src/server/editorServices.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,16 @@ namespace ts.server {
588588
return this.findExternalProjectByProjectName(projectName) || this.findConfiguredProjectByProjectName(toNormalizedPath(projectName));
589589
}
590590

591-
getDefaultProjectForFile(fileName: NormalizedPath, refreshInferredProjects: boolean) {
592-
if (refreshInferredProjects) {
591+
getDefaultProjectForFile(fileName: NormalizedPath, ensureProject: boolean) {
592+
let scriptInfo = this.getScriptInfoForNormalizedPath(fileName);
593+
if (ensureProject && !scriptInfo || scriptInfo.isOrphan()) {
593594
this.ensureProjectStructuresUptoDate();
595+
scriptInfo = this.getScriptInfoForNormalizedPath(fileName);
596+
if (!scriptInfo) {
597+
return Errors.ThrowNoProject();
598+
}
599+
return scriptInfo.getDefaultProject();
594600
}
595-
const scriptInfo = this.getScriptInfoForNormalizedPath(fileName);
596601
return scriptInfo && !scriptInfo.isOrphan() && scriptInfo.getDefaultProject();
597602
}
598603

@@ -1943,12 +1948,7 @@ namespace ts.server {
19431948
for (const file of changedFiles) {
19441949
const scriptInfo = this.getScriptInfo(file.fileName);
19451950
Debug.assert(!!scriptInfo);
1946-
// apply changes in reverse order
1947-
for (let i = file.changes.length - 1; i >= 0; i--) {
1948-
const change = file.changes[i];
1949-
scriptInfo.editContent(change.span.start, change.span.start + change.span.length, change.newText);
1950-
}
1951-
this.addChangedFile(scriptInfo);
1951+
this.applyChangesToFile(scriptInfo, file.changes);
19521952
}
19531953
}
19541954

@@ -1965,7 +1965,12 @@ namespace ts.server {
19651965
}
19661966

19671967
/* @internal */
1968-
addChangedFile(scriptInfo: ScriptInfo) {
1968+
applyChangesToFile(scriptInfo: ScriptInfo, changes: TextChange[]) {
1969+
// apply changes in reverse order
1970+
for (let i = changes.length - 1; i >= 0; i--) {
1971+
const change = changes[i];
1972+
scriptInfo.editContent(change.span.start, change.span.start + change.span.length, change.newText);
1973+
}
19691974
if (!this.changedFiles) {
19701975
this.changedFiles = [scriptInfo];
19711976
}

0 commit comments

Comments
 (0)