From dd6811fbe37f05a2b79427112a919d75a7417176 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Mon, 2 Mar 2020 16:52:03 -0800 Subject: [PATCH] Stop looking for the default configured project at node_modules (#35011) * Optionally stop looking for the default configured project at node_modules * Make stopping at node_modules non-optional * Generalize and simplify the change - node_modules files don't have default configured projects --- src/compiler/path.ts | 4 ++++ src/compiler/resolutionCache.ts | 4 ---- src/server/editorServices.ts | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/compiler/path.ts b/src/compiler/path.ts index d7d8d964d54..a550e1a0e9b 100644 --- a/src/compiler/path.ts +++ b/src/compiler/path.ts @@ -852,4 +852,8 @@ namespace ts { directory = parentPath; } } + + export function isNodeModulesDirectory(dirPath: Path) { + return endsWith(dirPath, "/node_modules"); + } } \ No newline at end of file diff --git a/src/compiler/resolutionCache.ts b/src/compiler/resolutionCache.ts index 011baa788b1..d5120871544 100644 --- a/src/compiler/resolutionCache.ts +++ b/src/compiler/resolutionCache.ts @@ -428,10 +428,6 @@ namespace ts { return cache && cache.get(moduleName); } - function isNodeModulesDirectory(dirPath: Path) { - return endsWith(dirPath, "/node_modules"); - } - function isNodeModulesAtTypesDirectory(dirPath: Path) { return endsWith(dirPath, "/node_modules/@types"); } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 47ab9e6a12f..a79070dde80 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1664,6 +1664,13 @@ namespace ts.server { const jsconfigFileName = asNormalizedPath(combinePaths(searchPath, "jsconfig.json")); result = action(jsconfigFileName, combinePaths(canonicalSearchPath, "jsconfig.json")); if (result) return jsconfigFileName; + + // If we started within node_modules, don't look outside node_modules. + // Otherwise, we might pick up a very large project and pull in the world, + // causing an editor delay. + if (isNodeModulesDirectory(canonicalSearchPath)) { + break; + } } const parentPath = asNormalizedPath(getDirectoryPath(searchPath));