Composer.LSP.Cursor (composer v0.2.0)

Copy Markdown View Source

What is under the cursor in a recipe group buffer.

When the buffer parses, Composer.Recipe.Locator answers. Otherwise a line scan finds the string literal enclosing the cursor: a {:use, ...} target when {:use, precedes it, a reference otherwise. The scan knows string literals, the {:use, prefix and keys (steps:) and nothing else; references are parsed by Composer.Ref.

Lines and columns are 1-based, columns in graphemes, as the locator's.

Summary

Functions

What is at line, column of text, or nil.

The completion context at line, column of text, by line scan: {:steps | :use, prefix, replace_range} inside a string literal of a steps: list (:use after {:use,), else nil. replace_range covers the literal's contents.

The string literal on line_text enclosing column: its value, the column of its opening quote and the column after its closing quote (nil when the line ends inside it). The cursor is inside from the opening quote up to the closing one.

Every string literal on line_text, in order (see literal_at/2).

The cookbook aliases written in text, read by scanning aliases: lists and the top-level bindings aliases: names, the nearest one starting on or above line first. Best effort, for a buffer that does not parse.

Types

literal()

@type literal() :: %{
  value: String.t(),
  start: pos_integer(),
  end: pos_integer() | nil
}

range()

@type range() :: Composer.Lint.Diagnostic.range()

t()

@type t() :: %{
  kind: :ref | :use | :alias | :key | :recipe,
  recipe: String.t() | nil,
  value: term(),
  range: range(),
  aliases: %{required(String.t()) => String.t()}
}

Functions

at(text, path, line, column)

@spec at(String.t(), Path.t(), pos_integer(), pos_integer()) :: t() | nil

What is at line, column of text, or nil.

context(text, line, column)

@spec context(String.t(), pos_integer(), pos_integer()) ::
  {:steps | :use, String.t(), range()} | nil

The completion context at line, column of text, by line scan: {:steps | :use, prefix, replace_range} inside a string literal of a steps: list (:use after {:use,), else nil. replace_range covers the literal's contents.

literal_at(line_text, column)

@spec literal_at(String.t(), pos_integer()) :: literal() | nil

The string literal on line_text enclosing column: its value, the column of its opening quote and the column after its closing quote (nil when the line ends inside it). The cursor is inside from the opening quote up to the closing one.

literals(line_text)

@spec literals(String.t()) :: [literal()]

Every string literal on line_text, in order (see literal_at/2).

scan_aliases(text, line)

@spec scan_aliases(String.t(), pos_integer()) :: %{required(String.t()) => String.t()}

The cookbook aliases written in text, read by scanning aliases: lists and the top-level bindings aliases: names, the nearest one starting on or above line first. Best effort, for a buffer that does not parse.