tools: golang.org/x/tools/internal/lsp/snippet Index | Files

package snippet

import "golang.org/x/tools/internal/lsp/snippet"

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

Package Files

snippet_builder.go

type Builder Uses

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) String Uses

func (b *Builder) String() string

String returns the built snippet string.

func (*Builder) WriteChoice Uses

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 Uses

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 Uses

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 Uses

func (b *Builder) WriteText(s string)

Package snippet imports 2 packages (graph) and is imported by 3 packages. Updated 2019-11-17. Refresh now. Tools for package owners.