MingaEditor.State.LSP (Minga v0.1.0)

Copy Markdown View Source

LSP coordination state for the Editor.

Groups the Editor's LSP-related fields into a focused sub-struct: server status tracking, cached responses (code lenses, inlay hints, selection ranges), and debounce timers for highlight and inlay hint requests.

All mutations go through functions on this module. Other modules read fields directly but never do %{lsp | field: value}.

Summary

Functions

Appends a single resolved code lens entry.

Returns a pure instruction for canceling the highlight debounce timer.

Returns a pure instruction for canceling the inlay hint debounce timer.

Clears the highlight debounce timer reference without cancelling it.

Clears the inlay hint debounce timer reference without cancelling it.

Clears the stored selection ranges and resets the index.

Drops pending requests owned by the active completion lifecycle.

Drops a formatting operation by request reference.

Moves the selection range index forward (expand) by one step.

Fetches a formatting operation by request reference.

Fetches an Editor-global LSP pending request by response reference.

Returns whether a formatting operation is active.

Returns the formatting operation for one Buffer.

Returns the newest active formatting operation.

Records the viewport top used by the latest inlay-hint request.

Replaces the stored code lenses.

Sets the highlight debounce timer reference.

Sets the inlay hint debounce timer and records the viewport top.

Replaces the stored inlay hints.

Stores a selection range chain and resets the index to 0.

Moves the selection range index backward (shrink) by one step.

Takes all structured operation requests originating from one departing tab.

Takes an Editor-global LSP request by response reference.

Tracks an Editor-global formatting operation.

Tracks an Editor-global LSP request for a structured operation.

Updates a single server's status and re-derives the aggregate status.

Types

current_origin_response_kind()

@type current_origin_response_kind() ::
  :definition
  | :peek_definition
  | :hover
  | :document_highlight
  | :code_action
  | :prepare_rename
  | :type_definition
  | :implementation
  | :document_symbol
  | :workspace_symbol
  | :selection_range
  | :prepare_call_hierarchy
  | :prepare_outgoing_hierarchy
  | :incoming_calls
  | :outgoing_calls
  | :code_lens
  | :code_lens_resolve

operation_request()

@type operation_request() ::
  {:operation, :references | :rename, MingaEditor.State.Operation.id(),
   MingaEditor.State.Tab.id() | nil}

pending_request()

@type pending_request() :: MingaEditor.State.LSP.PendingRequests.request()

semantic_layer()

@type semantic_layer() ::
  {buffer_version :: non_neg_integer(), capture_names :: tuple(),
   spans :: tuple()}

server_status()

@type server_status() :: :starting | :initializing | :ready | :crashed

t()

@type t() :: %MingaEditor.State.LSP{
  code_lenses: [map()],
  highlight_debounce_timer: reference() | nil,
  inlay_hint_debounce_timer: reference() | nil,
  inlay_hints: [map()],
  last_inlay_viewport_top: non_neg_integer() | nil,
  pending_requests: MingaEditor.State.LSP.PendingRequests.t(),
  selection_range_index: non_neg_integer(),
  selection_ranges: [map()] | nil,
  semantic_tokens: %{required(pid()) => semantic_layer()},
  server_statuses: %{required(atom()) => server_status()},
  status: MingaEditor.Shell.Traditional.Modeline.lsp_status()
}

Functions

accept_semantic_tokens(lsp, buffer, version, names, spans)

@spec accept_semantic_tokens(t(), pid(), non_neg_integer(), [String.t()], [
  Minga.Language.Highlight.Span.t()
]) :: t()

append_code_lens(lsp, entry)

@spec append_code_lens(t(), map()) :: t()

Appends a single resolved code lens entry.

cancel_highlight_timer(lsp)

@spec cancel_highlight_timer(t()) :: {:cancel_timer, t(), reference() | nil}

Returns a pure instruction for canceling the highlight debounce timer.

cancel_inlay_hint_timer(lsp)

@spec cancel_inlay_hint_timer(t()) :: {:cancel_timer, t(), reference() | nil}

Returns a pure instruction for canceling the inlay hint debounce timer.

clear_highlight_timer(lsp)

@spec clear_highlight_timer(t()) :: t()

Clears the highlight debounce timer reference without cancelling it.

clear_inlay_hint_timer(lsp)

@spec clear_inlay_hint_timer(t()) :: t()

Clears the inlay hint debounce timer reference without cancelling it.

clear_selection_ranges(lsp)

@spec clear_selection_ranges(t()) :: t()

Clears the stored selection ranges and resets the index.

clear_semantic_tokens(lsp, buffer)

@spec clear_semantic_tokens(t(), pid()) :: t()

drop_completion_requests(lsp)

@spec drop_completion_requests(t()) :: t()

Drops pending requests owned by the active completion lifecycle.

drop_format(lsp, ref)

@spec drop_format(t(), reference()) :: t()

Drops a formatting operation by request reference.

expand_selection(lsp)

@spec expand_selection(t()) :: t()

Moves the selection range index forward (expand) by one step.

fetch_format(lsp, ref)

@spec fetch_format(t(), reference()) ::
  {:ok, MingaEditor.State.LSP.FormatOperation.t()} | :error

