Composer.LSP.Workspace (composer v0.2.0)

Copy Markdown View Source

The language server's state, as a struct and pure transitions; Composer.LSP.Session holds it in a process.

  • cookbooks - the code cookbooks, discovered without local
  • local_dir - the local config directory
  • root, project - the host project's directory and app name
  • encoding - the negotiated position encoding
  • entries - the code cookbooks' completion entries (as in the completion index, Composer.Index)
  • buffers - open documents, %{path => %{uri, text}}
  • uris - the client's URI of each path it opened, to publish with
  • generation - per path, bumped by each save; a lint result for an older generation is dropped
  • published - the paths whose last published diagnostics were not empty
  • dependents - per saved path, the files last linted with it
  • queue, running - lints run one at a time; a queued path is queued once

Summary

Types

What to publish: the URI, path and diagnostics of each file.

t()

Functions

Replaces an open document's text (full sync).

Forgets a closed document's text. Its URI is kept for publishing.

Sets the negotiated position encoding.

Queues a lint of path, overtaking any earlier lint of it.

Records the result of the lint of path at generation, returning what to publish, or :stale when a newer save has overtaken it.

A workspace from cookbooks, local_dir, root, project and entries.

Takes the next lint to run, unless one is running: {:ok, {path, generation, args}, ws}, where args is what Composer.LSP.Diagnostics.run/2 takes; or {:none, ws}.

Records an opened document.

Swaps in reloaded cookbooks and their completion entries.

What a request needs, read without waiting on lints: the cookbooks, local dir, host, encoding, completion entries and open buffers.

The client's URI for path, or one built from the path.

Types

publish()

@type publish() :: [{String.t(), Path.t(), [Composer.Lint.Diagnostic.t()]}]

What to publish: the URI, path and diagnostics of each file.

t()

@type t() :: %Composer.LSP.Workspace{
  buffers: term(),
  cookbooks: term(),
  dependents: term(),
  encoding: term(),
  entries: term(),
  generation: term(),
  local_dir: term(),
  project: term(),
  published: term(),
  queue: term(),
  root: term(),
  running: term(),
  uris: term()
}

Functions

change(ws, uri, text)

@spec change(t(), String.t(), String.t()) :: t()

Replaces an open document's text (full sync).

close(ws, uri)

@spec close(t(), String.t()) :: t()

Forgets a closed document's text. Its URI is kept for publishing.

encoding(ws, encoding)

@spec encoding(t(), Composer.LSP.Position.encoding()) :: t()

Sets the negotiated position encoding.

enqueue_lint(ws, path)

@spec enqueue_lint(t(), Path.t()) :: t()

Queues a lint of path, overtaking any earlier lint of it.

finish_lint(ws, path, generation, result)

@spec finish_lint(t(), Path.t(), integer(), term()) :: {publish() | :stale, t()}

Records the result of the lint of path at generation, returning what to publish, or :stale when a newer save has overtaken it.

Every file with diagnostics is published, and so is the saved file and each file whose last published diagnostics were not empty: an empty list clears them.

new(opts)

@spec new(keyword()) :: t()

A workspace from cookbooks, local_dir, root, project and entries.

next_lint(ws)

@spec next_lint(t()) :: {:ok, {Path.t(), integer(), map()}, t()} | {:none, t()}

Takes the next lint to run, unless one is running: {:ok, {path, generation, args}, ws}, where args is what Composer.LSP.Diagnostics.run/2 takes; or {:none, ws}.

open(ws, uri, text)

@spec open(t(), String.t(), String.t()) :: t()

Records an opened document.

reloaded(ws, cookbooks, entries)

@spec reloaded(t(), list(), list()) :: t()

Swaps in reloaded cookbooks and their completion entries.

snapshot(ws)

@spec snapshot(t()) :: map()

What a request needs, read without waiting on lints: the cookbooks, local dir, host, encoding, completion entries and open buffers.

uri(ws, path)

@spec uri(t(), Path.t()) :: String.t()

The client's URI for path, or one built from the path.