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

full_name: Lean.Server.FileWorker.StickyDiagnostics
code: abbrev StickyDiagnostics 
goal: Type

full_name: Lean.Server.FileWorker.WorkerContext.stickyDiagnosticsRef
code: structure WorkerContext where
  /-- Synchronized output channel for LSP messages. Notifications for outdated versions are
    discarded on read. -/
  chanOut              : IO.Channel JsonRpc.Message
  /--
  Latest document version received by the client, used for filtering out notifications from
  previous versions.
  -/
  maxDocVersionRef     : IO.Ref Int
  freshRequestIdRef    : IO.Ref Int
  /--
  Channel that receives a message for every a `$/lean/fileProgress` notification, indicating whether
  the notification suggests that the file is currently being processed.
  -/
  chanIsProcessing     : IO.Channel Bool
  /--
  Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
  -/
  stickyDiagnosticsRef : IO.Ref StickyDiagnostics
  hLog                 : FS.Stream
  initParams           : InitializeParams
  processor            : Parser.InputContext → BaseIO Lean.Language.Lean.InitialSnapshot
  clientHasWidgets     : Bool
  /--
  Options defined on the worker cmdline (i.e. not including options from `setup-file`), used for
  context-free tasks such as editing delay.
  -/
  cmdlineOpts          : Options
goal: IO.Ref Lean.Server.FileWorker.StickyDiagnostics

full_name: Lean.Server.FileWorker.WorkerContext.initParams
code: structure WorkerContext where
  /-- Synchronized output channel for LSP messages. Notifications for outdated versions are
    discarded on read. -/
  chanOut              : IO.Channel JsonRpc.Message
  /--
  Latest document version received by the client, used for filtering out notifications from
  previous versions.
  -/
  maxDocVersionRef     : IO.Ref Int
  freshRequestIdRef    : IO.Ref Int
  /--
  Channel that receives a message for every a `$/lean/fileProgress` notification, indicating whether
  the notification suggests that the file is currently being processed.
  -/
  chanIsProcessing     : IO.Channel Bool
  /--
  Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
  -/
  stickyDiagnosticsRef : IO.Ref StickyDiagnostics
  hLog                 : FS.Stream
  initParams           : InitializeParams
  processor            : Parser.InputContext → BaseIO Lean.Language.Lean.InitialSnapshot
  clientHasWidgets     : Bool
  /--
  Options defined on the worker cmdline (i.e. not including options from `setup-file`), used for
  context-free tasks such as editing delay.
  -/
  cmdlineOpts          : Options
goal: Lean.Lsp.InitializeParams

full_name: Lean.Server.FileWorker.WorkerContext.chanOut
code: structure WorkerContext where
  /-- Synchronized output channel for LSP messages. Notifications for outdated versions are
    discarded on read. -/
  chanOut              : IO.Channel JsonRpc.Message
  /--
  Latest document version received by the client, used for filtering out notifications from
  previous versions.
  -/
  maxDocVersionRef     : IO.Ref Int
  freshRequestIdRef    : IO.Ref Int
  /--
  Channel that receives a message for every a `$/lean/fileProgress` notification, indicating whether
  the notification suggests that the file is currently being processed.
  -/
  chanIsProcessing     : IO.Channel Bool
  /--
  Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
  -/
  stickyDiagnosticsRef : IO.Ref StickyDiagnostics
  hLog                 : FS.Stream
  initParams           : InitializeParams
  processor            : Parser.InputContext → BaseIO Lean.Language.Lean.InitialSnapshot
  clientHasWidgets     : Bool
  /--
  Options defined on the worker cmdline (i.e. not including options from `setup-file`), used for
  context-free tasks such as editing delay.
  -/
  cmdlineOpts          : Options
goal: IO.Channel Lean.JsonRpc.Message

full_name: Lean.Server.FileWorker.WorkerContext.hLog
code: structure WorkerContext where
  /-- Synchronized output channel for LSP messages. Notifications for outdated versions are
    discarded on read. -/
  chanOut              : IO.Channel JsonRpc.Message
  /--
  Latest document version received by the client, used for filtering out notifications from
  previous versions.
  -/
  maxDocVersionRef     : IO.Ref Int
  freshRequestIdRef    : IO.Ref Int
  /--
  Channel that receives a message for every a `$/lean/fileProgress` notification, indicating whether
  the notification suggests that the file is currently being processed.
  -/
  chanIsProcessing     : IO.Channel Bool
  /--
  Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
  -/
  stickyDiagnosticsRef : IO.Ref StickyDiagnostics
  hLog                 : FS.Stream
  initParams           : InitializeParams
  processor            : Parser.InputContext → BaseIO Lean.Language.Lean.InitialSnapshot
  clientHasWidgets     : Bool
  /--
  Options defined on the worker cmdline (i.e. not including options from `setup-file`), used for
  context-free tasks such as editing delay.
  -/
  cmdlineOpts          : Options
