From 53e449c90149fe5929d35c843c87128f386e179d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Jul 2015 23:33:42 -0700 Subject: [PATCH 1/4] Allow tsconfig.json to be added to fourslash test. --- src/server/editorServices.ts | 6 ++---- .../server/{projectInfo.ts => projectInfo01.ts} | 0 tests/cases/fourslash/server/projectInfo02.ts | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) rename tests/cases/fourslash/server/{projectInfo.ts => projectInfo01.ts} (100%) create mode 100644 tests/cases/fourslash/server/projectInfo02.ts diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 91d400ff263..64ec600783a 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -803,9 +803,6 @@ namespace ts.server { } else { this.log("no config file"); } - if (configFileName) { - configFileName = getAbsolutePath(configFileName, searchPath); - } if (configFileName && (!this.configProjectIsActive(configFileName))) { var configResult = this.openConfigFile(configFileName, fileName); if (!configResult.success) { @@ -910,7 +907,8 @@ namespace ts.server { configFilename = ts.normalizePath(configFilename); // file references will be relative to dirPath (or absolute) var dirPath = ts.getDirectoryPath(configFilename); - var rawConfig: { config?: ProjectOptions; error?: Diagnostic; } = ts.readConfigFile(configFilename); + var contents = this.host.readFile(configFilename) + var rawConfig: { config?: ProjectOptions; error?: Diagnostic; } = ts.parseConfigFileText(configFilename, contents); if (rawConfig.error) { return rawConfig.error; } diff --git a/tests/cases/fourslash/server/projectInfo.ts b/tests/cases/fourslash/server/projectInfo01.ts similarity index 100% rename from tests/cases/fourslash/server/projectInfo.ts rename to tests/cases/fourslash/server/projectInfo01.ts diff --git a/tests/cases/fourslash/server/projectInfo02.ts b/tests/cases/fourslash/server/projectInfo02.ts new file mode 100644 index 00000000000..f884062fc14 --- /dev/null +++ b/tests/cases/fourslash/server/projectInfo02.ts @@ -0,0 +1,15 @@ +/// + +// @Filename: a.ts +////export var test = "test String" + +// @Filename: b.ts +////export var test2 = "test String" + +// @Filename: tsconfig.json +////{ "files": ["a.ts", "b.ts"] } + +debugger; + +goTo.file("a.ts") +verify.ProjectInfo(["lib.d.ts", "a.ts", "b.ts"]) From 450112d28a253e318ea927af1289527eff4a3f07 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Jul 2015 23:43:35 -0700 Subject: [PATCH 2/4] Remove debugger; --- tests/cases/fourslash/server/projectInfo02.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/cases/fourslash/server/projectInfo02.ts b/tests/cases/fourslash/server/projectInfo02.ts index f884062fc14..eb86c721ac7 100644 --- a/tests/cases/fourslash/server/projectInfo02.ts +++ b/tests/cases/fourslash/server/projectInfo02.ts @@ -9,7 +9,5 @@ // @Filename: tsconfig.json ////{ "files": ["a.ts", "b.ts"] } -debugger; - goTo.file("a.ts") verify.ProjectInfo(["lib.d.ts", "a.ts", "b.ts"]) From 90e31adea85e12d0e6c2004d29c2dbfd31f898fa Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 Jul 2015 21:02:58 -0700 Subject: [PATCH 3/4] Raise error if mixing tsconfig.json and directives. --- src/harness/fourslash.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 272f4c1c1dd..06ff5d4234b 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2476,6 +2476,17 @@ module FourSlash { } } + // @Filename is the only directive that can be used in a test that contains tsconfig.json file. + if (containTSConfigJson(files)) { + let directive = getNonFileNameOptionInFileList(files); + if (directive == null) { + directive = getNonFileNameOptionInObject(globalOptions); + } + if (directive !== null) { + throw Error("It is not allowed to use tsconfig.json along with directive '" + directive + "'"); + } + } + return { markerPositions, markers, @@ -2485,6 +2496,34 @@ module FourSlash { }; } + function containTSConfigJson(files: FourSlashFile[]): boolean { + for (let i = 0; i < files.length; ++i) { + if (files[i].fileOptions['Filename'] === 'tsconfig.json') { + return true; + } + } + return false; + } + + function getNonFileNameOptionInFileList(files: FourSlashFile[]): string { + for (let i = 0; i < files.length; ++i) { + let option = getNonFileNameOptionInObject(files[i].fileOptions); + if (option !== null) { + return option; + } + } + return null; + } + + function getNonFileNameOptionInObject(optionObject: { [s: string]: string }): string { + for (let option in optionObject) { + if (option !== metadataOptionNames.fileName) { + return option; + } + } + return null; + } + const enum State { none, inSlashStarMarker, From e4a1c97b7ddc0c191387760e77d370f1944d9114 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 29 Jul 2015 18:57:48 -0700 Subject: [PATCH 4/4] Address comments. --- src/harness/fourslash.ts | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 06ff5d4234b..5d73e04c8cb 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2479,10 +2479,10 @@ module FourSlash { // @Filename is the only directive that can be used in a test that contains tsconfig.json file. if (containTSConfigJson(files)) { let directive = getNonFileNameOptionInFileList(files); - if (directive == null) { + if (!directive) { directive = getNonFileNameOptionInObject(globalOptions); } - if (directive !== null) { + if (directive) { throw Error("It is not allowed to use tsconfig.json along with directive '" + directive + "'"); } } @@ -2497,22 +2497,11 @@ module FourSlash { } function containTSConfigJson(files: FourSlashFile[]): boolean { - for (let i = 0; i < files.length; ++i) { - if (files[i].fileOptions['Filename'] === 'tsconfig.json') { - return true; - } - } - return false; + return ts.forEach(files, f => f.fileOptions['Filename'] === 'tsconfig.json'); } function getNonFileNameOptionInFileList(files: FourSlashFile[]): string { - for (let i = 0; i < files.length; ++i) { - let option = getNonFileNameOptionInObject(files[i].fileOptions); - if (option !== null) { - return option; - } - } - return null; + return ts.forEach(files, f => getNonFileNameOptionInObject(f.fileOptions)); } function getNonFileNameOptionInObject(optionObject: { [s: string]: string }): string { @@ -2521,7 +2510,7 @@ module FourSlash { return option; } } - return null; + return undefined; } const enum State {