Refactor out file helpers into fs.ts

This commit is contained in:
Saoud Rizwan
2024-09-29 02:25:22 -04:00
parent ebead1b1fa
commit 2b63b91bfb
6 changed files with 107 additions and 117 deletions

View File

@@ -2,14 +2,12 @@ import * as fs from "fs/promises"
import * as path from "path"
import { listFiles } from "../glob/list-files"
import { LanguageParser, loadRequiredLanguageParsers } from "./languageParser"
import { fileExistsAtPath } from "../../utils/fs"
// TODO: implement caching behavior to avoid having to keep analyzing project for new tasks.
export async function parseSourceCodeForDefinitionsTopLevel(dirPath: string): Promise<string> {
// check if the path exists
const dirExists = await fs
.access(path.resolve(dirPath))
.then(() => true)
.catch(() => false)
const dirExists = await fileExistsAtPath(path.resolve(dirPath))
if (!dirExists) {
return "This directory does not exist or you do not have permission to access it."
}