goal: IO.FS.Stream

full_name: Lean.Server.FileWorker.WorkerContext.chanIsProcessing
code: structure WorkerContext where
  /-- Synchronized output channel for LSP messages. Notifications for outdated versions are
    discarded on read. -/
  chanOut              : IO.Channel JsonRpc.Message
  /--
  Latest document version received by the client, used for filtering out notifications from
  previous versions.
  -/
  maxDocVersionRef     : IO.Ref Int
  freshRequestIdRef    : IO.Ref Int
  /--
  Channel that receives a message for every a `$/lean/fileProgress` notification, indicating whether
  the notification suggests that the file is currently being processed.
  -/
  chanIsProcessing     : IO.Channel Bool
  /--
  Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
  -/
  stickyDiagnosticsRef : IO.Ref StickyDiagnostics
  hLog                 : FS.Stream
  initParams           : InitializeParams
  processor            : Parser.InputContext → BaseIO Lean.Language.Lean.InitialSnapshot
  clientHasWidgets     : Bool
  /--
  Options defined on the worker cmdline (i.e. not including options from `setup-file`), used for
  context-free tasks such as editing delay.
  -/
  cmdlineOpts          : Options
goal: IO.Channel Bool

full_name: Lean.Server.FileWorker.WorkerContext
code: structure WorkerContext where
  /-- Synchronized output channel for LSP messages. Notifications for outdated versions are
    discarded on read. -/
  chanOut              : IO.Channel JsonRpc.Message
  /--
  Latest document version received by the client, used for filtering out notifications from
  previous versions.
  -/
  maxDocVersionRef     : IO.Ref Int
  freshRequestIdRef    : IO.Ref Int
  /--
  Channel that receives a message for every a `$/lean/fileProgress` notification, indicating whether
  the notification suggests that the file is currently being processed.
  -/
  chanIsProcessing     : IO.Channel Bool
  /--
  Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
  -/
  stickyDiagnosticsRef : IO.Ref StickyDiagnostics
  hLog                 : FS.Stream
  initParams           : InitializeParams
  processor            : Parser.InputContext → BaseIO Lean.Language.Lean.InitialSnapshot
  clientHasWidgets     : Bool
  /--
  Options defined on the worker cmdline (i.e. not including options from `setup-file`), used for
  context-free tasks such as editing delay.
  -/
  cmdlineOpts          : Options
goal: Type

full_name: Lean.Server.FileWorker.WorkerContext.processor
code: structure WorkerContext where
  /-- Synchronized output channel for LSP messages. Notifications for outdated versions are
    discarded on read. -/
  chanOut              : IO.Channel JsonRpc.Message
  /--
  Latest document version received by the client, used for filtering out notifications from
  previous versions.
  -/
  maxDocVersionRef     : IO.Ref Int
  freshRequestIdRef    : IO.Ref Int
  /--
  Channel that receives a message for every a `$/lean/fileProgress` notification, indicating whether
  the notification suggests that the file is currently being processed.
  -/
  chanIsProcessing     : IO.Channel Bool
  /--
  Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
  -/
  stickyDiagnosticsRef : IO.Ref StickyDiagnostics
  hLog                 : FS.Stream
  initParams           : InitializeParams
  processor            : Parser.InputContext → BaseIO Lean.Language.Lean.InitialSnapshot
  clientHasWidgets     : Bool
  /--
  Options defined on the worker cmdline (i.e. not including options from `setup-file`), used for
  context-free tasks such as editing delay.
  -/
  cmdlineOpts          : Options
goal: Lean.Parser.InputContext → BaseIO Lean.Language.Lean.InitialSnapshot

full_name: Lean.Server.FileWorker.WorkerContext.freshRequestIdRef
code: structure WorkerContext where
  /-- Synchronized output channel for LSP messages. Notifications for outdated versions are
    discarded on read. -/
  chanOut              : IO.Channel JsonRpc.Message
  /--
  Latest document version received by the client, used for filtering out notifications from
  previous versions.
  -/
  maxDocVersionRef     : IO.Ref Int
  freshRequestIdRef    : IO.Ref Int
  /--
  Channel that receives a message for every a `$/lean/fileProgress` notification, indicating whether
  the notification suggests that the file is currently being processed.
  -/
  chanIsProcessing     : IO.Channel Bool
  /--
  Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
  -/
  stickyDiagnosticsRef : IO.Ref StickyDiagnostics
  hLog                 : FS.Stream
  initParams           : InitializeParams
  processor            : Parser.InputContext → BaseIO Lean.Language.Lean.InitialSnapshot
  clientHasWidgets     : Bool
  /--
  Options defined on the worker cmdline (i.e. not including options from `setup-file`), used for
  context-free tasks such as editing delay.
  -/
  cmdlineOpts          : Options
