completion

package
v0.0.0-...-cdc0bb7 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package completion completes CockroachDB SQL with CockroachDB's own grammar, read from the vendor goyacc parser rather than PostgreSQL's.

The vendor parser keeps its LALR tables private, so completion asks it questions through its public Parse instead:

  • Keywords: the text before the caret is parsed with each CockroachDB keyword appended. A keyword is offered when the parser shifts it, which an LALR(1) parser does only for a token that can follow the prefix. The prefix is first reduced to a shorter one that leaves the parser in the same state (probePrefix), and probing stops at a time budget.
  • Names: the word at the caret is replaced by a placeholder identifier and the statement is parsed, patched with a few closing tails when it is incomplete. Where the placeholder lands in CockroachDB's AST says what it names (a table, a column, an index after @) and which tables, aliases and CTEs are in scope. When no patch parses, a lexical scan of the statement supplies the scope.
  • Built-in functions and type names come from builtins.go, recorded from the pinned CockroachDB server.

Index

Constants

View Source
const (
	CandidateKeyword          = analysis.CandidateKeyword          // SQL keyword
	CandidateSchema           = analysis.CandidateSchema           // schema name
	CandidateTable            = analysis.CandidateTable            // table name
	CandidateView             = analysis.CandidateView             // view name
	CandidateMaterializedView = analysis.CandidateMaterializedView // materialized view name
	CandidateColumn           = analysis.CandidateColumn           // column name
	CandidateFunction         = analysis.CandidateFunction         // function name
	CandidateSequence         = analysis.CandidateSequence         // sequence name
	CandidateIndex            = analysis.CandidateIndex            // index name
	CandidateType_            = analysis.CandidateType_            // type name
)

Variables

View Source
var Engine engine

Engine is CockroachDB's analysis.Completer.

Functions

func QuoteIdentifierIfNeeded

func QuoteIdentifierIfNeeded(name string, caretInQuotes bool) string

QuoteIdentifierIfNeeded double-quotes name when CockroachDB would not read it back bare: it has upper case or special characters, or is a reserved keyword. Inside an open double quote only embedded quotes are doubled.

Types

type Candidate

type Candidate struct {
	Text       string        // the completion text
	Type       CandidateType // what kind of object this is
	Definition string        // optional definition/signature
	Comment    string        // optional doc comment
}

Candidate is a single completion suggestion.

func CompleteSession

func CompleteSession(ctx context.Context, cfg SessionConfig, statement string, caretLine, caretOffset int) []Candidate

CompleteSession completes the statement of a script at the 1-based line and 0-based UTF-16 code-unit caretOffset, as an editor reports a caret.

type CandidateType

type CandidateType = analysis.CandidateType

CandidateType classifies a completion candidate.

type SessionConfig

type SessionConfig struct {
	// DefaultDatabase is the active database name passed to LoadDatabase.
	DefaultDatabase string
	// DefaultSchema resolves unqualified names before "public" when
	// non-empty.
	DefaultSchema string
	// LoadDatabase fetches metadata for DefaultDatabase. When nil or failing,
	// completion runs without catalog objects and returns only keywords and
	// statement-local names such as CTEs.
	LoadDatabase func(ctx context.Context, name string) (*metadatapb.DatabaseSchemaMetadata, error)
}

SessionConfig configures session-aware CockroachDB completion.

Jump to

Keyboard shortcuts

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