completion

package
v0.0.0-...-f39ad0c Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: GPL-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package completion provides core functionality for code completion in Go editors and tools.

Index

Constants

View Source
const (
	BREAK       = "break"
	CASE        = "case"
	CHAN        = "chan"
	CONST       = "const"
	CONTINUE    = "continue"
	DEFAULT     = "default"
	DEFER       = "defer"
	ELSE        = "else"
	FALLTHROUGH = "fallthrough"
	FOR         = "for"
	FUNC        = "func"
	GO          = "go"
	GOTO        = "goto"
	IF          = "if"
	IMPORT      = "import"
	INTERFACE   = "interface"
	MAP         = "map"
	PACKAGE     = "package"
	RANGE       = "range"
	RETURN      = "return"
	SELECT      = "select"
	STRUCT      = "struct"
	SWITCH      = "switch"
	TYPE        = "type"
	VAR         = "var"
)
View Source
const MaxDeepCompletions = 3

MaxDeepCompletions limits deep completion results because in most cases there are too many to be useful.

Variables

This section is empty.

Functions

func Completion

func Completion(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle, protoPos protocol.Position, protoContext protocol.CompletionContext) ([]CompletionItem, *Selection, error)

Completion returns a list of possible candidates for completion, given a a file and a position.

The selection is computed based on the preceding identifier and can be used by the client to score the quality of the completion. For instance, some clients may tolerate imperfect matches as valid completion results, since users may make typos.

Types

type CompletionItem

type CompletionItem struct {
	// Label is the primary text the user sees for this completion item.
	Label string

	// Detail is supplemental information to present to the user.
	// This often contains the type or return type of the completion item.
	Detail string

	// InsertText is the text to insert if this item is selected.
	// Any of the prefix that has already been typed is not trimmed.
	// The insert text does not contain snippets.
	InsertText string

	Kind       protocol.CompletionItemKind
	Tags       []protocol.CompletionItemTag
	Deprecated bool // Deprecated, prefer Tags if available

	// An optional array of additional TextEdits that are applied when
	// selecting this completion.
	//
	// Additional text edits should be used to change text unrelated to the current cursor position
	// (for example adding an import statement at the top of the file if the completion item will
	// insert an unqualified type).
	AdditionalTextEdits []protocol.TextEdit

	// Depth is how many levels were searched to find this completion.
	// For example when completing "foo<>", "fooBar" is depth 0, and
	// "fooBar.Baz" is depth 1.
	Depth int

	// Score is the internal relevance score.
	// A higher score indicates that this completion item is more relevant.
	Score float64

	// Documentation is the documentation for the completion item.
	Documentation string
	// contains filtered or unexported fields
}

func (*CompletionItem) Snippet

func (i *CompletionItem) Snippet() string

Snippet is a convenience returns the snippet if available, otherwise the InsertText. used for an item, depending on if the callee wants placeholders or not.

type ErrIsDefinition

type ErrIsDefinition struct {
	// contains filtered or unexported fields
}

ErrIsDefinition is an error that informs the user they got no completions because they tried to complete the name of a new object being defined.

func (ErrIsDefinition) Error

func (e ErrIsDefinition) Error() string

type Selection

type Selection struct {
	source.MappedRange
	// contains filtered or unexported fields
}

A Selection represents the cursor position and surrounding identifier.

func (Selection) Content

func (p Selection) Content() string

func (Selection) End

func (p Selection) End() token.Pos

func (Selection) Prefix

func (p Selection) Prefix() string

func (Selection) Start

func (p Selection) Start() token.Pos

func (Selection) Suffix

func (p Selection) Suffix() string

Jump to

Keyboard shortcuts

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