goal: IO.Ref Int

full_name: Lean.Server.FileWorker.WorkerContext.maxDocVersionRef
code: structure WorkerContext where
  /-- Synchronized output channel for LSP messages. Notifications for outdated versions are
    discarded on read. -/
  chanOut              : IO.Channel JsonRpc.Message
  /--
  Latest document version received by the client, used for filtering out notifications from
  previous versions.
  -/
  maxDocVersionRef     : IO.Ref Int
  freshRequestIdRef    : IO.Ref Int
  /--
  Channel that receives a message for every a `$/lean/fileProgress` notification, indicating whether
  the notification suggests that the file is currently being processed.
  -/
  chanIsProcessing     : IO.Channel Bool
  /--
  Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
  -/
  stickyDiagnosticsRef : IO.Ref StickyDiagnostics
  hLog                 : FS.Stream
  initParams           : InitializeParams
  processor            : Parser.InputContext → BaseIO Lean.Language.Lean.InitialSnapshot
  clientHasWidgets     : Bool
  /--
  Options defined on the worker cmdline (i.e. not including options from `setup-file`), used for
  context-free tasks such as editing delay.
  -/
  cmdlineOpts          : Options
goal: IO.Ref Int

full_name: Lean.Server.FileWorker.WorkerContext.clientHasWidgets
code: structure WorkerContext where
  /-- Synchronized output channel for LSP messages. Notifications for outdated versions are
    discarded on read. -/
  chanOut              : IO.Channel JsonRpc.Message
  /--
  Latest document version received by the client, used for filtering out notifications from
  previous versions.
  -/
  maxDocVersionRef     : IO.Ref Int
  freshRequestIdRef    : IO.Ref Int
  /--
  Channel that receives a message for every a `$/lean/fileProgress` notification, indicating whether
  the notification suggests that the file is currently being processed.
  -/
  chanIsProcessing     : IO.Channel Bool
  /--
  Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
  -/
  stickyDiagnosticsRef : IO.Ref StickyDiagnostics
  hLog                 : FS.Stream
  initParams           : InitializeParams
  processor            : Parser.InputContext → BaseIO Lean.Language.Lean.InitialSnapshot
  clientHasWidgets     : Bool
  /--
  Options defined on the worker cmdline (i.e. not including options from `setup-file`), used for
  context-free tasks such as editing delay.
  -/
  cmdlineOpts          : Options
goal: Bool

full_name: Lean.Server.FileWorker.WorkerContext.cmdlineOpts
code: structure WorkerContext where
  /-- Synchronized output channel for LSP messages. Notifications for outdated versions are
    discarded on read. -/
  chanOut              : IO.Channel JsonRpc.Message
  /--
  Latest document version received by the client, used for filtering out notifications from
  previous versions.
  -/
  maxDocVersionRef     : IO.Ref Int
  freshRequestIdRef    : IO.Ref Int
  /--
  Channel that receives a message for every a `$/lean/fileProgress` notification, indicating whether
  the notification suggests that the file is currently being processed.
  -/
  chanIsProcessing     : IO.Channel Bool
  /--
  Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
  -/
  stickyDiagnosticsRef : IO.Ref StickyDiagnostics
  hLog                 : FS.Stream
  initParams           : InitializeParams
  processor            : Parser.InputContext → BaseIO Lean.Language.Lean.InitialSnapshot
  clientHasWidgets     : Bool
  /--
  Options defined on the worker cmdline (i.e. not including options from `setup-file`), used for
  context-free tasks such as editing delay.
  -/
  cmdlineOpts          : Options
goal: Lean.Options

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.mkIleanInfoNotification
code: private def mkIleanInfoNotification (method : String) (m : DocumentMeta)
      (trees : Array Elab.InfoTree) : BaseIO (JsonRpc.Notification Lsp.LeanIleanInfoParams) 
goal: BaseIO (Lean.JsonRpc.Notification Lean.Lsp.LeanIleanInfoParams)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.mkIleanInfoUpdateNotification
code: private def mkIleanInfoUpdateNotification : DocumentMeta → Array Elab.InfoTree →
      BaseIO (JsonRpc.Notification Lsp.LeanIleanInfoParams) 
goal: Lean.Server.DocumentMeta → Array Lean.Elab.InfoTree → BaseIO (Lean.JsonRpc.Notification Lean.Lsp.LeanIleanInfoParams)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.mkIleanInfoFinalNotification
code: private def mkIleanInfoFinalNotification : DocumentMeta → Array Elab.InfoTree →
      BaseIO (JsonRpc.Notification Lsp.LeanIleanInfoParams) 
