import { fdir } from "fdir";
import { URI } from "langium";
import { NodeFileSystemProvider } from "langium/node";
import { LikeC4LanguageMetaData } from "./generated/module.js";
import { logger } from "./logger.js";
export const LikeC4FileSystem = {
  fileSystemProvider: () => new SymLinkTraversingFileSystemProvider()
};
const hasExtension = (path) => LikeC4LanguageMetaData.fileExtensions.some((ext) => path.endsWith(ext));
class SymLinkTraversingFileSystemProvider extends NodeFileSystemProvider {
  async readDirectory(folderPath) {
    const entries = [];
    try {
      const crawled = await new fdir().withSymlinks().withFullPaths().filter(hasExtension).crawl(folderPath.fsPath).withPromise();
      for (const path of crawled) {
        entries.push({
          isFile: true,
          isDirectory: false,
          uri: URI.file(path)
        });
      }
    } catch (error) {
      logger.error(error);
    }
    return entries;
  }
}
