File: .lake/packages/lean4/src/lean/Lean/Server/Requests.lean

full_name: Lean.Server.instInhabitedRequestError
code: structure RequestError where
  code    : JsonRpc.ErrorCode
  message : String
  deriving Inhabited
goal: Inhabited Lean.Server.RequestError

full_name: Lean.Server.RequestError.code
code: structure RequestError where
  code    : JsonRpc.ErrorCode
  message : String
  deriving Inhabited
goal: Lean.JsonRpc.ErrorCode

full_name: Lean.Server.RequestError.message
code: structure RequestError where
  code    : JsonRpc.ErrorCode
  message : String
  deriving Inhabited
goal: String

full_name: Lean.Server.RequestError
code: structure RequestError where
  code    : JsonRpc.ErrorCode
  message : String
  deriving Inhabited
goal: Type

full_name: Lean.Server.RequestError.fileChanged
code: def fileChanged : RequestError 
goal: Lean.Server.RequestError

full_name: Lean.Server.RequestError.methodNotFound
code: def methodNotFound (method : String) : RequestError 
goal: Lean.Server.RequestError

full_name: Lean.Server.RequestError.invalidParams
code: def invalidParams (message : String) : RequestError 
goal: Lean.Server.RequestError

full_name: Lean.Server.RequestError.internalError
code: def internalError (message : String) : RequestError 
goal: Lean.Server.RequestError

full_name: Lean.Server.RequestError.ofException
code: def ofException (e : Lean.Exception) : IO RequestError 
goal: IO Lean.Server.RequestError

full_name: Lean.Server.RequestError.ofIoError
code: def ofIoError (e : IO.Error) : RequestError 
goal: Lean.Server.RequestError

full_name: Lean.Server.RequestError.toLspResponseError
code: def toLspResponseError (id : RequestID) (e : RequestError) : ResponseError Unit 
goal: Lean.JsonRpc.ResponseError Unit

full_name: Lean.Server.parseRequestParams
code: def parseRequestParams (paramType : Type) [FromJson paramType] (params : Json)
    : Except RequestError paramType 
goal: Except Lean.Server.RequestError paramType

full_name: Lean.Server.RequestContext.hLog
code: structure RequestContext where
  rpcSessions   : RBMap UInt64 (IO.Ref FileWorker.RpcSession) compare
  srcSearchPath : SearchPath
  doc           : FileWorker.EditableDocument
  hLog          : IO.FS.Stream
  initParams    : Lsp.InitializeParams
goal: IO.FS.Stream

full_name: Lean.Server.RequestContext.rpcSessions
code: structure RequestContext where
  rpcSessions   : RBMap UInt64 (IO.Ref FileWorker.RpcSession) compare
  srcSearchPath : SearchPath
  doc           : FileWorker.EditableDocument
  hLog          : IO.FS.Stream
  initParams    : Lsp.InitializeParams
goal: Lean.RBMap UInt64 (IO.Ref Lean.Server.FileWorker.RpcSession) compare

full_name: Lean.Server.RequestContext.srcSearchPath
code: structure RequestContext where
  rpcSessions   : RBMap UInt64 (IO.Ref FileWorker.RpcSession) compare
  srcSearchPath : SearchPath
  doc           : FileWorker.EditableDocument
  hLog          : IO.FS.Stream
  initParams    : Lsp.InitializeParams
goal: Lean.SearchPath

full_name: Lean.Server.RequestContext
code: structure RequestContext where
  rpcSessions   : RBMap UInt64 (IO.Ref FileWorker.RpcSession) compare
  srcSearchPath : SearchPath
  doc           : FileWorker.EditableDocument
  hLog          : IO.FS.Stream
  initParams    : Lsp.InitializeParams
goal: Type

full_name: Lean.Server.RequestContext.doc
code: structure RequestContext where
  rpcSessions   : RBMap UInt64 (IO.Ref FileWorker.RpcSession) compare
  srcSearchPath : SearchPath
  doc           : FileWorker.EditableDocument
  hLog          : IO.FS.Stream
  initParams    : Lsp.InitializeParams
goal: Lean.Server.FileWorker.EditableDocument

