Documentation
¶
Overview ¶
Package code converts between byte offsets and the line/column coordinates AnchorDB stores in bindings.
Lines are 1-based. Columns are 1-based *rune* offsets within their line, not byte offsets. Producers that natively work in bytes -- tree-sitter, for one -- must convert through PositionIndex before writing a span, otherwise any line containing non-ASCII text yields a column that Slice cannot resolve.
Index ¶
- func Context(content string, startLine, endLine int, window int) (string, string)
- func HashText(value string) string
- func MaxInt(a, b int) int
- func MinInt(a, b int) int
- func Offsets(content string, startLine, startCol, endLine, endCol int) (int, int, error)
- func RangeFromOffsets(content string, start, end int) (int, int, int, int)
- func Slice(content string, startLine, startCol, endLine, endCol int) (string, error)
- type PositionIndex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Context ¶
Context returns the `window` lines immediately before startLine and immediately after endLine. Line numbers outside the content are clamped, so a stale binding pointing past the end of a shrunken file yields empty context instead of panicking.
Types ¶
type PositionIndex ¶
type PositionIndex struct {
// contains filtered or unexported fields
}
PositionIndex converts byte offsets in a fixed piece of content into the line/rune-column coordinates described in the package docs. Building it once per file keeps conversion cheap when a file yields many symbols.
func NewPositionIndex ¶
func NewPositionIndex(content string) *PositionIndex