diff --git a/src/compiler/path.ts b/src/compiler/path.ts index d7d8d964d542b..a550e1a0e9b57 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 011baa788b1a2..d512087154473 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 3412c1c1598f7..c0a9b9530abe5 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));