full_name: Lean.Server.RequestContext.initParams
code: structure RequestContext where
  rpcSessions   : RBMap UInt64 (IO.Ref FileWorker.RpcSession) compare
  srcSearchPath : SearchPath
  doc           : FileWorker.EditableDocument
  hLog          : IO.FS.Stream
  initParams    : Lsp.InitializeParams
goal: Lean.Lsp.InitializeParams

full_name: Lean.Server.RequestTask
code: abbrev RequestTask α 
goal: Type u_1

full_name: Lean.Server.RequestT
code: abbrev RequestT m 
goal: Type u_1

full_name: Lean.Server.RequestM
code: /-- Workers execute request handlers in this monad. -/
abbrev RequestM 
goal: Type

full_name: Lean.Server.RequestTask.pure
code: abbrev RequestTask.pure (a : α) : RequestTask α 
goal: Lean.Server.RequestTask α

full_name: Lean.Server.instMonadLiftIORequestM
code: instance : MonadLift IO RequestM 
goal: MonadLift IO Lean.Server.RequestM

full_name: Lean.Server.instMonadLiftEIOExceptionRequestM
code: instance : MonadLift (EIO Exception) RequestM 
goal: MonadLift (EIO Lean.Exception) Lean.Server.RequestM

full_name: Lean.Server.RequestM.readDoc
code: def readDoc [Monad m] [MonadReaderOf RequestContext m] : m EditableDocument 
goal: m Lean.Server.FileWorker.EditableDocument

full_name: Lean.Server.RequestM.asTask
code: def asTask (t : RequestM α) : RequestM (RequestTask α) 
goal: Lean.Server.RequestM (Lean.Server.RequestTask α)

full_name: Lean.Server.RequestM.mapTask
code: def mapTask (t : Task α) (f : α → RequestM β) : RequestM (RequestTask β) 
goal: Lean.Server.RequestM (Lean.Server.RequestTask β)

full_name: Lean.Server.RequestM.bindTask
code: def bindTask (t : Task α) (f : α → RequestM (RequestTask β)) : RequestM (RequestTask β) 
goal: Lean.Server.RequestM (Lean.Server.RequestTask β)

full_name: Lean.Server.RequestM.waitFindSnapAux
code: def waitFindSnapAux (notFoundX : RequestM α) (x : Snapshot → RequestM α)
    : Except IO.Error (Option Snapshot) → RequestM α
  /- The elaboration task that we're waiting for may be aborted if the file contents change.
  In that case, we reply with the `fileChanged` error by default. Thanks to this, the server doesn't
  get bogged down in requests for an old state of the document. -/
  
goal: Except IO.Error (Option Lean.Server.Snapshots.Snapshot) → Lean.Server.RequestM α

full_name: Lean.Server.RequestM.withWaitFindSnap
code: /-- Create a task which waits for the first snapshot matching `p`, handles various errors,
and if a matching snapshot was found executes `x` with it. If not found, the task executes
`notFoundX`. -/
def withWaitFindSnap (doc : EditableDocument) (p : Snapshot → Bool)
    (notFoundX : RequestM β)
    (x : Snapshot → RequestM β)
    : RequestM (RequestTask β) 
goal: Lean.Server.RequestM (Lean.Server.RequestTask β)

full_name: Lean.Server.RequestM.bindWaitFindSnap
code: /-- See `withWaitFindSnap`. -/
def bindWaitFindSnap (doc : EditableDocument) (p : Snapshot → Bool)
    (notFoundX : RequestM (RequestTask β))
    (x : Snapshot → RequestM (RequestTask β))
    : RequestM (RequestTask β) 
goal: Lean.Server.RequestM (Lean.Server.RequestTask β)

full_name: Lean.Server.RequestM.withWaitFindSnapAtPos
code: /-- Create a task which waits for the snapshot containing `lspPos` and executes `f` with it.
If no such snapshot exists, the request fails with an error. -/
def withWaitFindSnapAtPos
    (lspPos : Lsp.Position)
    (f : Snapshots.Snapshot → RequestM α)
    : RequestM (RequestTask α) 
goal: Lean.Server.RequestM (Lean.Server.RequestTask α)

