Workspace.State (Workspace v0.4.2)

View Source

The low-level API and the workspace state struct.

The %Workspace.State{} structure

Every workspace is stored internally as a struct containing the following fields:

  • :projects - a map of the form %{atom => Workspace.Project.t()} where the key is the defined project name. It includes all detected workspace projects excluding any ignored ones.
  • :cwd - the directory from which the generation of the workspace struct occurred.
  • :mix_path - absolute path to the workspace's root mix.exs file.
  • :workspace_path - absolute path of the workspace, this is by default the folder containing the workspace mix file.
  • :git_root_path - the absolute path of the git repository containing the workspace
  • :git_workspace_path - the absolute path of the workspace within the git repository. It differs from the :workspace_path only if the workspace path is a symlink pointing inside the repository.
  • :config - the workspace's configuration, check Workspace.Config for more details.

Summary

Types

t()

Struct holding the workspace state.

Functions

Returns the absolute path of a file given relative to the git root.

Initializes a new workspace from the given settings.

Types

t()

@type t() :: %Workspace.State{
  config: keyword(),
  cwd: binary(),
  git_root_path: binary() | nil,
  git_workspace_path: binary() | nil,
  graph: :digraph.graph(),
  mix_path: binary(),
  projects: %{required(atom()) => Workspace.Project.t()},
  status_updated?: boolean(),
  workspace_path: binary()
}

Struct holding the workspace state.

It contains the following:

  • :projects - A map with all workspace projects.
  • :config - The workspace configuration settings.
  • :mix_path - The path to the workspace's root mix.exs.
  • :workspace_path - The workspace root path.
  • :git_root_path - The git root path, of the repository containing the workspace.
  • :git_workspace_path - The workspace path within the git repository.
  • :cwd - The directory from which the workspace was generated.
  • :graph - The DAG (directed acyclic graph) of the workspace, including the :affected_by paths of the projects as :path nodes.
  • :status_updated? - Set to true if the workspace status has been updated.

Functions

git_file_path(workspace, file)

@spec git_file_path(workspace :: t(), file :: Path.t()) :: Path.t()

Returns the absolute path of a file given relative to the git root.

The path is returned in the form of the workspace path, e.g. if the workspace path is a symlink pointing inside the repository, the returned path is under the symlinked workspace path, so that it can be compared with the projects paths.

The workspace is expected to be in a git repository.

new(path, mix_path, config, projects)

@spec new(
  path :: String.t(),
  mix_path :: String.t(),
  config :: keyword(),
  projects :: [Workspace.Project.t()]
) :: t()

Initializes a new workspace from the given settings.

It expects the following:

  • path is the root path of the workspace
  • mix_path is the root mix file, usually a mix.exs in the path
  • config is the workspace configuration
  • projects is a list of workspace projects

Notice that no validation is applied at this level.