mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-29 19:42:39 -05:00
expose the config file processing throught the LS and
add a callback to enumerate files in a directory
This commit is contained in:
@@ -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")) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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); }
|
||||
|
||||
@@ -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" };
|
||||
}
|
||||
|
||||
@@ -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, <Logger>host, adapter);
|
||||
}
|
||||
catch (err) {
|
||||
logInternalError(logger, err);
|
||||
logInternalError(<Logger>host, err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user