Skip to content

Commit dca368b

Browse files
authored
handle the case when conversion of tsconfig.json failed (microsoft#14160)
1 parent b4d2b1d commit dca368b

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,6 +3035,33 @@ namespace ts.projectSystem {
30353035
const inferredProject = projectService.inferredProjects[0];
30363036
assert.isTrue(inferredProject.containsFile(<server.NormalizedPath>file1.path));
30373037
});
3038+
3039+
it("should be able to handle @types if input file list is empty", () => {
3040+
const f = {
3041+
path: "/a/app.ts",
3042+
content: "let x = 1"
3043+
};
3044+
const config = {
3045+
path: "/a/tsconfig.json",
3046+
content: JSON.stringify({
3047+
compiler: {},
3048+
files: []
3049+
})
3050+
};
3051+
const t1 = {
3052+
path: "/a/node_modules/@types/typings/index.d.ts",
3053+
content: `export * from "./lib"`
3054+
};
3055+
const t2 = {
3056+
path: "/a/node_modules/@types/typings/lib.d.ts",
3057+
content: `export const x: number`
3058+
};
3059+
const host = createServerHost([f, config, t1, t2], { currentDirectory: getDirectoryPath(f.path) });
3060+
const projectService = createProjectService(host);
3061+
3062+
projectService.openClientFile(f.path);
3063+
projectService.checkNumberOfProjects({ configuredProjects: 1, inferredProjects: 1 });
3064+
});
30383065
});
30393066

30403067
describe("reload", () => {

src/server/editorServices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,9 @@ namespace ts.server {
948948

949949
private openConfigFile(configFileName: NormalizedPath, clientFileName?: string): OpenConfigFileResult {
950950
const conversionResult = this.convertConfigFileContentToProjectOptions(configFileName);
951-
const projectOptions = conversionResult.success
951+
const projectOptions: ProjectOptions = conversionResult.success
952952
? conversionResult.projectOptions
953-
: { files: [], compilerOptions: {} };
953+
: { files: [], compilerOptions: {}, typeAcquisition: { enable: false } };
954954
const project = this.createAndAddConfiguredProject(configFileName, projectOptions, conversionResult.configFileErrors, clientFileName);
955955
return {
956956
success: conversionResult.success,

0 commit comments

Comments
 (0)