complete

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: BSD-3-Clause Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSeedMatching

func IsSeedMatching(lseed string, completion string) bool

IsSeedMatching returns whether the given lowercase seed matches the given completion string. It checks whether different transformations of the completion contain the lowercase version of the seed.

func MatchPrecedence

func MatchPrecedence(lseed string, completion string) int

MatchPrecedence returns the sorting precedence of the given completion relative to the given lowercase seed. The completion is assumed to already match the seed by IsSeedMatching. A lower return value indicates a higher precedence.

func MatchSeedString

func MatchSeedString(completions []string, seed string) []string

MatchSeedString returns a list of matches given a list of string possibilities and a seed. It checks whether different transformations of each possible completion contain a lowercase version of the seed. It returns nil if there are no matches.

func SeedAfter added in v0.1.4

func SeedAfter(text string, f func(r rune) bool) string

SeedPath returns the text after the last rune for which the given function returns true, which is typically used for creating a completion seed string.

func SeedPath added in v0.1.4

func SeedPath(text string) string

SeedPath returns the text after the last whitespace and path/filepath separator, which is typically used for creating a completion seed string.

func SeedSpace added in v0.1.4

func SeedSpace(text string) string

SeedSpace returns the text after the last whitespace, which is typically used for creating a completion seed string.

Types

type Completion

type Completion struct {

	// Text is the completion text: what will actually be inserted if selected.
	Text string

	// Label is the label text to show the user. It is only used if
	// non-empty; otherwise Text is used.
	Label string

	// Icon is the icon to render in core for the completion item.
	Icon icons.Icon

	// Desc is extra description information used in tooltips in core.
	Desc string
}

Completion holds one potential completion

func MatchSeedCompletion

func MatchSeedCompletion(completions []Completion, seed string) []Completion

MatchSeedCompletion returns a list of matches given a list of Completion possibilities and a seed. It checks whether different transformations of each possible completion contain a lowercase version of the seed. It returns nil if there are no matches.

type Completions

type Completions []Completion

Completions is a full list (slice) of completion options

type Edit

type Edit struct {

	// completion text after special edits
	NewText string

	// number of runes, past the cursor, to delete, if any
	ForwardDelete int

	// cursor adjustment if cursor should be placed in a location other than at end of newText
	CursorAdjust int
}

Edit is returned from completion edit function to incorporate the selected completion

func EditWord

func EditWord(text string, cursorPos int, completion string, seed string) (ed Edit)

EditWord replaces the completion seed and any text up to the next whitespace with completion

type EditFunc

type EditFunc func(data any, text string, cursorPos int, comp Completion, seed string) Edit

EditFunc is passed the current text and the selected completion for text editing. Allows for other editing, e.g. adding "()" or adding "/", etc.

type Lookup

type Lookup struct {

	// if non-empty, the result is to view this file (full path)
	Filename string

	// starting line number within file to display
	StLine int

	// ending line number within file
	EdLine int

	// if filename is empty, this is raw text to display for lookup result
	Text []byte
}

Lookup is used for returning lookup results

func (*Lookup) SetFile

func (lk *Lookup) SetFile(fname string, st, ed int)

SetFile sets file info

type LookupFunc

type LookupFunc func(data any, text string, posLine, posChar int) Lookup

LookupFunc is the function called to get the lookup results for given input test and position.

type MatchFunc

type MatchFunc func(data any, text string, posLine, posChar int) Matches

MatchFunc is the function called to get the list of possible completions and also determines the correct seed based on the text passed as a parameter of CompletionFunc

type Matches

type Matches struct {

	// the matches based on seed
	Matches Completions

	// seed is the prefix we use to find possible completions
	Seed string
}

Matches is used for passing completions around. contains seed in addition to completions

Jump to

Keyboard shortcuts

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