complete

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: BSD-3-Clause Imports: 7 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 AddSyms added in v0.9.11

func AddSyms(sym syms.SymMap, scope string, md *Matches)

AddSyms adds given symbols as matches in the given match data Scope is e.g., type name (label only)

func AddSymsPrefix added in v0.9.11

func AddSymsPrefix(sym syms.SymMap, scope, seed string, md *Matches)

AddSymsPrefix adds subset of symbols that match seed prefix to given match data

func AddTypeNames added in v0.9.11

func AddTypeNames(typ *syms.Type, scope, seed string, md *Matches)

AddTypeNames adds names from given type as matches in the given match data Scope is e.g., type name (label only), and seed is prefix filter for names

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 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 Edit added in v0.9.11

type Edit 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"`
}

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

func EditWord

func EditWord(text string, cp 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 interface{}, 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 added in v0.9.11

type Lookup struct {
	Filename string `desc:"if non-empty, the result is to view this file (full path)"`
	StLine   int    `desc:"starting line number within file to display"`
	EdLine   int    `desc:"ending line number within file"`
	Text     []byte `desc:"if filename is empty, this is raw text to display for lookup result"`
}

Lookup is used for returning lookup results

func (*Lookup) SetFile added in v0.9.11

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

SetFile sets file info

type LookupFunc added in v0.9.11

type LookupFunc func(data interface{}, text string, posLn, posCh int) Lookup

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

type MatchFunc

type MatchFunc func(data interface{}, text string, posLn, posCh 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 added in v0.9.11

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

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