diff --git a/src/doctor.ts b/src/doctor.ts index d74206d..0828861 100644 --- a/src/doctor.ts +++ b/src/doctor.ts @@ -12,24 +12,23 @@ export class Doctor { scriptVersions: FileEntry = new Map() - constructor(public fileNames: string[], private compilerOptions: _ts.CompilerOptions, ts: typeof _ts) { - const host = createHost(fileNames, compilerOptions, this.scriptVersions, ts) + constructor(public fileNames: string[], private config: _ts.ParsedCommandLine, ts: typeof _ts) { + const host = createHost(fileNames, config, this.scriptVersions, ts) this.service = createService(host, ts) this.reporter = new Reporter(ts) } static fromConfigFile(configPath: string, ts: typeof _ts): Doctor { const content = fs.readFileSync(configPath).toString(); - const { config } = ts.parseConfigFileTextToJson(configPath, content) - const parsed = ts.parseJsonConfigFileContent( - config, + const { config: json } = ts.parseConfigFileTextToJson(configPath, content) + const config = ts.parseJsonConfigFileContent( + json, ts.sys, path.dirname(configPath) ); - const compilerOptions = parsed.options - const defaultLibFileName = _ts.getDefaultLibFileName(compilerOptions) - const libs = [defaultLibFileName, ...(compilerOptions.lib || [])] + const defaultLibFileName = _ts.getDefaultLibFileName(config.options) + const libs = [defaultLibFileName, ...(config.options.lib || [])] const allLibs = getAllLibs(uniq(libs)) /** @@ -39,11 +38,11 @@ export class Doctor { * we need to manually added lib.*.d.ts. */ const fileNames = [ - ...parsed.fileNames, + ...config.fileNames, ...allLibs ] - return new Doctor(fileNames, compilerOptions, ts) + return new Doctor(fileNames, config, ts) } getSemanticDiagnostics() { diff --git a/src/langSvc/createHost.ts b/src/langSvc/createHost.ts index 9934e3b..5718ec7 100644 --- a/src/langSvc/createHost.ts +++ b/src/langSvc/createHost.ts @@ -6,7 +6,7 @@ import { libDTS } from '../gen/libDTS' const libDTSRegexp = /^lib\..*\.d\.ts$/ -export const createHost = (fileNames: string[], compilerOptions: _ts.CompilerOptions, fileEntry: FileEntry, ts: typeof _ts): _ts.LanguageServiceHost => { +export const createHost = (fileNames: string[], config: _ts.ParsedCommandLine, fileEntry: FileEntry, ts: typeof _ts): _ts.LanguageServiceHost => { const getCurrentVersion = (fileName: string) => fileEntry.has(fileName) ? fileEntry.get(fileName)!.version : 0 const getTextFromSnapshot = (snapshot: _ts.IScriptSnapshot) => snapshot.getText(0, snapshot.getLength()) @@ -66,7 +66,7 @@ export const createHost = (fileNames: string[], compilerOptions: _ts.CompilerOpt } }, getCurrentDirectory: () => process.cwd(), - getCompilationSettings: () => compilerOptions, + getCompilationSettings: () => config.options, getDefaultLibFileName: options => ts.getDefaultLibFileName(options), resolveModuleNames: (moduleNames, containingFile, _, __, options) => { const ret: (_ts.ResolvedModule | undefined)[] = moduleNames.map(name => { @@ -87,6 +87,7 @@ export const createHost = (fileNames: string[], compilerOptions: _ts.CompilerOpt }); return ret; }, + getProjectReferences: () => config.projectReferences, fileExists: moduleResolutionHost.fileExists, readFile: moduleResolutionHost.readFile, readDirectory: ts.sys.readDirectory,