Skip to content

Commit 80ae52b

Browse files
author
Paul van Brenk
committed
expose the config file processing throught the LS and
add a callback to enumerate files in a directory
1 parent 02a480d commit 80ae52b

File tree

6 files changed

+59
-10
lines changed

6 files changed

+59
-10
lines changed

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ module ts {
292292
* @param basePath A root directory to resolve relative path entries in the config
293293
* file to. e.g. outDir
294294
*/
295-
export function parseConfigFile(json: any, basePath?: string): ParsedCommandLine {
295+
export function parseConfigFile(json: any, host: ParseConfigHost, basePath?: string): ParsedCommandLine {
296296
var errors: Diagnostic[] = [];
297297

298298
return {
@@ -351,7 +351,7 @@ module ts {
351351
}
352352
}
353353
else {
354-
var sysFiles = sys.readDirectory(basePath, ".ts");
354+
var sysFiles = host.readDirectory(basePath, ".ts");
355355
for (var i = 0; i < sysFiles.length; i++) {
356356
var name = sysFiles[i];
357357
if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) {

src/compiler/tsc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ module ts {
213213
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, configFileName));
214214
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
215215
}
216-
var configParseResult = parseConfigFile(configObject, getDirectoryPath(configFileName));
216+
var configParseResult = parseConfigFile(configObject, sys, getDirectoryPath(configFileName));
217217
if (configParseResult.errors.length > 0) {
218218
reportDiagnostics(configParseResult.errors);
219219
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);

src/compiler/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,10 @@ module ts {
10321032
getCurrentDirectory(): string;
10331033
}
10341034

1035+
export interface ParseConfigHost {
1036+
readDirectory(rootDir: string, extension: string): string[];
1037+
}
1038+
10351039
export interface WriteFileCallback {
10361040
(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void;
10371041
}

src/harness/harnessLanguageService.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ module Harness.LanguageService {
186186
var script = this.getScriptInfo(fileName);
187187
return script ? script.version.toString() : undefined;
188188
}
189+
189190
log(s: string): void { }
190191
trace(s: string): void { }
191192
error(s: string): void { }
@@ -203,7 +204,7 @@ module Harness.LanguageService {
203204
}
204205

205206
/// Shim adapter
206-
class ShimLanguageServiceHost extends LanguageServiceAdapterHost implements ts.LanguageServiceShimHost {
207+
class ShimLanguageServiceHost extends LanguageServiceAdapterHost implements ts.LanguageServiceShimHost, ts.CoreServicesShimHost {
207208
private nativeHost: NativeLanguageServiceHost;
208209
constructor(cancellationToken?: ts.CancellationToken, options?: ts.CompilerOptions) {
209210
super(cancellationToken, options);
@@ -227,6 +228,11 @@ module Harness.LanguageService {
227228
}
228229
getScriptVersion(fileName: string): string { return this.nativeHost.getScriptVersion(fileName); }
229230
getLocalizedDiagnosticMessages(): string { return JSON.stringify({}); }
231+
232+
readDirectory(rootDir: string, extension: string): string {
233+
throw new Error("NYI");
234+
}
235+
230236
log(s: string): void { this.nativeHost.log(s); }
231237
trace(s: string): void { this.nativeHost.trace(s); }
232238
error(s: string): void { this.nativeHost.error(s); }

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ module ts.server {
910910
return { errorMsg: "tsconfig syntax error" };
911911
}
912912
else {
913-
var parsedCommandLine = ts.parseConfigFile(rawConfig, dirPath);
913+
var parsedCommandLine = ts.parseConfigFile(rawConfig, ts.sys, dirPath);
914914
if (parsedCommandLine.errors && (parsedCommandLine.errors.length > 0)) {
915915
return { errorMsg: "tsconfig option errors" };
916916
}

src/services/shims.ts

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ module ts {
5757
getNewLine?(): string;
5858
}
5959

60+
/** Public interface of the the of a config service shim instance.*/
61+
export interface CoreServicesShimHost extends Logger {
62+
/** Returns a JSON-encoded value of the type: string[] */
63+
readDirectory(rootDir: string, extension: string): string;
64+
}
65+
6066
///
6167
/// Pre-processing
6268
///
@@ -77,7 +83,7 @@ module ts {
7783
export interface Shim {
7884
dispose(dummy: any): void;
7985
}
80-
86+
8187
export interface LanguageServiceShim extends Shim {
8288
languageService: LanguageService;
8389

@@ -188,6 +194,7 @@ module ts {
188194

189195
export interface CoreServicesShim extends Shim {
190196
getPreProcessedFileInfo(fileName: string, sourceText: IScriptSnapshot): string;
197+
getTSConfigFileInfo(fileName: string, sourceText: IScriptSnapshot): string;
191198
getDefaultCompilationSettings(): string;
192199
}
193200

@@ -302,6 +309,17 @@ module ts {
302309
}
303310
}
304311
}
312+
313+
export class CoreServicesShimHostAdapter implements ParseConfigHost {
314+
315+
constructor(private shimHost: CoreServicesShimHost) {
316+
}
317+
318+
public readDirectory(rootDir: string, extension: string): string[] {
319+
var encoded = this.shimHost.readDirectory(rootDir, extension);
320+
return JSON.parse(encoded);
321+
}
322+
}
305323

306324
function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any): any {
307325
logger.log(actionDescription);
@@ -741,7 +759,8 @@ module ts {
741759
}
742760

743761
class CoreServicesShimObject extends ShimBase implements CoreServicesShim {
744-
constructor(factory: ShimFactory, public logger: Logger) {
762+
763+
constructor(factory: ShimFactory, public logger: Logger, private host: CoreServicesShimHostAdapter) {
745764
super(factory);
746765
}
747766

@@ -779,6 +798,25 @@ module ts {
779798
});
780799
}
781800

801+
public getTSConfigFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string {
802+
return this.forwardJSONCall(
803+
"getTSConfigFileInfo('" + fileName + "')",
804+
() => {
805+
var text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength());
806+
var json = /\S/.test(text) ? JSON.parse(text) : {};
807+
808+
var configFile = parseConfigFile(json, this.host, getDirectoryPath(normalizeSlashes(fileName)));
809+
810+
var realErrors = realizeDiagnostics(configFile.errors, '\r\n');
811+
812+
return {
813+
options: configFile.options,
814+
files: configFile.fileNames,
815+
errors: realErrors
816+
};
817+
});
818+
}
819+
782820
public getDefaultCompilationSettings(): string {
783821
return this.forwardJSONCall(
784822
"getDefaultCompilationSettings()",
@@ -821,12 +859,13 @@ module ts {
821859
}
822860
}
823861

824-
public createCoreServicesShim(logger: Logger): CoreServicesShim {
862+
public createCoreServicesShim(host: CoreServicesShimHost): CoreServicesShim {
825863
try {
826-
return new CoreServicesShimObject(this, logger);
864+
var adapter = new CoreServicesShimHostAdapter(host);
865+
return new CoreServicesShimObject(this, <Logger>host, adapter);
827866
}
828867
catch (err) {
829-
logInternalError(logger, err);
868+
logInternalError(<Logger>host, err);
830869
throw err;
831870
}
832871
}

0 commit comments

Comments
 (0)