Documentation

Overview

Package snippet implements the specification for the LSP snippet format.

Snippets are "tab stop" templates returned as an optional attribute of LSP completion candidates. As the user presses tab, they cycle through a series of tab stops defined in the snippet. Each tab stop can optionally have placeholder text, which can be pre-selected by editors. For a full description of syntax and features, see "Snippet Syntax" at https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_completion.

A typical snippet looks like "foo(${1:i int}, ${2:s string})".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

A Builder is used to build an LSP snippet piecemeal. The zero value is ready to use. Do not copy a non-zero Builder.

func (*Builder) PrependText

func (b *Builder) PrependText(s string)

func (*Builder) String

func (b *Builder) String() string

String returns the built snippet string.

func (*Builder) Write

func (b *Builder) Write(data []byte) (int, error)

func (*Builder) WriteChoice

func (b *Builder) WriteChoice(choices []string)

WriteChoice writes a tab stop and list of text choices to the Builder. The user's editor will prompt the user to choose one of the choices.

func (*Builder) WriteFinalTabstop

func (b *Builder) WriteFinalTabstop()

WriteFinalTabstop marks where cursor ends up after the user has cycled through all the normal tab stops. It defaults to the character after the snippet.

func (*Builder) WritePlaceholder

func (b *Builder) WritePlaceholder(fn func(*Builder))

WritePlaceholder writes a tab stop and placeholder value to the Builder. The callback style allows for creating nested placeholders. To write an empty tab stop, provide a nil callback.

func (*Builder) WriteText

func (b *Builder) WriteText(s string)