code

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context(content string, startLine, endLine int, window int) (string, string)

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.

func HashText

func HashText(value string) string

func MaxInt

func MaxInt(a, b int) int

func MinInt

func MinInt(a, b int) int

func Offsets

func Offsets(content string, startLine, startCol, endLine, endCol int) (int, int, error)

func RangeFromOffsets

func RangeFromOffsets(content string, start, end int) (int, int, int, int)

func Slice

func Slice(content string, startLine, startCol, endLine, endCol int) (string, error)

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

func (*PositionIndex) LineCol

func (p *PositionIndex) LineCol(offset int) (int, int)

LineCol returns the 1-based line and 1-based rune column for a byte offset. Offsets outside the content are clamped to its bounds.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL