diff --git a/src/compiler/program.ts b/src/compiler/program.ts index f48f29785d9..7048496ada1 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -168,22 +168,19 @@ namespace ts { const typeReferenceExtensions = [".d.ts"]; - function getEffectiveTypeRoots(options: CompilerOptions, host: ModuleResolutionHost) { + export function getEffectiveTypeRoots(options: CompilerOptions, currentDirectory: string) { if (options.typeRoots) { return options.typeRoots; } - let currentDirectory: string; if (options.configFilePath) { currentDirectory = getDirectoryPath(options.configFilePath); } - else if (host.getCurrentDirectory) { - currentDirectory = host.getCurrentDirectory(); - } if (!currentDirectory) { return undefined; } + return map(defaultTypeRoots, d => combinePaths(currentDirectory, d)); } @@ -201,7 +198,7 @@ namespace ts { traceEnabled }; - const typeRoots = getEffectiveTypeRoots(options, host); + const typeRoots = getEffectiveTypeRoots(options, host.getCurrentDirectory && host.getCurrentDirectory()); if (traceEnabled) { if (containingFile === undefined) { if (typeRoots === undefined) { @@ -1061,7 +1058,7 @@ namespace ts { // Walk the primary type lookup locations const result: string[] = []; if (host.directoryExists && host.getDirectories) { - const typeRoots = getEffectiveTypeRoots(options, host); + const typeRoots = getEffectiveTypeRoots(options, host.getCurrentDirectory && host.getCurrentDirectory()); if (typeRoots) { for (const root of typeRoots) { if (host.directoryExists(root)) { diff --git a/src/services/services.ts b/src/services/services.ts index 8bb378e090a..519a5abe8cf 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4846,17 +4846,10 @@ namespace ts { result.push(createCompletionEntryForModule(moduleName, ScriptElementKind.externalModuleName)); } } - else if (host.getDirectories && options.typeRoots) { - const absoluteRoots = map(options.typeRoots, rootDirectory => { - if (isRootedDiskPath(rootDirectory)) { - return normalizePath(rootDirectory); - } - - const basePath = options.project || host.getCurrentDirectory(); - return normalizePath(combinePaths(basePath, rootDirectory)); - }); - for (const absoluteRoot of absoluteRoots) { - getCompletionEntriesFromDirectories(host, options, absoluteRoot, result); + else if (host.getDirectories) { + const typeRoots = getEffectiveTypeRoots(options, host.getCurrentDirectory()); + for (const root of typeRoots) { + getCompletionEntriesFromDirectories(host, options, root, result); } }