Composer.LSP.Lookup (composer v0.2.0)

Copy Markdown View Source

Resolves what is under the cursor (Composer.LSP.Cursor) as a run would: the recipe's aliases are expanded, and the cookbook owning the buffer's file is the context unqualified references are looked up in first. Shared by hover and goto-definition.

Results:

  • {:step, meta} - a step reference
  • {:recipe, recipe} - a {:use, ...} target, or the recipe whose name key is under the cursor, as a loaded %Composer.Recipe{}
  • {:hex, package, :explicit | :fallthrough} - a hex: reference, or an unqualified name no cookbook has as a step

  • {:alias, name, target} - a cookbook alias name
  • {:error, reason} - a reference that does not resolve
  • nil - nothing to resolve (a recipe key)

Summary

Functions

The cookbooks a lookup resolves against: the snapshot's code cookbooks and local, built from its directory (which may not exist).

Replaces an aliased cookbook part of written with the cookbook it names in aliases (%{"lab" => "composer_lab"}).

Resolves cursor, a hit in the buffer of the file at path, against the cookbooks of snapshot (Composer.LSP.Workspace.snapshot/1).

Types

result()

@type result() ::
  {:step, Composer.Step.Meta.t()}
  | {:recipe, Composer.Recipe.t()}
  | {:hex, String.t(), :explicit | :fallthrough}
  | {:alias, String.t(), String.t() | nil}
  | {:error, term()}
  | nil

Functions

cookbooks(map)

@spec cookbooks(map()) :: [Composer.Cookbook.t()]

The cookbooks a lookup resolves against: the snapshot's code cookbooks and local, built from its directory (which may not exist).

expand(written, aliases)

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

Replaces an aliased cookbook part of written with the cookbook it names in aliases (%{"lab" => "composer_lab"}).

resolve(cursor, path, snapshot)

@spec resolve(Composer.LSP.Cursor.t() | nil, Path.t(), map()) :: result()

Resolves cursor, a hit in the buffer of the file at path, against the cookbooks of snapshot (Composer.LSP.Workspace.snapshot/1).