enso/app/gui2/shared/languageServer/files.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
868 B
TypeScript
Raw Normal View History

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))
}
}
}
}