# `Minga.LSP.PositionEncoding`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga/lsp/position_encoding.ex#L1)

Converts between Minga's byte-indexed positions and LSP positions.

LSP historically uses UTF-16 code unit offsets for character positions, a legacy of the JavaScript/TypeScript origins. Modern servers support UTF-8 offset encoding via capability negotiation in LSP 3.17+.

The conversion implementation lives in `Minga.Core.PositionEncoding` so pure diagnostics and other Layer 0 modules can use the same rules without depending on LSP services.

# `encoding`

```elixir
@type encoding() :: Minga.Core.PositionEncoding.encoding()
```

The negotiated offset encoding for a server session.

# `client_supported_encodings`

```elixir
@spec client_supported_encodings() :: [String.t()]
```

Returns the LSP encoding strings for capability advertisement.

# `from_lsp`

```elixir
@spec from_lsp(map(), String.t(), encoding()) ::
  {non_neg_integer(), non_neg_integer()}
```

Converts an LSP position map back to a Minga `{line, byte_col}` tuple.

# `negotiate`

```elixir
@spec negotiate([String.t()]) :: encoding()
```

Negotiates the best offset encoding from the server's supported list.

Prefers UTF-8, then UTF-16, then UTF-32. Falls back to UTF-16 if the server does not advertise support.

# `to_lsp`

```elixir
@spec to_lsp({non_neg_integer(), non_neg_integer()}, String.t(), encoding()) :: map()
```

Converts a Minga `{line, byte_col}` position to an LSP position map.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