full_name: Lean.Server.RequestM.runCommandElabM
code: def runCommandElabM (snap : Snapshot) (c : RequestT CommandElabM α) : RequestM α 
goal: Lean.Server.RequestM α

full_name: Lean.Server.RequestM.runCoreM
code: def runCoreM (snap : Snapshot) (c : RequestT CoreM α) : RequestM α 
goal: Lean.Server.RequestM α

full_name: Lean.Server.RequestM.runTermElabM
code: def runTermElabM (snap : Snapshot) (c : RequestT TermElabM α) : RequestM α 
goal: Lean.Server.RequestM α

full_name: Lean.Server.RequestHandler
code: structure RequestHandler where
  fileSource : Json → Except RequestError Lsp.DocumentUri
  handle : Json → RequestM (RequestTask Json)
goal: Type

full_name: Lean.Server.RequestHandler.fileSource
code: structure RequestHandler where
  fileSource : Json → Except RequestError Lsp.DocumentUri
  handle : Json → RequestM (RequestTask Json)
goal: Lean.Json → Except Lean.Server.RequestError Lean.Lsp.DocumentUri

full_name: Lean.Server.RequestHandler.handle
code: structure RequestHandler where
  fileSource : Json → Except RequestError Lsp.DocumentUri
  handle : Json → RequestM (RequestTask Json)
goal: Lean.Json → Lean.Server.RequestM (Lean.Server.RequestTask Lean.Json)

full_name: Lean.Server.initFn._@..lake.packages.lean4.src.lean.Lean.Server.Requests._hyg.1143
code: builtin_initialize requestHandlers : IO.Ref (PersistentHashMap String RequestHandler) ←
  IO.mkRef {}
goal: IO (IO.Ref (Lean.PersistentHashMap String Lean.Server.RequestHandler))

full_name: Lean.Server.requestHandlers
code: builtin_initialize requestHandlers : IO.Ref (PersistentHashMap String RequestHandler) ←
  IO.mkRef {}
goal: IO.Ref (Lean.PersistentHashMap String Lean.Server.RequestHandler)

full_name: Lean.Server.registerLspRequestHandler
code: /-- NB: This method may only be called in `initialize` blocks (user or builtin).

A registration consists of:
- a type of JSON-parsable request data `paramType`
- a `FileSource` instance for it so the system knows where to route requests
- a type of JSON-serializable response data `respType`
- an actual `handler` which runs in the `RequestM` monad and is expected
  to produce an asynchronous `RequestTask` which does any waiting/computation

A handler task may be cancelled at any time, so it should check the cancellation token when possible
to handle this cooperatively. Any exceptions thrown in a request handler will be reported to the client
as LSP error responses. -/
def registerLspRequestHandler (method : String)
    paramType [FromJson paramType] [FileSource paramType]
    respType [ToJson respType]
    (handler : paramType → RequestM (RequestTask respType)) : IO Unit 
goal: IO Unit

full_name: Lean.Server.lookupLspRequestHandler
code: def lookupLspRequestHandler (method : String) : IO (Option RequestHandler) 
goal: IO (Option Lean.Server.RequestHandler)

full_name: Lean.Server.chainLspRequestHandler
code: /-- NB: This method may only be called in `initialize` blocks (user or builtin).

Register another handler to invoke after the last one registered for a method.
At least one handler for the method must have already been registered to perform
chaining.

For more details on the registration of a handler, see `registerLspRequestHandler`. -/
def chainLspRequestHandler (method : String)
    paramType [FromJson paramType]
    respType [FromJson respType] [ToJson respType]
    (handler : paramType → RequestTask respType → RequestM (RequestTask respType)) : IO Unit 
goal: IO Unit

full_name: Lean.Server.routeLspRequest
code: def routeLspRequest (method : String) (params : Json) : IO (Except RequestError DocumentUri) 
goal: IO (Except Lean.Server.RequestError Lean.Lsp.DocumentUri)

full_name: Lean.Server.handleLspRequest
code: def handleLspRequest (method : String) (params : Json) : RequestM (RequestTask Json) 
goal: Lean.Server.RequestM (Lean.Server.RequestTask Lean.Json)