@@ -280,36 +280,50 @@ func GetEachFileNameOfModule(
280280 }
281281 }
282282
283- // !!! TODO: Symlink directory handling
284- // const symlinkedDirectories = host.getSymlinkCache?.().getSymlinkedDirectoriesByRealpath();
285- // const fullImportedFileName = getNormalizedAbsolutePath(importedFileName, cwd);
286- // const result = symlinkedDirectories && forEachAncestorDirectoryStoppingAtGlobalCache(
287- // host,
288- // getDirectoryPath(fullImportedFileName),
289- // realPathDirectory => {
290- // const symlinkDirectories = symlinkedDirectories.get(ensureTrailingDirectorySeparator(toPath(realPathDirectory, cwd, getCanonicalFileName)));
291- // if (!symlinkDirectories) return undefined; // Continue to ancestor directory
292-
293- // // Don't want to a package to globally import from itself (importNameCodeFix_symlink_own_package.ts)
294- // if (startsWithDirectory(importingFileName, realPathDirectory, getCanonicalFileName)) {
295- // return false; // Stop search, each ancestor directory will also hit this condition
296- // }
297-
298- // return forEach(targets, target => {
299- // if (!startsWithDirectory(target, realPathDirectory, getCanonicalFileName)) {
300- // return;
301- // }
302-
303- // const relative = getRelativePathFromDirectory(realPathDirectory, target, getCanonicalFileName);
304- // for (const symlinkDirectory of symlinkDirectories) {
305- // const option = resolvePath(symlinkDirectory, relative);
306- // const result = cb(option, target === referenceRedirect);
307- // shouldFilterIgnoredPaths = true; // We found a non-ignored path in symlinks, so we can reject ignored-path realpaths
308- // if (result) return result;
309- // }
310- // });
311- // },
312- // );
283+ symlinkedDirectories := host .GetSymlinkCache ().DirectoriesByRealpath ()
284+ fullImportedFileName := tspath .GetNormalizedAbsolutePath (importedFileName , cwd )
285+ if symlinkedDirectories != nil {
286+ tspath .ForEachAncestorDirectoryStoppingAtGlobalCache (
287+ host .GetGlobalTypingsCacheLocation (),
288+ tspath .GetDirectoryPath (fullImportedFileName ),
289+ func (realPathDirectory string ) (bool , bool ) {
290+ symlinkDirectories := symlinkedDirectories .Get (tspath .ToPath (realPathDirectory , cwd , host .UseCaseSensitiveFileNames ()).EnsureTrailingDirectorySeparator ())
291+ if symlinkDirectories == nil {
292+ return false , false
293+ } // Continue to ancestor directory
294+
295+ // Don't want to a package to globally import from itself (importNameCodeFix_symlink_own_package.ts)
296+ if tspath .StartsWithDirectory (importingFileName , realPathDirectory , host .UseCaseSensitiveFileNames ()) {
297+ return false , true // Stop search, each ancestor directory will also hit this condition
298+ }
299+
300+ for _ , target := range targets {
301+ if ! tspath .StartsWithDirectory (target , realPathDirectory , host .UseCaseSensitiveFileNames ()) {
302+ continue
303+ }
304+
305+ relative := tspath .GetRelativePathFromDirectory (
306+ realPathDirectory ,
307+ target ,
308+ tspath.ComparePathsOptions {
309+ UseCaseSensitiveFileNames : host .UseCaseSensitiveFileNames (),
310+ CurrentDirectory : cwd ,
311+ })
312+ for _ , symlinkDirectory := range symlinkDirectories {
313+ option := tspath .ResolvePath (symlinkDirectory , relative )
314+ results = append (results , ModulePath {
315+ FileName : option ,
316+ IsInNodeModules : ContainsNodeModules (option ),
317+ IsRedirect : target == referenceRedirect ,
318+ })
319+ shouldFilterIgnoredPaths = true // We found a non-ignored path in symlinks, so we can reject ignored-path realpaths
320+ }
321+ }
322+
323+ return false , false
324+ },
325+ )
326+ }
313327
314328 if preferSymlinks {
315329 for _ , p := range targets {
0 commit comments