goal: Lean.Server.DocumentMeta → Array Lean.Elab.InfoTree → BaseIO (Lean.JsonRpc.Notification Lean.Lsp.LeanIleanInfoParams)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.mkImportClosureNotification
code: /-- Yields a `$/lean/importClosure` notification. -/
  private def mkImportClosureNotification (importClosure : Array DocumentUri)
      : JsonRpc.Notification Lsp.LeanImportClosureParams 
goal: Lean.JsonRpc.Notification Lean.Lsp.LeanImportClosureParams

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.ReportSnapshotsState.hasFatal
code: /-- State of `reportSnapshots`. -/
  private structure ReportSnapshotsState where
    /-- Whether we have waited for a snapshot to finish at least once (see debouncing below). -/
    hasBlocked := false
    /-- All info trees encountered so far. -/
    allInfoTrees : Array Elab.InfoTree := #[]
    /-- New info trees encountered since we last sent a .ilean update notification. -/
    newInfoTrees : Array Elab.InfoTree := #[]
    /-- Whether we encountered any snapshot with `Snapshot.isFatal`. -/
    hasFatal := false
  deriving Inhabited
goal: Bool

full_name: Lean.Server.FileWorker.instInhabitedReportSnapshotsState
code: /-- State of `reportSnapshots`. -/
  private structure ReportSnapshotsState where
    /-- Whether we have waited for a snapshot to finish at least once (see debouncing below). -/
    hasBlocked := false
    /-- All info trees encountered so far. -/
    allInfoTrees : Array Elab.InfoTree := #[]
    /-- New info trees encountered since we last sent a .ilean update notification. -/
    newInfoTrees : Array Elab.InfoTree := #[]
    /-- Whether we encountered any snapshot with `Snapshot.isFatal`. -/
    hasFatal := false
  deriving Inhabited
goal: Inhabited Lean.Server.FileWorker.ReportSnapshotsState

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.ReportSnapshotsState
code: /-- State of `reportSnapshots`. -/
  private structure ReportSnapshotsState where
    /-- Whether we have waited for a snapshot to finish at least once (see debouncing below). -/
    hasBlocked := false
    /-- All info trees encountered so far. -/
    allInfoTrees : Array Elab.InfoTree := #[]
    /-- New info trees encountered since we last sent a .ilean update notification. -/
    newInfoTrees : Array Elab.InfoTree := #[]
    /-- Whether we encountered any snapshot with `Snapshot.isFatal`. -/
    hasFatal := false
  deriving Inhabited
goal: Type

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.ReportSnapshotsState.hasBlocked
code: /-- State of `reportSnapshots`. -/
  private structure ReportSnapshotsState where
    /-- Whether we have waited for a snapshot to finish at least once (see debouncing below). -/
    hasBlocked := false
    /-- All info trees encountered so far. -/
    allInfoTrees : Array Elab.InfoTree := #[]
    /-- New info trees encountered since we last sent a .ilean update notification. -/
    newInfoTrees : Array Elab.InfoTree := #[]
    /-- Whether we encountered any snapshot with `Snapshot.isFatal`. -/
    hasFatal := false
  deriving Inhabited
goal: Bool

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.ReportSnapshotsState.newInfoTrees
code: /-- State of `reportSnapshots`. -/
  private structure ReportSnapshotsState where
    /-- Whether we have waited for a snapshot to finish at least once (see debouncing below). -/
    hasBlocked := false
    /-- All info trees encountered so far. -/
    allInfoTrees : Array Elab.InfoTree := #[]
    /-- New info trees encountered since we last sent a .ilean update notification. -/
    newInfoTrees : Array Elab.InfoTree := #[]
    /-- Whether we encountered any snapshot with `Snapshot.isFatal`. -/
    hasFatal := false
  deriving Inhabited
goal: Array Lean.Elab.InfoTree

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.ReportSnapshotsState.allInfoTrees
code: /-- State of `reportSnapshots`. -/
  private structure ReportSnapshotsState where
    /-- Whether we have waited for a snapshot to finish at least once (see debouncing below). -/
    hasBlocked := false
    /-- All info trees encountered so far. -/
    allInfoTrees : Array Elab.InfoTree := #[]
    /-- New info trees encountered since we last sent a .ilean update notification. -/
    newInfoTrees : Array Elab.InfoTree := #[]
    /-- Whether we encountered any snapshot with `Snapshot.isFatal`. -/
    hasFatal := false
  deriving Inhabited
goal: Array Lean.Elab.InfoTree

