Reuse effective type roots code in language service

This commit is contained in:
Richard Knoll 2016-08-26 18:03:20 -07:00
parent 276b56dfb0
commit fb6ff42b93
2 changed files with 8 additions and 18 deletions

View File

@ -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)) {

View File

@ -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);
}
}