complete

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package complete turns a caret position into completion candidates.

The engine is pure logic over a Catalog lookup, so the interesting part — which names belong at which position — is tested without a database or a terminal.

Index

Constants

View Source
const MaxCandidates = 200

MaxCandidates bounds the popup. A schema with thousands of tables would otherwise produce a list nobody can navigate.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Text   string
	Kind   Kind
	Detail string
	// ReplaceFrom and ReplaceTo delimit what accepting this candidate
	// overwrites, so the editor does not have to work it out again.
	ReplaceFrom, ReplaceTo int
}

Candidate is one suggestion, together with the text it replaces.

type Catalog

type Catalog interface {
	Schemas(ctx context.Context, datasource string) ([]string, error)
	Tables(ctx context.Context, datasource, schema string) ([]string, error)
	Columns(ctx context.Context, datasource, schema, table string) ([]string, error)
}

Catalog is the metadata source. It is an interface so the engine can be tested without SQLite, and so a cold cache is just an empty answer.

type Engine

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

Engine produces candidates for one datasource.

func New

func New(catalog Catalog, datasource, defaultSchema string) *Engine

New returns an engine reading from catalog.

func (*Engine) SetSchema

func (e *Engine) SetSchema(schema string)

SetSchema changes the schema unqualified names resolve against, which follows the tree selection and any USE statement.

func (*Engine) Suggest

func (e *Engine) Suggest(ctx context.Context, sql string, offset int) ([]Candidate, error)

Suggest returns candidates for the caret position in sql.

A catalog failure yields no candidates rather than an error: completion runs on a keystroke, and a cold or locked cache must never interrupt typing.

type Kind

type Kind int

Kind classifies a candidate, so the popup can label it.

const (
	KindTable Kind = iota
	KindColumn
	KindSchema
	KindKeyword
)

func (Kind) String

func (k Kind) String() string

Jump to

Keyboard shortcuts

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