full_name: Lean.Server.FileWorker.initFn._@..lake.packages.lean4.src.lean.Lean.Server.FileWorker._hyg.296
code: register_builtin_option server.reportDelayMs : Nat := {
    defValue := 200
    group := "server"
    descr := "(server) time in milliseconds to wait before reporting progress and diagnostics on \
      document edit in order to reduce flickering

This option can only be set on the command line, not in the lakefile or via `set_option`."
  }
goal: IO (Lean.Option Nat)

full_name: Lean.Server.FileWorker.server.reportDelayMs
code: register_builtin_option server.reportDelayMs : Nat := {
    defValue := 200
    group := "server"
    descr := "(server) time in milliseconds to wait before reporting progress and diagnostics on \
      document edit in order to reduce flickering

This option can only be set on the command line, not in the lakefile or via `set_option`."
  }
goal: Lean.Option Nat

full_name: Lean.Server.FileWorker.MemorizedInteractiveDiagnostics
code: /--
  Type of state stored in `Snapshot.Diagnostics.cacheRef?`.

  See also section "Communication" in Lean/Server/README.md.
  -/
  structure MemorizedInteractiveDiagnostics where
    diags : Array Widget.InteractiveDiagnostic
  deriving TypeName
goal: Type

full_name: Lean.Server.FileWorker.MemorizedInteractiveDiagnostics.diags
code: /--
  Type of state stored in `Snapshot.Diagnostics.cacheRef?`.

  See also section "Communication" in Lean/Server/README.md.
  -/
  structure MemorizedInteractiveDiagnostics where
    diags : Array Widget.InteractiveDiagnostic
  deriving TypeName
goal: Array Lean.Widget.InteractiveDiagnostic

full_name: Lean.Server.FileWorker.instImpl._@..lake.packages.lean4.src.lean.Lean.Server.FileWorker._hyg.348
code: TypeName
goal: TypeName Lean.Server.FileWorker.MemorizedInteractiveDiagnostics

full_name: Lean.Server.FileWorker.instTypeNameMemorizedInteractiveDiagnostics
code: TypeName
goal: TypeName Lean.Server.FileWorker.MemorizedInteractiveDiagnostics

full_name: Lean.Server.FileWorker.inst._@..lake.packages.lean4.src.lean.Lean.Server.FileWorker._hyg.348
code: TypeName
goal: TypeName Lean.Server.FileWorker.MemorizedInteractiveDiagnostics

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.publishDiagnostics
code: /--
  Sends a `textDocument/publishDiagnostics` notification to the client that contains the diagnostics
  in `ctx.stickyDiagnosticsRef` and `doc.diagnosticsRef`.
  -/
  private def publishDiagnostics (ctx : WorkerContext) (doc : EditableDocumentCore)
      : BaseIO Unit 
goal: BaseIO Unit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.reportSnapshots
code: /--
    Reports status of a snapshot tree incrementally to the user: progress,
    diagnostics, .ilean reference information.

    See also section "Communication" in Lean/Server/README.md.

    Debouncing: we only report information
    * after first waiting for `reportDelayMs`, to give trivial tasks a chance to finish
    * when first blocking, i.e. not before skipping over any unchanged snapshots and such trival
      tasks
    * afterwards, each time new information is found in a snapshot
    * at the very end, if we never blocked (e.g. emptying a file should make
      sure to empty diagnostics as well eventually) -/
  private partial def reportSnapshots (ctx : WorkerContext) (doc : EditableDocumentCore)
      (cancelTk : CancelToken) : BaseIO (Task Unit) 
goal: BaseIO (Task Unit)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.reportSnapshots.go
code: /--
    Reports status of a snapshot tree incrementally to the user: progress,
    diagnostics, .ilean reference information.

    See also section "Communication" in Lean/Server/README.md.

    Debouncing: we only report information
    * after first waiting for `reportDelayMs`, to give trivial tasks a chance to finish
    * when first blocking, i.e. not before skipping over any unchanged snapshots and such trival
      tasks
    * afterwards, each time new information is found in a snapshot
    * at the very end, if we never blocked (e.g. emptying a file should make
      sure to empty diagnostics as well eventually) -/
  private partial def reportSnapshots (ctx : WorkerContext) (doc : EditableDocumentCore)
      (cancelTk : CancelToken) : BaseIO (Task Unit) 
goal: BaseIO (Task Lean.Server.FileWorker.ReportSnapshotsState)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.reportSnapshots.goSeq
code: /--
    Reports status of a snapshot tree incrementally to the user: progress,
    diagnostics, .ilean reference information.

    See also section "Communication" in Lean/Server/README.md.

    Debouncing: we only report information
    * after first waiting for `reportDelayMs`, to give trivial tasks a chance to finish
    * when first blocking, i.e. not before skipping over any unchanged snapshots and such trival
      tasks
    * afterwards, each time new information is found in a snapshot
    * at the very end, if we never blocked (e.g. emptying a file should make
      sure to empty diagnostics as well eventually) -/
  private partial def reportSnapshots (ctx : WorkerContext) (doc : EditableDocumentCore)
      (cancelTk : CancelToken) : BaseIO (Task Unit) 
