completion

package
v1.5.12 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package completion provides code completion for LSP.

Package completion provides code completion for the Lua language server.

It analyzes the cursor position and context to suggest relevant completions including local variables, global symbols, table fields, and type members.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveMemberType added in v1.5.3

func ResolveMemberType(t typ.Type, name string) typ.Type

ResolveMemberType resolves the type of a named member on the given receiver type. It returns nil if the member cannot be resolved.

Types

type Context

type Context struct {
	File        string
	Line        int
	Col         int
	Trigger     TriggerKind
	TriggerChar string
	Prefix      string      // text before cursor on current "word"
	Kind        ContextKind // detected context kind
	// ReceiverType is the resolved type of the receiver for member access (after ".").
	ReceiverType typ.Type
	// LocalSymbols holds in-scope locals at the completion site.
	// When provided, identifier completions will prefer these symbols.
	LocalSymbols []*index.Symbol
}

Context describes the completion context.

type ContextKind

type ContextKind int

ContextKind describes what kind of completion is needed.

const (
	ContextUnknown    ContextKind = iota
	ContextIdentifier             // local variable, function name
	ContextMember                 // after "." - field/method access
	ContextKeyword                // language keywords
)

type Item

type Item struct {
	Label         string   // display text
	Kind          Kind     // item kind
	Detail        string   // type signature
	Documentation string   // doc comment
	InsertText    string   // text to insert (may differ from label)
	IsSnippet     bool     // if InsertText contains $1, $2 placeholders
	SortText      string   // for ordering
	FilterText    string   // for filtering
	Deprecated    bool     // whether this item is deprecated
	Type          typ.Type // the type of the completed item
}

Item represents a completion suggestion.

type Kind

type Kind int

Kind represents completion item kind (matches LSP CompletionItemKind).

const (
	KindText Kind = iota + 1
	KindMethod
	KindFunction
	KindConstructor
	KindField
	KindVariable
	KindClass
	KindInterface
	KindModule
	KindProperty
	KindUnit
	KindValue
	KindEnum
	KindKeyword
	KindSnippet
	KindColor
	KindFile
	KindReference
	KindFolder
	KindEnumMember
	KindConstant
	KindStruct
	KindEvent
	KindOperator
	KindTypeParameter
)

type Provider

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

Provider handles completion requests.

func NewProvider

func NewProvider(symbols *index.SymbolIndex) *Provider

NewProvider creates a completion provider.

func (*Provider) Complete

func (p *Provider) Complete(ctx *Context) []Item

Complete returns completion items for the given context.

func (*Provider) ResolveItem

func (p *Provider) ResolveItem(item *Item) *Item

ResolveItem adds detail to a completion item (lazy loading).

func (*Provider) SetTypeFormatter

func (p *Provider) SetTypeFormatter(f TypeFormatter)

SetTypeFormatter sets a custom type formatter for completion details.

type TriggerKind

type TriggerKind int

TriggerKind describes how completion was triggered.

const (
	TriggerInvoked TriggerKind = iota + 1
	TriggerCharacter
	TriggerIncomplete
)

type TypeFormatter

type TypeFormatter func(any) string

TypeFormatter formats a type for display.

Jump to

Keyboard shortcuts

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