mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 22:01:42 +03:00
de406c69fa
Fixes #8520 If the websocket is closed not by us, we automatically try to reconnect with it, and initialize the protocol again. **Restoring state (execution contexts, attached visualizations) is not part of this PR**. It's a part of making IDE work after hibernation (or LS crash). # Important Notes It required somewhat heavy refactoring: 1. I decided to use an existing implementation of reconnecting websocket. Replaced (later discovered by me) our implementation. 2. The LanguageServer class now handles both reconnecting and re-initializing - that make usage of it simpler (no more `Promise<LanguageServer>` - each method will just wait for (re)connection and initialization. 3. The stuff in `net` src's module was partially moved to shared's counterpart (with tests). Merged `exponentialBackoff` implementations, which also brought me to 4. Rewriting LS client, so it returns Result instead of throwing, what is closer our desired state, and allows us using exponentialBackoff method without any wrappers.
38 lines
1007 B
TypeScript
38 lines
1007 B
TypeScript
import { type LanguageServer } from '../languageServer'
|
|
import type { FileSystemObject, Path } from '../languageServerTypes'
|
|
import { Err, Ok, type Result } from '../util/data/result'
|
|
|
|
export async function walkFs(
|
|
ls: LanguageServer,
|
|
path: Path,
|
|
cb: (type: FileSystemObject['type'], path: Path) => void,
|
|
): Promise<Result<void>> {
|
|
const files = await ls.listFiles(path)
|
|
if (!files.ok) return files
|
|
for (const file of files.value.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
|
|
return Err('Unexpected object: ' + JSON.stringify(unexpected))
|
|
}
|
|
}
|
|
}
|
|
return Ok()
|
|
}
|