elvish: github.com/elves/elvish/pkg/edit/complete Index | Files

package complete

import "github.com/elves/elvish/pkg/edit/complete"

Package complete implements the code completion algorithm for Elvish.


Package Files

complete.go completers.go filterers.go generators.go node_utils.go raw_item.go

type ArgGenerator Uses

type ArgGenerator func(args []string) ([]RawItem, error)

ArgGenerator is the type of functions that generate raw candidates for a command argument. It takes all the existing arguments, the last being the argument to complete, and returns raw candidates or an error.

type CodeBuffer Uses

type CodeBuffer struct {
    Content string
    Dot     int

CodeBuffer is the same the type in github.com/elves/elvish/pkg/el/codearea, replicated here to avoid an unnecessary dependency.

type ComplexItem Uses

type ComplexItem struct {
    Stem         string   // Used in the code and the menu.
    CodeSuffix   string   // Appended to the code.
    Display      string   // How the item is displayed. If empty, defaults to Stem.
    DisplayStyle ui.Style // Use for displaying.

ComplexItem is an implementation of RawItem that offers customization options.

func (ComplexItem) Cook Uses

func (c ComplexItem) Cook(q parse.PrimaryType) completion.Item

func (ComplexItem) String Uses

func (c ComplexItem) String() string

type Config Uses

type Config struct {
    // An interface to access the runtime. Complete will return an error if this
    // is nil.
    PureEvaler PureEvaler
    // A function for filtering raw candidates. If nil, no filtering is done.
    Filterer Filterer
    // Used to generate candidates for a command argument. Defaults to
    // Filenames.
    ArgGenerator ArgGenerator

Config stores the configuration required for code completion.

type Filterer Uses

type Filterer func(ctxName, seed string, rawItems []RawItem) []RawItem

Filterer is the type of functions that filter raw candidates.

type PlainItem Uses

type PlainItem string

PlainItem is a simple implementation of RawItem.

func (PlainItem) Cook Uses

func (p PlainItem) Cook(q parse.PrimaryType) completion.Item

func (PlainItem) String Uses

func (p PlainItem) String() string

type PureEvaler Uses

type PureEvaler interface {
    EachExternal(func(cmd string))
    EachSpecial(func(special string))
    EachVariableInNs(string, func(string))
    PurelyEvalPrimary(pn *parse.Primary) interface{}
    PurelyEvalCompound(*parse.Compound) (string, error)
    PurelyEvalPartialCompound(*parse.Compound, *parse.Indexing) (string, error)

PureEvaler encapsulates the functionality the completion algorithm needs from the language runtime.

type RawItem Uses

type RawItem interface {
    String() string
    Cook(parse.PrimaryType) completion.Item

RawItem represents completion items before the quoting pass.

func FilterPrefix Uses

func FilterPrefix(ctxName, seed string, items []RawItem) []RawItem

FilterPrefix filters raw items by prefix. It can be used as a Filterer in Config.

func GenerateFileNames Uses

func GenerateFileNames(args []string) ([]RawItem, error)

GenerateFileNames returns filename candidates that are suitable for completing the last argument. It can be used in Config.ArgGenerator.

func GenerateForSudo Uses

func GenerateForSudo(cfg Config, args []string) ([]RawItem, error)

GenerateForSudo generates candidates for sudo.

type Result Uses

type Result struct {
    Name    string
    Replace diag.Ranging
    Items   []completion.Item

Result keeps the result of the completion algorithm.

func Complete Uses

func Complete(code CodeBuffer, cfg Config) (*Result, error)

Complete runs the code completion algorithm in the given context, and returns the completion type, items and any error encountered.

Package complete imports 17 packages (graph) and is imported by 1 packages. Updated 2020-02-22. Refresh now. Tools for package owners.