Merge pull request #9396 from zhengbli/fix9186
Check getCurrentDirectory availability in getEffectiveTypeRoots
This commit is contained in:
commit
50177b14d0
2 changed files with 31 additions and 6 deletions
|
@ -187,8 +187,22 @@ namespace ts {
|
|||
const typeReferenceExtensions = [".d.ts"];
|
||||
|
||||
function getEffectiveTypeRoots(options: CompilerOptions, host: ModuleResolutionHost) {
|
||||
return options.typeRoots ||
|
||||
map(defaultTypeRoots, d => combinePaths(options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory(), d));
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -228,7 +242,7 @@ namespace ts {
|
|||
const failedLookupLocations: string[] = [];
|
||||
|
||||
// Check primary library paths
|
||||
if (typeRoots.length) {
|
||||
if (typeRoots && typeRoots.length) {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", "));
|
||||
}
|
||||
|
@ -1046,9 +1060,11 @@ namespace ts {
|
|||
let result: string[] = [];
|
||||
if (host.directoryExists && host.getDirectories) {
|
||||
const typeRoots = getEffectiveTypeRoots(options, host);
|
||||
for (const root of typeRoots) {
|
||||
if (host.directoryExists(root)) {
|
||||
result = result.concat(host.getDirectories(root));
|
||||
if (typeRoots) {
|
||||
for (const root of typeRoots) {
|
||||
if (host.directoryExists(root)) {
|
||||
result = result.concat(host.getDirectories(root));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
9
tests/cases/fourslash/server/typeReferenceOnServer.ts
Normal file
9
tests/cases/fourslash/server/typeReferenceOnServer.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
/// <reference path='../fourslash.ts' />
|
||||
|
||||
/////// <reference types="foo" />
|
||||
////var x: number;
|
||||
////x./*1*/
|
||||
|
||||
goTo.marker("1");
|
||||
verify.not.completionListIsEmpty();
|
||||
|
Loading…
Reference in a new issue