span

package
v0.0.67 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0, NCSA Imports: 10 Imported by: 0

Documentation

Overview

Package span implements utilities to resolve byte offsets within a file to line and column numbers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteOffsets added in v0.0.61

func ByteOffsets(s *cpb.Span) (int32, int32)

ByteOffsets returns the starting and ending byte offsets of the Span.

func InBounds

func InBounds(kind xpb.DecorationsRequest_SpanKind, start, end, startBoundary, endBoundary int32) bool

InBounds reports whether [start,end) is bounded by the specified [startBoundary,endBoundary) span.

Types

type Normalizer

type Normalizer struct {
	// contains filtered or unexported fields
}

Normalizer fixes xref.Locations within a given source text so that each point has consistent byte_offset, line_number, and column_offset fields within the range of text's length and its line lengths.

func NewNormalizer

func NewNormalizer(text []byte) *Normalizer

NewNormalizer returns a Normalizer for Locations within text.

func (*Normalizer) ByteOffset

func (n *Normalizer) ByteOffset(offset int32) *cpb.Point

ByteOffset returns a normalized point based on the given offset within the Normalizer's text. A normalized point has all of its fields set consistently and clamped within the range [0,len(text)).

func (*Normalizer) Location

func (n *Normalizer) Location(loc *xpb.Location) (*xpb.Location, error)

Location returns a normalized location within the Normalizer's text. Normalized FILE locations have no start/end points. Normalized SPAN locations have fully populated start/end points clamped in the range [0, len(text)).

func (*Normalizer) Point

func (n *Normalizer) Point(p *cpb.Point) *cpb.Point

Point returns a normalized point within the Normalizer's text. A normalized point has all of its fields set consistently and clamped within the range [0,len(text)).

func (*Normalizer) Span

func (n *Normalizer) Span(s *cpb.Span) *cpb.Span

Span returns a Span with its start and end normalized.

func (*Normalizer) SpanOffsets

func (n *Normalizer) SpanOffsets(start, end int32) *cpb.Span

SpanOffsets returns a Span based on normalized start and end byte offsets.

type Patcher

type Patcher struct {
	// contains filtered or unexported fields
}

Patcher uses a computed diff between two texts to map spans from the original text to the new text.

func NewPatcher

func NewPatcher(oldText, newText []byte) (p *Patcher, err error)

NewPatcher returns a Patcher based on the diff between oldText and newText.

func Unmarshal added in v0.0.61

func Unmarshal(rec []byte) (*Patcher, error)

Unmarshal decodes a Patcher from its packed binary format.

func (*Patcher) Marshal added in v0.0.61

func (p *Patcher) Marshal() ([]byte, error)

Marshal encodes the Patcher into a packed binary format.

func (*Patcher) Patch

func (p *Patcher) Patch(spanStart, spanEnd int32) (newStart, newEnd int32, exists bool)

Patch returns the resulting span of mapping the given span from the Patcher's constructed oldText to its newText. If the span no longer exists in newText or is invalid, the returned bool will be false. As a convenience, if p==nil, the original span will be returned.

func (*Patcher) PatchSpan

func (p *Patcher) PatchSpan(s *cpb.Span) (span *cpb.Span, exists bool)

PatchSpan returns the resulting Span of mapping the given Span from the Patcher's constructed oldText to its newText. If the span no longer exists in newText or is invalid, the returned bool will be false. As a convenience, if p==nil, the original span will be returned.

Jump to

Keyboard shortcuts

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