Skip to content

Commit

Permalink
Update collectFshFilesForPath to not check the same folder multiple t…
Browse files Browse the repository at this point in the history
…imes (#99)

* Update collectFshFilesForPath to work better with monorepos

* Remove excess default

---------

Co-authored-by: Ethan Diamond <[email protected]>
  • Loading branch information
ethanjdiamond and Ethan Diamond authored Oct 23, 2024
1 parent 9f17be9 commit 2eeffc6
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> = 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);
}
}

Expand Down

0 comments on commit 2eeffc6

Please sign in to comment.