document

package
v0.2.0-rc9 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package document encapsulates processing for HCL text documents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyChanges

func ApplyChanges(original []byte, changes Changes) ([]byte, error)

ApplyChanges applies the supplied changes to the text supplied.

func ByteOffsetForPos

func ByteOffsetForPos(lines []source.Line, pos Pos) (int, error)

ByteOffsetForPos returns the byte offset for the supplied position or an error if such a position could not be found in the supplied lines.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if the supplied error refers to a missing document.

func NotFound

func NotFound(uri string) error

NotFound returns an error that represents a missing document.

Types

type Change

type Change interface {
	Text() string  // the text to use
	Range() *Range // the range to replace
}

Change represents an edit where a specific range in a document is substituted with specific text. When no range is present, a full document change is assumed.

type Changes

type Changes []Change

Changes is a list of change commands.

type DirHandle

type DirHandle struct {
	URI string
}

DirHandle represents a directory location

This may be received via LSP from the client (as URI) or constructed from a file path on OS FS.

func DirHandleFromPath

func DirHandleFromPath(dirPath string) DirHandle

DirHandleFromPath creates a DirHandle from a given path.

dirPath is expected to be a directory path (rather than document). It is however outside the scope of the function to verify this is actually the case or whether the directory exists.

func DirHandleFromURI

func DirHandleFromURI(dirUri string) DirHandle

DirHandleFromURI creates a DirHandle from a given URI.

dirUri is expected to be a directory URI (rather than document). It is however outside the scope of the function to verify this is actually the case or whether the directory exists.

func (DirHandle) Path

func (dh DirHandle) Path() string

Path returns (the usually) absolute path for the dir handle.

type Document

type Document struct {
	Dir        DirHandle     // the directory where the doc lives.
	Filename   string        // the file name.
	ModTime    time.Time     // last modified time.
	LanguageID string        // language ID as supplied by the language client.
	Version    int           // document version used to ensure edits are in sequence.
	Text       []byte        // the text of the document as a byte slice.
	Lines      []source.Line // text separated into lines to enable byte offset computation for position conversions.
}

Document represents a text document of interest.

func (*Document) FullPath

func (d *Document) FullPath() string

FullPath returns the full filesystem path of the document.

type Handle

type Handle struct {
	Dir      DirHandle // the directory handle.
	Filename string    // the file name.
}

Handle represents a document location

This may be received via LSP from the client (as URI) or constructed from a file path on OS FS.

func HandleFromPath

func HandleFromPath(docPath string) Handle

HandleFromPath creates a Handle from a given path.

docPath is expected to be a document path (rather than dir). It is however outside the scope of the function to verify this is actually the case or whether the file exists.

func HandleFromURI

func HandleFromURI(docUri string) Handle

HandleFromURI creates a Handle from a given URI.

docURI is expected to be a document URI (rather than dir). It is however outside the scope of the function to verify this is actually the case or whether the file exists.

func (Handle) FullPath

func (h Handle) FullPath() string

FullPath returns the full filesystem path for the handle.

func (Handle) FullURI

func (h Handle) FullURI() string

FullURI returns a URI for the handle.

type Pos

type Pos struct {
	Line, Column int
}

Pos represents LSP-style position (zero-indexed).

func (Pos) String

func (p Pos) String() string

type Range

type Range struct {
	Start, End Pos
}

Range represents LSP-style range between two positions. Positions are zero-indexed unlike HCL ranges.

Directories

Path Synopsis
Package diff provides facilities to represent the differences between two document texts as a sequence of document.Change records.
Package diff provides facilities to represent the differences between two document texts as a sequence of document.Change records.
Package source provides facilities to represent text documents as a sequence of lines.
Package source provides facilities to represent text documents as a sequence of lines.
Package store implements a store for HCL documents open in the editor and tracks unsaved changes for each of them.
Package store implements a store for HCL documents open in the editor and tracks unsaved changes for each of them.

Jump to

Keyboard shortcuts

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