mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
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:
@@ -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)) {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @moduleResolution: node
|
||||
|
||||
// @Filename: /node_modules/x/foo.d.ts
|
||||
////not read
|
||||
|
||||
// @Filename: /node_modules/x/bar.d.ts
|
||||
////not read
|
||||
|
||||
// @Filename: /src/node_modules/y/index.d.ts
|
||||
////not read
|
||||
|
||||
// @Filename: /src/a.ts
|
||||
////import {} from "/*1*/";
|
||||
|
||||
// @Filename: /src/folder/b.ts
|
||||
////import {} from "x//*2*/";
|
||||
|
||||
verify.completionsAt("1", ["y", "x"]);
|
||||
verify.completionsAt("2", ["bar", "foo"]);
|
||||
Reference in New Issue
Block a user