diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 8169421ca17..fc1293d6040 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -292,7 +292,7 @@ module ts { * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ - export function parseConfigFile(json: any, basePath?: string): ParsedCommandLine { + export function parseConfigFile(json: any, host: ParseConfigHost, basePath?: string): ParsedCommandLine { var errors: Diagnostic[] = []; return { @@ -351,7 +351,7 @@ module ts { } } else { - var sysFiles = sys.readDirectory(basePath, ".ts"); + var sysFiles = host.readDirectory(basePath, ".ts"); for (var i = 0; i < sysFiles.length; i++) { var name = sysFiles[i]; if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 0cbeff8204a..7eb86efbfae 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -213,7 +213,7 @@ module ts { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, configFileName)); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } - var configParseResult = parseConfigFile(configObject, getDirectoryPath(configFileName)); + var configParseResult = parseConfigFile(configObject, sys, getDirectoryPath(configFileName)); if (configParseResult.errors.length > 0) { reportDiagnostics(configParseResult.errors); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9191a6999bf..7decd8bd215 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1032,6 +1032,10 @@ module ts { getCurrentDirectory(): string; } + export interface ParseConfigHost { + readDirectory(rootDir: string, extension: string): string[]; + } + export interface WriteFileCallback { (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index bce4c9828fa..e7c60e4d862 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -186,6 +186,7 @@ module Harness.LanguageService { var script = this.getScriptInfo(fileName); return script ? script.version.toString() : undefined; } + log(s: string): void { } trace(s: string): void { } error(s: string): void { } @@ -203,7 +204,7 @@ module Harness.LanguageService { } /// Shim adapter - class ShimLanguageServiceHost extends LanguageServiceAdapterHost implements ts.LanguageServiceShimHost { + class ShimLanguageServiceHost extends LanguageServiceAdapterHost implements ts.LanguageServiceShimHost, ts.CoreServicesShimHost { private nativeHost: NativeLanguageServiceHost; constructor(cancellationToken?: ts.CancellationToken, options?: ts.CompilerOptions) { super(cancellationToken, options); @@ -227,6 +228,11 @@ module Harness.LanguageService { } getScriptVersion(fileName: string): string { return this.nativeHost.getScriptVersion(fileName); } getLocalizedDiagnosticMessages(): string { return JSON.stringify({}); } + + readDirectory(rootDir: string, extension: string): string { + throw new Error("NYI"); + } + log(s: string): void { this.nativeHost.log(s); } trace(s: string): void { this.nativeHost.trace(s); } error(s: string): void { this.nativeHost.error(s); } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 8b4ab2cffa8..9ed31c91968 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -910,7 +910,7 @@ module ts.server { return { errorMsg: "tsconfig syntax error" }; } else { - var parsedCommandLine = ts.parseConfigFile(rawConfig, dirPath); + var parsedCommandLine = ts.parseConfigFile(rawConfig, ts.sys, dirPath); if (parsedCommandLine.errors && (parsedCommandLine.errors.length > 0)) { return { errorMsg: "tsconfig option errors" }; } diff --git a/src/services/shims.ts b/src/services/shims.ts index 110090daf5c..a8de3b817c4 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -57,6 +57,12 @@ module ts { getNewLine?(): string; } + /** Public interface of the the of a config service shim instance.*/ + export interface CoreServicesShimHost extends Logger { + /** Returns a JSON-encoded value of the type: string[] */ + readDirectory(rootDir: string, extension: string): string; + } + /// /// Pre-processing /// @@ -77,7 +83,7 @@ module ts { export interface Shim { dispose(dummy: any): void; } - + export interface LanguageServiceShim extends Shim { languageService: LanguageService; @@ -188,6 +194,7 @@ module ts { export interface CoreServicesShim extends Shim { getPreProcessedFileInfo(fileName: string, sourceText: IScriptSnapshot): string; + getTSConfigFileInfo(fileName: string, sourceText: IScriptSnapshot): string; getDefaultCompilationSettings(): string; } @@ -302,6 +309,17 @@ module ts { } } } + + export class CoreServicesShimHostAdapter implements ParseConfigHost { + + constructor(private shimHost: CoreServicesShimHost) { + } + + public readDirectory(rootDir: string, extension: string): string[] { + var encoded = this.shimHost.readDirectory(rootDir, extension); + return JSON.parse(encoded); + } + } function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any): any { logger.log(actionDescription); @@ -741,7 +759,8 @@ module ts { } class CoreServicesShimObject extends ShimBase implements CoreServicesShim { - constructor(factory: ShimFactory, public logger: Logger) { + + constructor(factory: ShimFactory, public logger: Logger, private host: CoreServicesShimHostAdapter) { super(factory); } @@ -779,6 +798,25 @@ module ts { }); } + public getTSConfigFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string { + return this.forwardJSONCall( + "getTSConfigFileInfo('" + fileName + "')", + () => { + var text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); + var json = /\S/.test(text) ? JSON.parse(text) : {}; + + var configFile = parseConfigFile(json, this.host, getDirectoryPath(normalizeSlashes(fileName))); + + var realErrors = realizeDiagnostics(configFile.errors, '\r\n'); + + return { + options: configFile.options, + files: configFile.fileNames, + errors: realErrors + }; + }); + } + public getDefaultCompilationSettings(): string { return this.forwardJSONCall( "getDefaultCompilationSettings()", @@ -821,12 +859,13 @@ module ts { } } - public createCoreServicesShim(logger: Logger): CoreServicesShim { + public createCoreServicesShim(host: CoreServicesShimHost): CoreServicesShim { try { - return new CoreServicesShimObject(this, logger); + var adapter = new CoreServicesShimHostAdapter(host); + return new CoreServicesShimObject(this, host, adapter); } catch (err) { - logInternalError(logger, err); + logInternalError(host, err); throw err; } }