toolsgolang.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

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)

Source Files

snippet_builder.go

Version
v0.1.10
Published
Mar 15, 2022
Platform
js/wasm
Imports
2 packages
Last checked
6 hours ago

Tools for package owners.