completion

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2024 License: BSD-3-Clause Imports: 50 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 *cache.Snapshot, fh file.Handle, 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
}

A CompletionItem represents a possible completion suggested by the algorithm.

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 Selection

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

A Selection represents the cursor position and surrounding identifier.

func (Selection) Prefix

func (p Selection) Prefix() string

func (Selection) PrefixRange added in v0.16.0

func (p Selection) PrefixRange() (protocol.Range, error)

PrefixRange returns the protocol.Range of the prefix of the selection.

func (Selection) Range

func (p Selection) Range() (protocol.Range, error)

Range returns the surrounding identifier's protocol.Range.

func (Selection) Suffix

func (p Selection) Suffix() string

Directories

Path Synopsis
Package snippet implements the specification for the LSP snippet format.
Package snippet implements the specification for the LSP snippet format.

Jump to

Keyboard shortcuts

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