completion

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package completion suggests completions for partially typed ClickHouse SQL.

The engine is a pure function of the input text, the cursor position and a metadata snapshot: it performs no I/O and can therefore run on every keystroke. It works on tokens rather than a parse tree because the input is by definition incomplete; see context.go for the heuristics.

Index

Constants

View Source
const MaxSuggestions = 500

MaxSuggestions caps the size of a result.

View Source
const WordSeparators = " \t\n\r!\"#%&'()*+,-./:;<=>?@[]^{|}~"

WordSeparators are the characters that end a completable word. The line editor re-derives the word being replaced from these, so suggestions must never contain one of them; names that would are not offered (see offerable).

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgKind

type ArgKind int

ArgKind says what a meta command's argument refers to.

const (
	ArgNone ArgKind = iota
	ArgDatabase
	ArgTable
	ArgFormat
)

type Engine

type Engine struct {
	Commands []MetaCommand
	// OutputFormats are the client-side formats offered after FORMAT.
	OutputFormats []string
}

Engine completes SQL and meta commands.

func (*Engine) Complete

func (e *Engine) Complete(input string, cursor int, snap *metadata.Snapshot, database string) Result

Complete returns suggestions for the word that ends at cursor (a byte offset into input). database is the session's current database.

type Kind

type Kind string

Kind says what a suggestion is.

const (
	KindKeyword       Kind = "keyword"
	KindDatabase      Kind = "database"
	KindTable         Kind = "table"
	KindView          Kind = "view"
	KindDictionary    Kind = "dictionary"
	KindColumn        Kind = "column"
	KindAlias         Kind = "alias"
	KindFunction      Kind = "function"
	KindAggregate     Kind = "aggregate function"
	KindTableFunction Kind = "table function"
	KindDataType      Kind = "type"
	KindEngine        Kind = "engine"
	KindFormat        Kind = "format"
	KindSetting       Kind = "setting"
	KindCommand       Kind = "command"
)

type MetaCommand

type MetaCommand struct {
	Name string // including the backslash
	Help string
	Arg  ArgKind
}

MetaCommand describes a backslash command for completion purposes.

type Result

type Result struct {
	Suggestions []Suggestion
	// Start is the byte offset of the word being completed; a chosen
	// suggestion replaces input[Start:cursor].
	Start int
}

Result is the outcome of a completion request.

type Suggestion

type Suggestion struct {
	// Text replaces the word being completed.
	Text string
	Kind Kind
	// Detail is extra information for display, such as a column's type.
	Detail string
}

Suggestion is one completion candidate.

Jump to

Keyboard shortcuts

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