Documentation
¶
Overview ¶
Package goxmap provides source positions and bidirectional mappings between generated GOX artifacts and their original source files.
Offsets and columns are byte based. Protocol-specific encodings, such as the UTF-16 positions used by LSP, are converted only at the package boundary.
Index ¶
- func MarshalJSONDocument(sourceMap *Map, generated string, sources map[string]string) ([]byte, error)
- type BytePosition
- type JSONDocument
- type JSONMapping
- type JSONPosition
- type JSONRange
- type LineIndex
- func (i *LineIndex) ByteOffset(position BytePosition) (int, error)
- func (i *LineIndex) BytePosition(offset int) (BytePosition, error)
- func (i *LineIndex) LineCount() int
- func (i *LineIndex) Text() string
- func (i *LineIndex) UTF16Offset(position UTF16Position) (int, error)
- func (i *LineIndex) UTF16Position(offset int) (UTF16Position, error)
- type Map
- type Mapping
- type MappingKind
- type Position
- type Range
- type SourceRange
- type UTF16Position
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BytePosition ¶
BytePosition identifies a zero-based line and byte column.
type JSONDocument ¶
type JSONDocument struct {
Version int `json:"version"`
GeneratedURI string `json:"generatedUri"`
Sources []string `json:"sources"`
Mappings []JSONMapping `json:"mappings"`
}
type JSONMapping ¶
type JSONPosition ¶
type JSONRange ¶
type JSONRange struct {
Start JSONPosition `json:"start"`
End JSONPosition `json:"end"`
}
type LineIndex ¶
type LineIndex struct {
// contains filtered or unexported fields
}
LineIndex converts positions in one immutable source string. Newline bytes are represented by the position immediately after the line content. CRLF is treated as one newline and neither byte is part of the line content.
func NewLineIndex ¶
NewLineIndex indexes text without copying it. The string remains immutable by construction and may be shared safely by readers.
func (*LineIndex) ByteOffset ¶
func (i *LineIndex) ByteOffset(position BytePosition) (int, error)
ByteOffset converts a byte-based position to an offset.
func (*LineIndex) BytePosition ¶
func (i *LineIndex) BytePosition(offset int) (BytePosition, error)
BytePosition converts an offset to a byte-based position.
func (*LineIndex) LineCount ¶
LineCount returns the number of logical lines, including the empty final line when text ends in a newline.
func (*LineIndex) UTF16Offset ¶
func (i *LineIndex) UTF16Offset(position UTF16Position) (int, error)
UTF16Offset converts an LSP-compatible UTF-16 position to a byte offset. A position may not split a surrogate pair.
func (*LineIndex) UTF16Position ¶
func (i *LineIndex) UTF16Position(offset int) (UTF16Position, error)
UTF16Position converts an offset to an LSP-compatible UTF-16 position.
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is an immutable, bidirectional source map. Generated ranges may not overlap, which keeps forward lookups deterministic. Multiple generated ranges may refer to the same original range.
func Compose ¶
Compose combines lower (generated -> intermediate) with upper (intermediate -> original). Only lower ranges that refer to upper's generated URI participate. Exact intersections stay exact; generated scaffolding or an upstream anchor remains an anchor.
func New ¶
New validates and constructs a source map. Input mappings are copied and sorted by their generated range.
func UnmarshalJSONDocument ¶
UnmarshalJSONDocument restores the immutable offset map used by the compiler and language tooling from its persisted, readable representation.
func (*Map) GeneratedPositions ¶
GeneratedPositions maps an original byte offset to every generated location derived from it. Results follow generated-document order.
func (*Map) GeneratedURI ¶
GeneratedURI returns the identity of the generated document.
func (*Map) OriginalPosition ¶
OriginalPosition maps a generated byte offset back to its GOX source.
func (*Map) OriginalRange ¶
func (m *Map) OriginalRange(generated Range) (SourceRange, MappingKind, bool)
OriginalRange maps a non-empty generated range when it is fully contained in one mapping segment. Ranges crossing generated and source boundaries are intentionally rejected instead of being reported with false precision.
type Mapping ¶
type Mapping struct {
Generated Range
Original SourceRange
Kind MappingKind
}
Mapping relates one range in a generated document to an original source.
type MappingKind ¶
type MappingKind uint8
MappingKind describes how precisely generated bytes correspond to source.
const ( // Exact maps byte-for-byte preserved text. Generated and original ranges // must have the same length. Exact MappingKind = iota // Anchor associates generated scaffolding with an original range. Positions // inside it resolve to the start of the original range and are not exact. Anchor )
type Range ¶
Range is a zero-based, half-open byte range [Start, End).
type SourceRange ¶
SourceRange identifies a range in one source document.
type UTF16Position ¶
UTF16Position identifies a zero-based line and UTF-16 code-unit column, as required by the Language Server Protocol.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer builds transformed text and the map from that text to one immediate input document. It deliberately distinguishes copied bytes from generated scaffolding so callers cannot accidentally mark generated code as exact.
func (*Writer) WriteGenerated ¶
WriteGenerated writes compiler-generated text anchored to a source range. Empty generated text is ignored; the anchor itself may be a point range.
func (*Writer) WriteSource ¶
WriteSource copies an exact source range into the generated document.