mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 04:43:26 +03:00
168e222fcc
- Closes #8077 # Important Notes Tests are still WIP
34 lines
868 B
TypeScript
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))
|
|
}
|
|
}
|
|
}
|
|
}
|