Merge pull request #3904 from hoanhtien/tsconfigTest

Fix bug: fourslash test does not recognize tsconfig.json.
This commit is contained in:
tien
2015-07-30 10:53:51 -07:00
4 changed files with 43 additions and 4 deletions

View File

@@ -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) {
directive = getNonFileNameOptionInObject(globalOptions);
}
if (directive) {
throw Error("It is not allowed to use tsconfig.json along with directive '" + directive + "'");
}
}
return {
markerPositions,
markers,
@@ -2485,6 +2496,23 @@ module FourSlash {
};
}
function containTSConfigJson(files: FourSlashFile[]): boolean {
return ts.forEach(files, f => f.fileOptions['Filename'] === 'tsconfig.json');
}
function getNonFileNameOptionInFileList(files: FourSlashFile[]): string {
return ts.forEach(files, f => getNonFileNameOptionInObject(f.fileOptions));
}
function getNonFileNameOptionInObject(optionObject: { [s: string]: string }): string {
for (let option in optionObject) {
if (option !== metadataOptionNames.fileName) {
return option;
}
}
return undefined;
}
const enum State {
none,
inSlashStarMarker,

View File

@@ -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;
}

View File

@@ -0,0 +1,13 @@
/// <reference path="../fourslash.ts"/>
// @Filename: a.ts
////export var test = "test String"
// @Filename: b.ts
////export var test2 = "test String"
// @Filename: tsconfig.json
////{ "files": ["a.ts", "b.ts"] }
goTo.file("a.ts")
verify.ProjectInfo(["lib.d.ts", "a.ts", "b.ts"])