Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update collectFshFilesForPath to not check the same folder multiple times #99

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading