Composer.LSP.Convert (composer v0.2.0)

Copy Markdown View Source

Maps Composer data to the Language Server Protocol's shapes, as plain maps with atom keys named like GenLSP's structure fields (related_information, new_text, ...). Composer.LSP.Server turns them into GenLSP structures; nothing here depends on GenLSP.

Positions are converted with Composer.LSP.Position, which needs each line's text. A line_fun gives it: line_fun.(path, line) returns line line (1-based) of the file at path, or nil. lines_for/1 builds one from the files on disk.

Summary

Functions

The LSP diagnostic of d, a diagnostic in file d.file. One with no position is placed at the start of the file. Its data carries the code and the suggestions, for code actions.

Line line (1-based) of a tuple of lines, or nil.

A line_fun over the files at paths, each read once. A file that cannot be read has no lines.

The file: URI of an absolute path.

The LSP range of a Composer range (nil is the start of the file). line_of.(line) gives a line's text.

The LSP severity of a diagnostic severity.

The path of a file: URI, percent-decoded; nil for any other scheme.

Types

line_fun()

@type line_fun() :: (Path.t(), pos_integer() -> String.t() | nil)

lsp_position()

@type lsp_position() :: %{line: non_neg_integer(), character: non_neg_integer()}

lsp_range()

@type lsp_range() :: %{start: lsp_position(), end: lsp_position()}

Functions

diagnostic(d, encoding, line_fun)

The LSP diagnostic of d, a diagnostic in file d.file. One with no position is placed at the start of the file. Its data carries the code and the suggestions, for code actions.

line_text(lines, line)

@spec line_text(tuple(), integer()) :: String.t() | nil

Line line (1-based) of a tuple of lines, or nil.

lines_for(paths)

@spec lines_for([Path.t()]) :: line_fun()

A line_fun over the files at paths, each read once. A file that cannot be read has no lines.

path_to_uri(path)

@spec path_to_uri(Path.t()) :: String.t()

The file: URI of an absolute path.

range(arg1, encoding, line_of)

The LSP range of a Composer range (nil is the start of the file). line_of.(line) gives a line's text.

severity(atom)

@spec severity(:error | :warning) :: 1 | 2

The LSP severity of a diagnostic severity.

uri_to_path(arg1)

@spec uri_to_path(String.t()) :: Path.t() | nil

The path of a file: URI, percent-decoded; nil for any other scheme.