goal: List (Lean.Language.SnapshotTask Lean.Language.SnapshotTree) → BaseIO (Task Lean.Server.FileWorker.ReportSnapshotsState)

full_name: Lean.Server.FileWorker.PendingRequestMap
code: abbrev PendingRequestMap 
goal: Type

full_name: Lean.Server.FileWorker.AvailableImportsCache.lastRequestTimestampMs
code: structure AvailableImportsCache where
  availableImports       : ImportCompletion.AvailableImports
  lastRequestTimestampMs : Nat
goal: Nat

full_name: Lean.Server.FileWorker.AvailableImportsCache.availableImports
code: structure AvailableImportsCache where
  availableImports       : ImportCompletion.AvailableImports
  lastRequestTimestampMs : Nat
goal: ImportCompletion.AvailableImports

full_name: Lean.Server.FileWorker.AvailableImportsCache
code: structure AvailableImportsCache where
  availableImports       : ImportCompletion.AvailableImports
  lastRequestTimestampMs : Nat
goal: Type

full_name: Lean.Server.FileWorker.WorkerState.importCachingTask?
code: structure WorkerState where
  doc                : EditableDocument
  /-- Token flagged for aborting `doc.reporter` when a new document version comes in. -/
  reporterCancelTk   : CancelToken
  srcSearchPathTask  : Task SearchPath
  importCachingTask? : Option (Task (Except Error AvailableImportsCache))
  pendingRequests    : PendingRequestMap
  /-- A map of RPC session IDs. We allow asynchronous elab tasks and request handlers
  to modify sessions. A single `Ref` ensures atomic transactions. -/
  rpcSessions        : RBMap UInt64 (IO.Ref RpcSession) compare
goal: Option (Task (Except IO.Error Lean.Server.FileWorker.AvailableImportsCache))

full_name: Lean.Server.FileWorker.WorkerState.srcSearchPathTask
code: structure WorkerState where
  doc                : EditableDocument
  /-- Token flagged for aborting `doc.reporter` when a new document version comes in. -/
  reporterCancelTk   : CancelToken
  srcSearchPathTask  : Task SearchPath
  importCachingTask? : Option (Task (Except Error AvailableImportsCache))
  pendingRequests    : PendingRequestMap
  /-- A map of RPC session IDs. We allow asynchronous elab tasks and request handlers
  to modify sessions. A single `Ref` ensures atomic transactions. -/
  rpcSessions        : RBMap UInt64 (IO.Ref RpcSession) compare
goal: Task Lean.SearchPath

full_name: Lean.Server.FileWorker.WorkerState.reporterCancelTk
code: structure WorkerState where
  doc                : EditableDocument
  /-- Token flagged for aborting `doc.reporter` when a new document version comes in. -/
  reporterCancelTk   : CancelToken
  srcSearchPathTask  : Task SearchPath
  importCachingTask? : Option (Task (Except Error AvailableImportsCache))
  pendingRequests    : PendingRequestMap
  /-- A map of RPC session IDs. We allow asynchronous elab tasks and request handlers
  to modify sessions. A single `Ref` ensures atomic transactions. -/
  rpcSessions        : RBMap UInt64 (IO.Ref RpcSession) compare
goal: IO.CancelToken

full_name: Lean.Server.FileWorker.WorkerState
code: structure WorkerState where
  doc                : EditableDocument
  /-- Token flagged for aborting `doc.reporter` when a new document version comes in. -/
  reporterCancelTk   : CancelToken
  srcSearchPathTask  : Task SearchPath
  importCachingTask? : Option (Task (Except Error AvailableImportsCache))
  pendingRequests    : PendingRequestMap
  /-- A map of RPC session IDs. We allow asynchronous elab tasks and request handlers
  to modify sessions. A single `Ref` ensures atomic transactions. -/
  rpcSessions        : RBMap UInt64 (IO.Ref RpcSession) compare
goal: Type

full_name: Lean.Server.FileWorker.WorkerState.rpcSessions
code: structure WorkerState where
  doc                : EditableDocument
  /-- Token flagged for aborting `doc.reporter` when a new document version comes in. -/
  reporterCancelTk   : CancelToken
  srcSearchPathTask  : Task SearchPath
  importCachingTask? : Option (Task (Except Error AvailableImportsCache))
  pendingRequests    : PendingRequestMap
  /-- A map of RPC session IDs. We allow asynchronous elab tasks and request handlers
  to modify sessions. A single `Ref` ensures atomic transactions. -/
  rpcSessions        : RBMap UInt64 (IO.Ref RpcSession) compare
