Integrate format diagnostic host in DenoCompiler

This commit is contained in:
Kitson Kelly 2018-09-06 09:34:25 -07:00 committed by Ryan Dahl
parent 63c2fc8d1f
commit 11aef6e107

View file

@ -113,16 +113,6 @@ export class ModuleMetaData implements ts.IScriptSnapshot {
} }
} }
/**
* The required minimal API to allow formatting of TypeScript compiler
* diagnostics.
*/
const formatDiagnosticsHost: ts.FormatDiagnosticsHost = {
getCurrentDirectory: () => ".",
getCanonicalFileName: (fileName: string) => fileName,
getNewLine: () => EOL
};
/** /**
* Throw a module resolution error, when a module is unsuccessfully resolved. * Throw a module resolution error, when a module is unsuccessfully resolved.
*/ */
@ -142,7 +132,8 @@ function throwResolutionError(
* with Deno specific APIs to provide an interface for compiling and running * with Deno specific APIs to provide an interface for compiling and running
* TypeScript and JavaScript modules. * TypeScript and JavaScript modules.
*/ */
export class DenoCompiler implements ts.LanguageServiceHost { export class DenoCompiler
implements ts.LanguageServiceHost, ts.FormatDiagnosticsHost {
// Modules are usually referenced by their ModuleSpecifier and ContainingFile, // Modules are usually referenced by their ModuleSpecifier and ContainingFile,
// and keeping a map of the resolved module file name allows more efficient // and keeping a map of the resolved module file name allows more efficient
// future resolution // future resolution
@ -370,7 +361,7 @@ export class DenoCompiler implements ts.LanguageServiceHost {
if (diagnostics.length > 0) { if (diagnostics.length > 0) {
const errMsg = this._ts.formatDiagnosticsWithColorAndContext( const errMsg = this._ts.formatDiagnosticsWithColorAndContext(
diagnostics, diagnostics,
formatDiagnosticsHost this
); );
console.log(errMsg); console.log(errMsg);
// All TypeScript errors are terminal for deno // All TypeScript errors are terminal for deno
@ -598,6 +589,11 @@ export class DenoCompiler implements ts.LanguageServiceHost {
// TypeScript Language Service API // TypeScript Language Service API
getCanonicalFileName(fileName: string): string {
this._log("getCanonicalFileName", fileName);
return fileName;
}
getCompilationSettings(): ts.CompilerOptions { getCompilationSettings(): ts.CompilerOptions {
this._log("getCompilationSettings()"); this._log("getCompilationSettings()");
return this._options; return this._options;