text

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package text implements text editing helper routines for LSP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CutPrefix

func CutPrefix(s, prefix string) (after string, found bool)

CutPrefix returns s without the provided leading prefix string and reports whether it found the prefix. If s doesn't start with prefix, CutPrefix returns s, false. If prefix is the empty string, CutPrefix returns s, true.

TODO(fhs): remove and use strings.CutPrefix in Go >= 1.20

func DocumentURI

func DocumentURI(f AddressableFile) (uri protocol.DocumentURI, filename string, err error)

DocumentURI returns the URI and filename of a file being edited.

func Edit

func Edit(f File, edits []protocol.TextEdit) error

Edit applied edits to file f.

func Position

func Position(f AddressableFile) (pos *protocol.TextDocumentPositionParams, filename string, err error)

Position returns the current position within a file being edited.

func ToPath

func ToPath(uri protocol.DocumentURI) string

ToPath converts URI to filename.

func ToURI

func ToURI(filename string) protocol.DocumentURI

ToURI converts filename to URI.

Types

type AddressableFile

type AddressableFile interface {
	File

	// Filename returns the filesystem path to the file.
	Filename() (string, error)

	// CurrentAddr returns the address of current selection.
	CurrentAddr() (q0, q1 int, err error)
}

AddressableFile represents an open file in text editor which has a current adddress.

type EditList

type EditList []protocol.TextEdit

func (EditList) Len

func (l EditList) Len() int

func (EditList) Less

func (l EditList) Less(i, j int) bool

func (EditList) Swap

func (l EditList) Swap(i, j int)

type File

type File interface {
	// Reader returns a reader for the entire file text buffer ("body" in acme).
	Reader() (io.Reader, error)

	// WriteAt replaces the text in rune range [q0, q1) with bytes b.
	WriteAt(q0, q1 int, b []byte) (int, error)

	// Mark marks the file for later undo.
	Mark() error

	// DisableMark turns off automatic marking (e.g. generated by WriteAt).
	DisableMark() error
}

File represents an open file in text editor.

Jump to

Keyboard shortcuts

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