span

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2019 License: Apache-2.0, NCSA Imports: 8 Imported by: 3

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 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) *Patcher

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

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(span *cpb.Span) (newStart, newEnd int32, exists bool)

PatchSpan returns the given Span's byte offsets mapped from the Patcher's oldText to its newText using Patcher.Patch.

Jump to

Keyboard shortcuts

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