enso/app/gui2/shared/languageServer/files.ts
somebody1234 168e222fcc
Read custom visualizations (#8180)
- Closes #8077

# Important Notes
Tests are still WIP
2023-11-03 20:09:45 +00:00

34 lines
868 B
TypeScript

import { type LanguageServer } from 'shared/languageServer'
import type { FileSystemObject, Path } from 'shared/languageServerTypes'
export async function walkFs(
ls: LanguageServer,
path: Path,
cb: (type: FileSystemObject['type'], path: Path) => void,
) {
for (const file of (await ls.listFiles(path)).paths) {
const filePath: Path = {
rootId: file.path.rootId,
segments: [...file.path.segments, file.name],
}
cb(file.type, filePath)
switch (file.type) {
case 'Directory':
case 'DirectoryTruncated': {
walkFs(ls, filePath, cb)
break
}
case 'File':
case 'Other':
case 'SymlinkLoop': {
// Ignored.
break
}
default: {
const unexpected: never = file
throw new Error('Unexpected object: ' + JSON.stringify(unexpected))
}
}
}
}