complete

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package complete implements the code completion algorithm for Elvish.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgGenerator

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

type CodeBuffer struct {
	Content string
	Dot     int
}

CodeBuffer is the same the type in src.elv.sh/pkg/el/codearea, replicated here to avoid an unnecessary dependency.

type ComplexItem

type ComplexItem struct {
	Stem       string  // Used in the code and the menu.
	CodeSuffix string  // Appended to the code.
	Display    ui.Text // How the item is displayed. If empty, defaults to ui.T(Stem).
}

ComplexItem is an implementation of RawItem that offers customization options.

func (ComplexItem) Cook

func (ComplexItem) String

func (c ComplexItem) String() string

type Config

type Config struct {
	// A function for filtering raw candidates. If nil, no filtering is done.
	Filterer Filterer
	// Used to generate candidates for a command argument. Defaults to
	// GenerateFileNames.
	ArgGenerator ArgGenerator
}

Config stores the configuration required for code completion.

type Filterer

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

Filterer is the type of functions that filter raw candidates.

type PlainItem

type PlainItem string

PlainItem is a simple implementation of RawItem.

func (PlainItem) Cook

func (PlainItem) String

func (p PlainItem) String() string

type RawItem

type RawItem interface {
	String() string
	Cook(parse.PrimaryType) modes.CompletionItem
}

RawItem represents completion items before the quoting pass.

func FilterPrefix

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

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

func GenerateForSudo(args []string, ev *eval.Evaler, cfg Config) ([]RawItem, error)

GenerateForSudo generates candidates for sudo.

type Result

type Result struct {
	Name    string
	Replace diag.Ranging
	Items   []modes.CompletionItem
}

Result keeps the result of the completion algorithm.

func Complete

func Complete(code CodeBuffer, ev *eval.Evaler, cfg Config) (*Result, error)

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

Jump to

Keyboard shortcuts

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