tools: Index | Files

package completion

import ""

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


Package Files

completion.go completion_builtin.go completion_format.go completion_keywords.go completion_labels.go completion_literal.go completion_package.go completion_printf.go completion_snippet.go completion_statements.go deep_completion.go util.go


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"
const MaxDeepCompletions = 3

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

func Completion Uses

func Completion(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle, protoPos protocol.Position, triggerCharacter string) ([]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.

type CompletionItem Uses

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

    // 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 Uses

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 Uses

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 Uses

func (e ErrIsDefinition) Error() string

type Selection Uses

type Selection struct {
    // contains filtered or unexported fields

A Selection represents the cursor position and surrounding identifier.

func (Selection) Content Uses

func (p Selection) Content() string

func (Selection) End Uses

func (p Selection) End() token.Pos

func (Selection) Prefix Uses

func (p Selection) Prefix() string

func (Selection) Start Uses

func (p Selection) Start() token.Pos

func (Selection) Suffix Uses

func (p Selection) Suffix() string

Package completion imports 28 packages (graph) and is imported by 3 packages. Updated 2020-09-30. Refresh now. Tools for package owners.