-
Notifications
You must be signed in to change notification settings - Fork 12.2k
/
configFileSearch.ts
136 lines (120 loc) · 6.53 KB
/
configFileSearch.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
namespace ts.projectSystem {
describe("unittests:: tsserver:: searching for config file", () => {
it("should stop at projectRootPath if given", () => {
const f1 = {
path: "/a/file1.ts",
content: ""
};
const configFile = {
path: "/tsconfig.json",
content: "{}"
};
const host = createServerHost([f1, configFile]);
const service = createProjectService(host);
service.openClientFile(f1.path, /*fileContent*/ undefined, /*scriptKind*/ undefined, "/a");
checkNumberOfConfiguredProjects(service, 0);
checkNumberOfInferredProjects(service, 1);
service.closeClientFile(f1.path);
service.openClientFile(f1.path);
checkNumberOfConfiguredProjects(service, 1);
checkNumberOfInferredProjects(service, 0);
});
it("should use projectRootPath when searching for inferred project again", () => {
const projectDir = "/a/b/projects/project";
const configFileLocation = `${projectDir}/src`;
const f1 = {
path: `${configFileLocation}/file1.ts`,
content: ""
};
const configFile = {
path: `${configFileLocation}/tsconfig.json`,
content: "{}"
};
const configFile2 = {
path: "/a/b/projects/tsconfig.json",
content: "{}"
};
const host = createServerHost([f1, libFile, configFile, configFile2]);
const service = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) });
service.openClientFile(f1.path, /*fileContent*/ undefined, /*scriptKind*/ undefined, projectDir);
// Delete config file - should create inferred project and not configured project
host.deleteFile(configFile.path);
service.runQueuedTimeoutCallbacks();
checkNumberOfProjects(service, { inferredProjects: 1 });
baselineTsserverLogs("configFileSearch", "should use projectRootPath when searching for inferred project again", service);
});
it("should use projectRootPath when searching for inferred project again 2", () => {
const projectDir = "/a/b/projects/project";
const configFileLocation = `${projectDir}/src`;
const f1 = {
path: `${configFileLocation}/file1.ts`,
content: ""
};
const configFile = {
path: `${configFileLocation}/tsconfig.json`,
content: "{}"
};
const configFile2 = {
path: "/a/b/projects/tsconfig.json",
content: "{}"
};
const host = createServerHost([f1, libFile, configFile, configFile2]);
const service = createProjectService(host, {
useSingleInferredProject: true,
useInferredProjectPerProjectRoot: true,
logger: createLoggerWithInMemoryLogs(host),
});
service.openClientFile(f1.path, /*fileContent*/ undefined, /*scriptKind*/ undefined, projectDir);
// Delete config file - should create inferred project with project root path set
host.deleteFile(configFile.path);
service.runQueuedTimeoutCallbacks();
baselineTsserverLogs("configFileSearch", "should use projectRootPath when searching for inferred project again 2", service);
});
describe("when the opened file is not from project root", () => {
const projectRoot = "/a/b/projects/project";
const file: File = {
path: `${projectRoot}/src/index.ts`,
content: "let y = 10"
};
const tsconfig: File = {
path: `${projectRoot}/tsconfig.json`,
content: "{}"
};
function openClientFile(files: File[]) {
const host = createServerHost(files);
const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) });
projectService.openClientFile(file.path, /*fileContent*/ undefined, /*scriptKind*/ undefined, "/a/b/projects/proj");
return { host, projectService };
}
it("tsconfig for the file exists", () => {
const { host, projectService } = openClientFile([file, libFile, tsconfig]);
host.deleteFile(tsconfig.path);
projectService.runQueuedTimeoutCallbacks();
host.writeFile(tsconfig.path, tsconfig.content);
projectService.runQueuedTimeoutCallbacks();
baselineTsserverLogs("configFileSearch", "tsconfig for the file exists", projectService);
});
it("tsconfig for the file does not exist", () => {
const { host, projectService } = openClientFile([file, libFile]);
host.writeFile(tsconfig.path, tsconfig.content);
projectService.runQueuedTimeoutCallbacks();
host.deleteFile(tsconfig.path);
projectService.runQueuedTimeoutCallbacks();
baselineTsserverLogs("configFileSearch", "tsconfig for the file does not exist", projectService);
});
});
describe("should not search and watch config files from directories that cannot be watched", () => {
function verifyConfigFileWatch(scenario: string, projectRootPath: string | undefined) {
it(scenario, () => {
const path = `/root/teams/VSCode68/Shared Documents/General/jt-ts-test-workspace/x.js`;
const host = createServerHost([libFile, { path, content: "const x = 10" }], { useCaseSensitiveFileNames: true });
const service = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) });
service.openClientFile(path, /*fileContent*/ undefined, /*scriptKind*/ undefined, projectRootPath);
baselineTsserverLogs("configFileSearch", scenario, service);
});
}
verifyConfigFileWatch("when projectRootPath is not present", /*projectRootPath*/ undefined);
verifyConfigFileWatch("when projectRootPath is present but file is not from project root", "/a/b");
});
});
}