~/bend-docscommunity

bolt/lsp/files/service.bend source

bolt/lsp/files/service.bend on the hub · documented module

# files: an effect service: a file's text by path, and where Base lives.import Base# effect service: a file's text, and where Base istype Files is Type:  Files{read: String -> IO(Maybe<&2, String>), base_path: Unit -> IO(String)}# None when the file cannot be readdef read(f: Files, path: String) -> IO(Maybe<&2, String>):  Files{r, b} = f  r(path)# the path of Base, from a files servicedef base_path(f: Files) -> IO(String):  Files{r, b} = f  b(Unit{})# every path read, in order (a missing file is a None)def read_all(~f: Files, paths: List<&2, String>) -> IO(List<&2, Maybe<&2, String>>):  match paths:    case Nil{}:      IO.pure(List<&2, Maybe<&2, String>>, [])    case Con{p, rest}:      do IO<List<&2, Maybe<&2, String>>>:        r : Maybe<&2, String> <- read(f, p)        more : List<&2, Maybe<&2, String>> <- read_all(~f, rest)        return r <> more