goal: Lean.RBMap UInt64 (IO.Ref Lean.Server.FileWorker.RpcSession) compare

full_name: Lean.Server.FileWorker.WorkerState.pendingRequests
code: structure WorkerState where
  doc                : EditableDocument
  /-- Token flagged for aborting `doc.reporter` when a new document version comes in. -/
  reporterCancelTk   : CancelToken
  srcSearchPathTask  : Task SearchPath
  importCachingTask? : Option (Task (Except Error AvailableImportsCache))
  pendingRequests    : PendingRequestMap
  /-- A map of RPC session IDs. We allow asynchronous elab tasks and request handlers
  to modify sessions. A single `Ref` ensures atomic transactions. -/
  rpcSessions        : RBMap UInt64 (IO.Ref RpcSession) compare
goal: Lean.Server.FileWorker.PendingRequestMap

full_name: Lean.Server.FileWorker.WorkerState.doc
code: structure WorkerState where
  doc                : EditableDocument
  /-- Token flagged for aborting `doc.reporter` when a new document version comes in. -/
  reporterCancelTk   : CancelToken
  srcSearchPathTask  : Task SearchPath
  importCachingTask? : Option (Task (Except Error AvailableImportsCache))
  pendingRequests    : PendingRequestMap
  /-- A map of RPC session IDs. We allow asynchronous elab tasks and request handlers
  to modify sessions. A single `Ref` ensures atomic transactions. -/
  rpcSessions        : RBMap UInt64 (IO.Ref RpcSession) compare
goal: Lean.Server.FileWorker.EditableDocument

full_name: Lean.Server.FileWorker.WorkerM
code: abbrev WorkerM 
goal: Type

full_name: Lean.Server.FileWorker.initFn._@..lake.packages.lean4.src.lean.Lean.Server.FileWorker._hyg.1792
code: /-- Makes sure we load imports at most once per process as they cannot be unloaded. -/
private builtin_initialize importsLoadedRef : IO.Ref Bool ← IO.mkRef false
goal: IO (IO.Ref Bool)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Server.FileWorker.0.Lean.Server.FileWorker.importsLoadedRef
code: /-- Makes sure we load imports at most once per process as they cannot be unloaded. -/
private builtin_initialize importsLoadedRef : IO.Ref Bool ← IO.mkRef false
goal: IO.Ref Bool

full_name: Lean.Server.FileWorker.setupImports
code: /--
Callback from Lean language processor after parsing imports that requests necessary information from
Lake for processing imports.
-/
def setupImports (meta : DocumentMeta) (cmdlineOpts : Options) (chanOut : Channel JsonRpc.Message)
    (srcSearchPathPromise : Promise SearchPath) (stx : Syntax) :
    Language.ProcessingT IO (Except Language.Lean.HeaderProcessedSnapshot SetupImportsResult) 
goal: Lean.Language.ProcessingT IO (Except Lean.Language.Lean.HeaderProcessedSnapshot Lean.Language.Lean.SetupImportsResult)

full_name: Lean.Server.FileWorker.initializeWorker.getImportClosure?
code: def initializeWorker (meta : DocumentMeta) (o e : FS.Stream) (initParams : InitializeParams) (opts : Options)
      : IO (WorkerContext × WorkerState) 
goal: Array Lean.Name

full_name: Lean.Server.FileWorker.initializeWorker.mkLspOutputChannel
code: def initializeWorker (meta : DocumentMeta) (o e : FS.Stream) (initParams : InitializeParams) (opts : Options)
      : IO (WorkerContext × WorkerState) 
goal: IO (IO.Channel Lean.JsonRpc.Message)

full_name: Lean.Server.FileWorker.initializeWorker
code: def initializeWorker (meta : DocumentMeta) (o e : FS.Stream) (initParams : InitializeParams) (opts : Options)
      : IO (WorkerContext × WorkerState) 
goal: IO (Lean.Server.FileWorker.WorkerContext × Lean.Server.FileWorker.WorkerState)

full_name: Lean.Server.FileWorker.sendServerRequest
code: def sendServerRequest [ToJson α]
      (ctx    : WorkerContext)
      (method : String)
      (param  : α)
      : IO Unit 
goal: IO Unit

full_name: Lean.Server.FileWorker.updatePendingRequests
code: def updatePendingRequests (map : PendingRequestMap → PendingRequestMap) : WorkerM Unit 
goal: Lean.Server.FileWorker.WorkerM Unit

