Support path completions inside node_modules (#19692)

* Support path completions inside node_modules

* Fix: Start searching from current file's directory, not host.getCurrentDirectory()

* Add test for nested node_modules

* Also test in /src/folder/b.ts
This commit is contained in:
Andy
2017-11-03 15:05:44 -07:00
committed by GitHub
parent 78421e87f7
commit 749e151c23
2 changed files with 31 additions and 1 deletions

View File

@@ -144,8 +144,8 @@ namespace ts.Completions.PathCompletions {
let result: CompletionEntry[];
const fileExtensions = getSupportedExtensions(compilerOptions);
if (baseUrl) {
const fileExtensions = getSupportedExtensions(compilerOptions);
const projectDir = compilerOptions.project || host.getCurrentDirectory();
const absolute = isRootedDiskPath(baseUrl) ? baseUrl : combinePaths(projectDir, baseUrl);
result = getCompletionEntriesForDirectoryFragment(fragment, normalizePath(absolute), fileExtensions, /*includeExtensions*/ false, span, host);
@@ -176,6 +176,15 @@ namespace ts.Completions.PathCompletions {
result = [];
}
if (compilerOptions.moduleResolution === ts.ModuleResolutionKind.NodeJs) {
forEachAncestorDirectory(scriptPath, ancestor => {
const nodeModules = combinePaths(ancestor, "node_modules");
if (host.directoryExists(nodeModules)) {
getCompletionEntriesForDirectoryFragment(fragment, nodeModules, fileExtensions, /*includeExtensions*/ false, span, host, /*exclude*/ undefined, result);
}
});
}
getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, span, result);
for (const moduleName of enumeratePotentialNonRelativeModules(fragment, scriptPath, compilerOptions, typeChecker, host)) {