mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Reuse effective type roots code in language service
This commit is contained in:
parent
276b56dfb0
commit
fb6ff42b93
@ -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)) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user