full_name: Lean.Server.FileWorker.updateDocument
code: /-- Given the new document, updates editable doc state. -/
  def updateDocument (meta : DocumentMeta) : WorkerM Unit 
goal: Lean.Server.FileWorker.WorkerM Unit

full_name: Lean.Server.FileWorker.handleDidChange
code: def handleDidChange (p : DidChangeTextDocumentParams) : WorkerM Unit 
goal: Lean.Server.FileWorker.WorkerM Unit

full_name: Lean.Server.FileWorker.handleCancelRequest
code: def handleCancelRequest (p : CancelParams) : WorkerM Unit 
goal: Lean.Server.FileWorker.WorkerM Unit

full_name: Lean.Server.FileWorker.handleStaleDependency
code: /--
  Received from the watchdog when a dependency of this file is detected as being stale.
  Issues a sticky diagnostic to the client that it should run "Restart File".
  -/
  def handleStaleDependency (_ : LeanStaleDependencyParams) : WorkerM Unit 
goal: Lean.Lsp.LeanStaleDependencyParams → Lean.Server.FileWorker.WorkerM Unit

full_name: Lean.Server.FileWorker.handleRpcRelease
code: def handleRpcRelease (p : Lsp.RpcReleaseParams) : WorkerM Unit 
goal: Lean.Server.FileWorker.WorkerM Unit

full_name: Lean.Server.FileWorker.handleRpcKeepAlive
code: def handleRpcKeepAlive (p : Lsp.RpcKeepAliveParams) : WorkerM Unit 
goal: Lean.Server.FileWorker.WorkerM Unit

full_name: Lean.Server.FileWorker.handleRpcConnect
code: def handleRpcConnect (_ : RpcConnectParams) : WorkerM RpcConnected 
goal: Lean.Lsp.RpcConnectParams → Lean.Server.FileWorker.WorkerM Lean.Lsp.RpcConnected

full_name: Lean.Server.FileWorker.parseParams
code: def parseParams (paramType : Type) [FromJson paramType] (params : Json) : WorkerM paramType 
goal: Lean.Server.FileWorker.WorkerM paramType

full_name: Lean.Server.FileWorker.handleNotification
code: def handleNotification (method : String) (params : Json) : WorkerM Unit 
goal: Lean.Server.FileWorker.WorkerM Unit

full_name: Lean.Server.FileWorker.queueRequest
code: def queueRequest (id : RequestID) (requestTask : Task (Except IO.Error Unit))
      : WorkerM Unit 
goal: Lean.Server.FileWorker.WorkerM Unit

full_name: Lean.Server.FileWorker.handleGetInteractiveDiagnosticsRequest
code: def handleGetInteractiveDiagnosticsRequest (params : GetInteractiveDiagnosticsParams) :
      WorkerM (Array InteractiveDiagnostic) 
goal: Lean.Server.FileWorker.WorkerM (Array Lean.Widget.InteractiveDiagnostic)

full_name: Lean.Server.FileWorker.handleImportCompletionRequest
code: def handleImportCompletionRequest (id : RequestID) (params : CompletionParams)
      : WorkerM (Task (Except Error AvailableImportsCache)) 
goal: Lean.Server.FileWorker.WorkerM (Task (Except IO.Error Lean.Server.FileWorker.AvailableImportsCache))

full_name: Lean.Server.FileWorker.handleRequest
code: def handleRequest (id : RequestID) (method : String) (params : Json)
      : WorkerM Unit 
goal: Lean.Server.FileWorker.WorkerM Unit

full_name: Lean.Server.FileWorker.handleResponse
code: def handleResponse (_ : RequestID) (_ : Json) : WorkerM Unit 
goal: Lean.JsonRpc.RequestID → Lean.Json → Lean.Server.FileWorker.WorkerM Unit

full_name: Lean.Server.FileWorker.mainLoop
code: partial def mainLoop : WorkerM Unit 
goal: Lean.Server.FileWorker.WorkerM Unit

full_name: Lean.Server.FileWorker.runRefreshTask
code: def runRefreshTask : WorkerM (Task (Except IO.Error Unit)) 
goal: Lean.Server.FileWorker.WorkerM (Task (Except IO.Error Unit))

full_name: Lean.Server.FileWorker.initAndRunWorker.writeError
code: def initAndRunWorker (i o e : FS.Stream) (opts : Options) : IO UInt32 
goal: IO Unit

full_name: Lean.Server.FileWorker.initAndRunWorker
code: def initAndRunWorker (i o e : FS.Stream) (opts : Options) : IO UInt32 
goal: IO UInt32

full_name: Lean.Server.FileWorker.workerMain
code: @[export lean_server_worker_main]
def workerMain (opts : Options) : IO UInt32 
goal: IO UInt32