complete

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2019 License: BSD-3-Clause Imports: 4 Imported by: 5

Documentation

Overview

Package Complete provides functions for text completion

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtendSeed

func ExtendSeed(matches Completions, seed string) string

ExtendSeed tries to extend the current seed checking possible completions for a longer common seed e.g. if the current seed is "ab" and the completions are "abcde" and "abcdf" then Extend returns "cd" but if the possible completions are "abcde" and "abz" then Extend returns ""

func HasUpperCase

func HasUpperCase(str string) bool

HasUpperCase returns true if string has an upper-case letter

func MatchSeedString

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

MatchSeed returns a list of matches given a list of string possibilities and a seed. The seed is basically a prefix.

func SeedWhiteSpace

func SeedWhiteSpace(text string) string

SeedWhiteSpace returns the text after the last whitespace

Types

type Completion

type Completion struct {
	Text  string            `desc:"completion text -- what will actually be inserted if selected"`
	Label string            `desc:"label to show the user -- only used for menu display if non-empty -- otherwise Text is used"`
	Icon  string            `desc:"icon name"`
	Desc  string            `desc:"possible extra information, e.g. type, arguments, etc. - not currently used"`
	Extra map[string]string `desc:"lang specific or other, e.g. class or type"`
}

Completion holds one potential completion

func MatchSeedCompletion

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

MatchSeedCompletion returns a list of matching completion structs given a list of possibilities and a seed. The seed is basically a prefix.

type Completions

type Completions []Completion

Completions is a full list (slice) of completion options

type EditData

type EditData struct {
	NewText       string `desc:"completion text after special edits"`
	ForwardDelete int    `desc:"number of runes, past the cursor, to delete, if any"`
	CursorAdjust  int    `desc:"cursor adjustment if cursor should be placed in a location other than at end of newText"`
}

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

func EditWord

func EditWord(text string, cp int, completion string, seed string) (ed EditData)

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

type EditFunc

type EditFunc func(data interface{}, text string, cursorPos int, completion Completion, seed string) EditData

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

type MatchData

type MatchData struct {
	Matches Completions `desc:"the matches based on seed"`
	Seed    string      `desc:"seed is the prefix we use to find possible completions"`
}

MatchData is used for passing completions around -- contains seed in addition to completions

type MatchFunc

type MatchFunc func(data interface{}, text string, posLn, posCh int) MatchData

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

Jump to

Keyboard shortcuts

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