Skip to content

Commit 196f1c2

Browse files
Merge pull request microsoft#20910 from uniqueiniquity/allowDynamicNotOpenByClient
Allow dynamic files script info to be created when not opened by client
2 parents 1ebfac0 + b9ea347 commit 196f1c2

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,24 @@ namespace ts.projectSystem {
11841184
checkNumberOfInferredProjects(projectService, 0);
11851185
});
11861186

1187+
it("external project for dynamic file", () => {
1188+
const externalProjectName = "^ScriptDocument1 file1.ts";
1189+
const externalFiles = toExternalFiles(["^ScriptDocument1 file1.ts"]);
1190+
const host = createServerHost([]);
1191+
const projectService = createProjectService(host);
1192+
projectService.openExternalProject({
1193+
rootFiles: externalFiles,
1194+
options: {},
1195+
projectFileName: externalProjectName
1196+
});
1197+
1198+
checkNumberOfExternalProjects(projectService, 1);
1199+
checkNumberOfInferredProjects(projectService, 0);
1200+
1201+
externalFiles[0].content = "let x =1;";
1202+
projectService.applyChangesInOpenFiles(externalFiles, [], []);
1203+
});
1204+
11871205
it("external project that included config files", () => {
11881206
const file1 = {
11891207
path: "/a/b/f1.ts",

src/server/editorServices.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,9 +1776,10 @@ namespace ts.server {
17761776
const path = normalizedPathToPath(fileName, currentDirectory, this.toCanonicalFileName);
17771777
let info = this.getScriptInfoForPath(path);
17781778
if (!info) {
1779-
Debug.assert(isRootedDiskPath(fileName) || openedByClient, "Script info with relative file name can only be open script info");
1780-
Debug.assert(!isRootedDiskPath(fileName) || this.currentDirectory === currentDirectory || !this.openFilesWithNonRootedDiskPath.has(this.toCanonicalFileName(fileName)), "Open script files with non rooted disk path opened with current directory context cannot have same canonical names");
17811779
const isDynamic = isDynamicFileName(fileName);
1780+
Debug.assert(isRootedDiskPath(fileName) || isDynamic || openedByClient, "Script info with non-dynamic relative file name can only be open script info");
1781+
Debug.assert(!isRootedDiskPath(fileName) || this.currentDirectory === currentDirectory || !this.openFilesWithNonRootedDiskPath.has(this.toCanonicalFileName(fileName)), "Open script files with non rooted disk path opened with current directory context cannot have same canonical names");
1782+
Debug.assert(!isDynamic || this.currentDirectory === currentDirectory, "Dynamic files must always have current directory context since containing external project name will always match the script info name.");
17821783
// If the file is not opened by client and the file doesnot exist on the disk, return
17831784
if (!openedByClient && !isDynamic && !(hostToQueryFileExistsOn || this.host).fileExists(fileName)) {
17841785
return;

0 commit comments

Comments
 (0)