Skip to content

Commit fb6ff42

Browse files
committed
Reuse effective type roots code in language service
1 parent 276b56d commit fb6ff42

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

src/compiler/program.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,19 @@ namespace ts {
168168

169169
const typeReferenceExtensions = [".d.ts"];
170170

171-
function getEffectiveTypeRoots(options: CompilerOptions, host: ModuleResolutionHost) {
171+
export function getEffectiveTypeRoots(options: CompilerOptions, currentDirectory: string) {
172172
if (options.typeRoots) {
173173
return options.typeRoots;
174174
}
175175

176-
let currentDirectory: string;
177176
if (options.configFilePath) {
178177
currentDirectory = getDirectoryPath(options.configFilePath);
179178
}
180-
else if (host.getCurrentDirectory) {
181-
currentDirectory = host.getCurrentDirectory();
182-
}
183179

184180
if (!currentDirectory) {
185181
return undefined;
186182
}
183+
187184
return map(defaultTypeRoots, d => combinePaths(currentDirectory, d));
188185
}
189186

@@ -201,7 +198,7 @@ namespace ts {
201198
traceEnabled
202199
};
203200

204-
const typeRoots = getEffectiveTypeRoots(options, host);
201+
const typeRoots = getEffectiveTypeRoots(options, host.getCurrentDirectory && host.getCurrentDirectory());
205202
if (traceEnabled) {
206203
if (containingFile === undefined) {
207204
if (typeRoots === undefined) {
@@ -1061,7 +1058,7 @@ namespace ts {
10611058
// Walk the primary type lookup locations
10621059
const result: string[] = [];
10631060
if (host.directoryExists && host.getDirectories) {
1064-
const typeRoots = getEffectiveTypeRoots(options, host);
1061+
const typeRoots = getEffectiveTypeRoots(options, host.getCurrentDirectory && host.getCurrentDirectory());
10651062
if (typeRoots) {
10661063
for (const root of typeRoots) {
10671064
if (host.directoryExists(root)) {

src/services/services.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4846,17 +4846,10 @@ namespace ts {
48464846
result.push(createCompletionEntryForModule(moduleName, ScriptElementKind.externalModuleName));
48474847
}
48484848
}
4849-
else if (host.getDirectories && options.typeRoots) {
4850-
const absoluteRoots = map(options.typeRoots, rootDirectory => {
4851-
if (isRootedDiskPath(rootDirectory)) {
4852-
return normalizePath(rootDirectory);
4853-
}
4854-
4855-
const basePath = options.project || host.getCurrentDirectory();
4856-
return normalizePath(combinePaths(basePath, rootDirectory));
4857-
});
4858-
for (const absoluteRoot of absoluteRoots) {
4859-
getCompletionEntriesFromDirectories(host, options, absoluteRoot, result);
4849+
else if (host.getDirectories) {
4850+
const typeRoots = getEffectiveTypeRoots(options, host.getCurrentDirectory());
4851+
for (const root of typeRoots) {
4852+
getCompletionEntriesFromDirectories(host, options, root, result);
48604853
}
48614854
}
48624855

0 commit comments

Comments
 (0)