Fetches a formatting operation by request reference.

fetch_pending_request(lsp, ref)

@spec fetch_pending_request(t(), reference()) :: {:ok, pending_request()} | :error

Fetches an Editor-global LSP pending request by response reference.

format_active?(lsp, ref)

@spec format_active?(t(), reference()) :: boolean()

Returns whether a formatting operation is active.

format_for_buffer(lsp, buffer)

@spec format_for_buffer(t(), pid()) :: MingaEditor.State.LSP.FormatOperation.t() | nil

Returns the formatting operation for one Buffer.

newest_format(lsp)

@spec newest_format(t()) :: MingaEditor.State.LSP.FormatOperation.t() | nil

Returns the newest active formatting operation.

remember_inlay_viewport(lsp, viewport_top)

@spec remember_inlay_viewport(t(), non_neg_integer()) :: t()

Records the viewport top used by the latest inlay-hint request.

retire_buffer(lsp, buffer)

@spec retire_buffer(t(), pid()) :: t()

set_code_lenses(lsp, lenses)

@spec set_code_lenses(t(), [map()]) :: t()

Replaces the stored code lenses.

set_highlight_timer(lsp, timer)

@spec set_highlight_timer(t(), reference()) :: t()

Sets the highlight debounce timer reference.

set_inlay_hint_timer(lsp, timer, viewport_top)

@spec set_inlay_hint_timer(t(), reference(), non_neg_integer()) :: t()

Sets the inlay hint debounce timer and records the viewport top.

set_inlay_hints(lsp, hints)

@spec set_inlay_hints(t(), [map()]) :: t()

Replaces the stored inlay hints.

set_selection_ranges(lsp, ranges)

@spec set_selection_ranges(t(), [map()]) :: t()

Stores a selection range chain and resets the index to 0.

shrink_selection(lsp)

@spec shrink_selection(t()) :: t()

Moves the selection range index backward (shrink) by one step.

take_operation_requests_for_tab(lsp, tab_id)

@spec take_operation_requests_for_tab(t(), pos_integer()) ::
  {[operation_request()], t()}

Takes all structured operation requests originating from one departing tab.

take_pending_request(lsp, ref)

@spec take_pending_request(t(), reference()) :: {:ok, pending_request(), t()} | :error

Takes an Editor-global LSP request by response reference.

track_completion_resolve_request(lsp, ref, client, buffer, version, gen, raw_item)

@spec track_completion_resolve_request(
  t(),
  reference(),
  pid(),
  pid(),
  non_neg_integer(),
  non_neg_integer(),
  map()
) :: t()

track_completion_result_request(lsp, ref, role, client, buffer, version, gen, pos)

@spec track_completion_result_request(
  t(),
  reference(),
  MingaEditor.CompletionTrigger.response_role(),
  pid(),
  pid(),
  non_neg_integer(),
  non_neg_integer(),
  {non_neg_integer(), non_neg_integer()}
) :: t()

track_format(lsp, operation)

@spec track_format(t(), MingaEditor.State.LSP.FormatOperation.t()) :: t()

Tracks an Editor-global formatting operation.

track_hover_mouse_request(lsp, ref, row, col, buffer, buffer_line, buffer_col, version)

@spec track_hover_mouse_request(
  t(),
  reference(),
  non_neg_integer(),
  non_neg_integer(),
  pid(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer()
) :: t()

Tracks an Editor-global mouse hover request.

track_inlay_hint_request(lsp, ref, client, buffer, version, tab_id, viewport_top, viewport_rows)

@spec track_inlay_hint_request(
  t(),
  reference(),
  pid(),
  pid(),
  non_neg_integer(),
  MingaEditor.State.Tab.id() | nil,
  non_neg_integer(),
  pos_integer()
) :: t()

track_operation_request(lsp, ref, kind, operation_id, tab_id)

@spec track_operation_request(
  t(),
  reference(),
  :references | :rename,
  MingaEditor.State.Operation.id(),
  MingaEditor.State.Tab.id() | nil
) :: t()

Tracks an Editor-global LSP request for a structured operation.

track_response_request(lsp, ref, kind, client, buffer, version, tab_id, cursor)

@spec track_response_request(
  t(),
  reference(),
  current_origin_response_kind(),
  pid(),
  pid(),
  non_neg_integer(),
  MingaEditor.State.Tab.id() | nil,
  {non_neg_integer(), non_neg_integer()} | nil
) :: t()

track_semantic_tokens_request(lsp, ref, client, buffer, version, encoding, legend)

@spec track_semantic_tokens_request(
  t(),
  reference(),
  pid(),
  pid(),
  non_neg_integer(),
  Minga.LSP.PositionEncoding.encoding(),
  {[String.t()], [String.t()]}
) :: t()

track_signature_help_request(lsp, ref, client, buffer, version, cursor)

@spec track_signature_help_request(
  t(),
  reference(),
  pid(),
  pid(),
  non_neg_integer(),
  {non_neg_integer(), non_neg_integer()}
) :: t()

update_server_status(lsp, name, status)

@spec update_server_status(t(), atom(), atom()) :: t()

Updates a single server's status and re-derives the aggregate status.

When status is :stopped, the server is removed from the map entirely.