Skip to content

Commit

Permalink
feat: add support for project references
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Oct 16, 2020
1 parent e441441 commit ffcf32b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
19 changes: 9 additions & 10 deletions src/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))

/**
Expand All @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions src/langSvc/createHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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 => {
Expand All @@ -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,
Expand Down

0 comments on commit ffcf32b

Please sign in to comment.