diff --git a/src/utils.ts b/src/utils.ts index 007c7bb..9503f6e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,14 +2,23 @@ import fs from 'fs'; import path from 'path'; import { TextDocument, Position } from 'vscode'; -export function collectFshFilesForPath(filepath: string, fshFiles: string[]): void { - const stats = fs.statSync(filepath); +export function collectFshFilesForPath( + filepath: string, + fshFiles: string[], + visitedPaths: Set = new Set() +) { + const realPath = fs.realpathSync(filepath); + if (visitedPaths.has(realPath)) { + return; + } + visitedPaths.add(realPath); + const stats = fs.statSync(realPath); if (stats.isDirectory()) { - fs.readdirSync(filepath).forEach(file => { - collectFshFilesForPath(path.join(filepath, file), fshFiles); + fs.readdirSync(realPath).forEach(file => { + collectFshFilesForPath(path.join(realPath, file), fshFiles, visitedPaths); }); } else if (filepath.endsWith('.fsh')) { - fshFiles.push(filepath); + fshFiles.push(realPath); } }