def work

bolt@1.27.0.0 · src/lsp/server.bend:551

import bolt@1.27.0.0/src/lsp/server.bend as Server
import Base
import emerging-ezjson@1.2.0.0/main.bend as Ezjson
import emerging-ezjson@1.2.0.0/src/value.bend as J
import bolt@1.27.0.0/src/lsp/proto.bend as Proto
import bolt@1.27.0.0/src/lsp/docs.bend as Docs
import bolt@1.27.0.0/src/lsp/checker/answer.bend as C
import bolt@1.27.0.0/src/lsp/files/service.bend as F
import bolt@1.27.0.0/src/lsp/enc.bend as Enc

551# the work behind a method: what the checker, the files and the documents
552# give it. It does not see the message's id: step alone puts that on a reply
553def work(  # noqa: L001 LSP IO glue
554  ~fs: F.Files,
555  ~ck: C.Checker,
556  ee: Enc.Enc,
557  mm: Method,
558  +params: J.Json,
559  +docs: List<&2, Docs.Doc>
560) -> IO(Work):
561  match mm:
562    case MInitialize{}:
563      IO.pure(Work, answered(Proto.capabilities(ee), docs))
564    case MShutdown{}:
565      IO.pure(Work, answered(J.JNull{}, docs))
566    case MExit{}:
567      IO.pure(Work, noted([], docs))
568    case MOpen{}:
569      pub.opened(~fs, ~ck, ee, uri_of(params),
570        Maybe.default(&2, String, Ezjson.as_str(Ezjson.get(Ezjson.get(params, "textDocument"), "text")), ""), docs)
571    case MChange{}:
572      pub.changed(~fs, ee, uri_of(params),
573        Maybe.default(&2, String, Ezjson.as_str(Ezjson.get(Ezjson.at(Ezjson.get(params, "contentChanges"), 0), "text")), ""), docs)
574    case MSave{}:
575      pub.saved(~fs, ~ck, ee, uri_of(params), docs)
576    case MClose{}:
577      IO.pure(Work, pub.close(ee, uri_of(params), docs))
578    case MHover{}:
579      hovered(~fs, ee, docs, uri_of(params), params)
580    case MDefinition{}:
581      defined(~fs, ee, docs, uri_of(params), params)
582    case MSymbols{}:
583      symbols(~fs, ee, docs, uri_of(params))
584    case MCompletion{}:
585      complete(~fs, ee, docs, uri_of(params), params)
586    case MReferences{}:
587      references(~fs, ee, docs, uri_of(params), params)
588    case MRename{}:
589      renamed(~fs, ee, docs, uri_of(params), params)
590    case MSemantic{}:
591      semantic(~fs, ee, docs, uri_of(params))
592    case MOther{}:
593      IO.pure(Work, noted([], docs))

Uses (30)

Used by (1)