quickinput

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 26 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 quickinput holds the command palette, quick open and the pickers (SPEC §10.6).

The model files (item.go, picker.go, registry.go, controller.go, listprovider.go, commands.go, gotoline.go, help.go, views.go) import no Glutter type: a Picker is the state of one quick pick (its value, items, filtering and active item), a Registry maps prefixes to providers, and a Controller shows one picker at a time and switches providers as the value changes. They are used on the UI thread only and tested without a window. The widget (host.go, rows.go) shows the controller's picker.

Index

Constants

View Source
const (
	// CommandsPrefix is the prefix of the mode that lists the commands.
	CommandsPrefix = ">"
	// ShowCommandsCommand is Show All Commands.
	ShowCommandsCommand = "workbench.action.showCommands"
)

The prefix of the command palette and the id of the command that opens it.

View Source
const (
	// EditorsPrefix lists the editors of all groups in the order of the groups and the tabs: "edt ".
	EditorsPrefix = "edt "
	// EditorsMRUPrefix lists them in the order they were used: "edt mru ".
	EditorsMRUPrefix = "edt mru "
	// EditorsActiveGroupPrefix lists the editors of the active group in the order they were used: "edt active ".
	EditorsActiveGroupPrefix = "edt active "
	// EditorsContextKey is true while one of the editor modes is shown (VS Code's inEditorsPicker).
	EditorsContextKey = "inEditorsPicker"
	// EditorsPlaceholder is the hint of the input in these modes.
	EditorsPlaceholder = "Type the name of an editor to open it."
	// EditorsNoResults is the row shown when no editor matches.
	EditorsNoResults = "No matching editors"
)

The prefixes of the modes that list the open editors, the context key that is true while one of them is shown, and the labels of the picker.

View Source
const (
	// ShowAllEditorsCommand is Show All Editors By Appearance (Ctrl+K Ctrl+P).
	ShowAllEditorsCommand = "workbench.action.showAllEditors"
	// ShowAllEditorsByMRUCommand is Show All Editors By Most Recently Used.
	ShowAllEditorsByMRUCommand = "workbench.action.showAllEditorsByMostRecentlyUsed"
	// ShowEditorsInActiveGroupCommand is Show Editors in Active Group By Most Recently Used.
	ShowEditorsInActiveGroupCommand = "workbench.action.showEditorsInActiveGroup"
)

The ids of the commands that open the editor modes.

View Source
const (
	// FilesPlaceholder is the hint of the input in the file mode. VS Code's text goes on with "to go to
	// symbol), or paste a link", which the file mode does not have.
	FilesPlaceholder = "Search files by name (append : to go to line)"
	// FilesNoResults is the row shown when nothing matches.
	FilesNoResults = "No matching results"
	// FilesRecentSeparator and FilesResultsSeparator are the headings of the two groups of rows.
	FilesRecentSeparator  = "recently opened"
	FilesResultsSeparator = "file results"
	// FilesContextKey is the context key that is true while the file mode is shown (VS Code's
	// defaultQuickAccessContextKeyValue).
	FilesContextKey = "inFilesPicker"
	// QuickOpenCommand is the command that opens the quick input, in the file mode by default.
	QuickOpenCommand = "workbench.action.quickOpen"
)

The labels of the file mode.

View Source
const (
	// GoToLinePrefix is the prefix of the mode that goes to a line and a column.
	GoToLinePrefix = ":"
	// GoToOffsetPrefix is the prefix of the mode that goes to a character position.
	GoToOffsetPrefix = "::"
	// GoToLineCommand is Go to Line/Column.
	GoToLineCommand = "workbench.action.gotoLine"
	// GoToOffsetCommand is Go to Offset.
	GoToOffsetCommand = "workbench.action.gotoOffset"
)

The prefixes of the go to line modes and the ids of the commands that open them.

View Source
const (
	// MaxWidth is the widest the widget gets; it is 62% of the window when that is less.
	MaxWidth = 600.0
	// MaxListHeight is the height of 20 rows, the most the list shows before it scrolls.
	MaxListHeight = 20 * RowHeight
)

Metrics of the quick input widget, from VS Code's quickInput.css and quickInputController.ts.

View Source
const (
	// RowHeight is the height of a row.
	RowHeight = 22.0
	// RowHeightDetail is the height of a row with a detail line.
	RowHeightDetail = 44.0
)

The heights of rows, from VS Code's quickInputList.ts.

View Source
const (
	// ViewsPrefix is the prefix of the mode that opens a view.
	ViewsPrefix = "view "
	// OpenViewCommand is Open View.
	OpenViewCommand = "workbench.action.openView"
	// QuickOpenViewCommand is Quick Open View, which has no key on Linux.
	QuickOpenViewCommand = "workbench.action.quickOpenView"
)

The prefix of the views mode and the ids of the commands that open it.

View Source
const ClearHistoryCommand = "workbench.action.clearCommandHistory"

ClearHistoryCommand is Clear Command History.

View Source
const HelpPrefix = "?"

HelpPrefix is the prefix of the help mode.

Variables

This section is empty.

Functions

func KeyCaps

func KeyCaps(label string) [][]string

KeyCaps splits the label of a keybinding ("Ctrl+K Ctrl+C") into chords and each chord into the names of its keys, which the list draws as key caps: [["Ctrl", "K"], ["Ctrl", "C"]]. A key that is a plus sign stays a key ("Ctrl++" is Ctrl and +).

func RowKey

func RowKey(i int) foundation.Key

RowKey is the key of the widget of the row at an index, which a test finds it by.

Types

type BaseHandler

type BaseHandler struct{}

BaseHandler is a Handler that does nothing, to embed.

func (BaseHandler) Accept

func (BaseHandler) Accept(Row, KeyMods)

Accept implements Handler.

func (BaseHandler) Done

func (BaseHandler) Done(bool)

Done implements Handler.

func (BaseHandler) ValueChanged

func (BaseHandler) ValueChanged(string)

ValueChanged implements Handler.

type Button

type Button struct {
	// Icon is the code point of a Codicon.
	Icon int
	// Tooltip is the hover text.
	Tooltip string
	// AlwaysVisible shows the button on every row, not only on the active row and the row under the pointer:
	// the dirty mark of the editor picker.
	AlwaysVisible bool
	// HoverIcon, when set, is the Codicon the button shows while the pointer is over the row: the dirty dot
	// turns into the cross.
	HoverIcon int
}

Button is a button at the right edge of an item (VS Code's IQuickInputButton).

type CommandsHistory

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

CommandsHistory remembers the commands that were run, the most recent last, up to a limit (VS Code's CommandsHistory, in memory until the UI state is persisted, SPEC §10.10). A command has a counter that grows with each run; the palette puts the commands that have one first, the highest counter first.

func NewCommandsHistory

func NewCommandsHistory(limit int) *CommandsHistory

NewCommandsHistory makes a history that keeps at most limit commands (0 keeps none).

func (*CommandsHistory) Clear

func (h *CommandsHistory) Clear()

Clear forgets every command.

func (*CommandsHistory) IDs

func (h *CommandsHistory) IDs() []string

IDs lists the commands in the history, the most recent first.

func (*CommandsHistory) Peek

func (h *CommandsHistory) Peek(id string) int

Peek is the counter of a command, or 0 when it is not in the history.

func (*CommandsHistory) Push

func (h *CommandsHistory) Push(id string)

Push records that a command was run.

func (*CommandsHistory) Remove

func (h *CommandsHistory) Remove(id string)

Remove takes a command out of the history.

func (*CommandsHistory) SetLimit

func (h *CommandsHistory) SetLimit(limit int)

SetLimit changes the number of commands kept; the oldest are dropped.

type CommandsOptions

type CommandsOptions struct {
	// Commands is the registry of the commands: those with a title are listed.
	Commands *command.Registry
	// Menus, when set, is asked for the CommandPalette menu: a command with an item there whose
	// When does not hold is left out of the palette.
	Menus *command.MenuRegistry
	// Context gives the context keys the preconditions and the keys are looked up in: the keys of
	// the widget that had the focus when the palette opened.
	Context func() contextkey.Context
	// Keybinding gives the label of the key of a command ("Ctrl+G"), or "".
	Keybinding func(id string, ctx contextkey.Context) string
	// Available, when set, is asked about each command with a title: false leaves it out. The window
	// uses it to list the commands of the editor only while an editor is open (VS Code lists the actions
	// of the active text editor, not of the editor that has the focus).
	Available func(id string, ctx contextkey.Context) bool
	// Run runs a command by id; the palette calls it after it is hidden.
	Run func(id string) error
	// OnError is told of a command that failed.
	OnError func(id string, err error)
	// History is the recently used commands; the provider makes one when nil.
	History *CommandsHistory
	// HistoryLimit gives the number of commands the history keeps (workbench.commandPalette.history);
	// the default of 50 when nil.
	HistoryLimit func() int
	// PreserveInput tells whether the last input is restored when the palette opens
	// (workbench.commandPalette.preserveInput).
	PreserveInput func() bool
}

CommandsOptions are what the provider of the command palette needs.

type Controller

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

Controller shows the quick input: one picker at a time, with the provider that the value selects (SPEC §10.6). The widget (Host) follows it with OnChange. It is used on the UI thread only.

func NewController

func NewController(opts ControllerOptions) *Controller

NewController makes a controller over a registry.

func (*Controller) Accept

func (c *Controller) Accept(mods KeyMods)

Accept accepts the active row of the picker: the provider decides what happens (a list provider hides the picker and runs the item). It does nothing when no row is active.

func (*Controller) AcceptRow

func (c *Controller) AcceptRow(row Row, mods KeyMods)

AcceptRow hides the picker and runs the Accept of a row's item once the focus is back. It is what a list provider does when the user accepts; the item without an Accept keeps the picker open.

func (*Controller) Configure

func (c *Controller) Configure(opts ControllerOptions)

Configure sets the hooks of the options that are not nil: the window makes its controller before its widgets exist and gives it the hooks that need them when the shell starts.

func (*Controller) DisarmQuickNavigate

func (c *Controller) DisarmQuickNavigate()

DisarmQuickNavigate stops waiting for the release of the keys: the release was missed, or the window lost the keyboard. The picker goes on as any other: Enter or a click chooses, Escape closes.

func (*Controller) Hide

func (c *Controller) Hide()

Hide closes the quick input without a choice.

func (*Controller) InvokerContext

func (c *Controller) InvokerContext() contextkey.Context

InvokerContext is the context keys of the widget that had the focus when the quick input opened; it is never nil.

func (*Controller) Navigate

func (c *Controller) Navigate(next bool, qn *QuickNavigate)

Navigate moves the active row to the next or the previous one, going round at the ends, and waits again for the release of the keys (VS Code's navigate; the commands quickOpenNavigateNextInEditorPicker and quickOpenNavigatePreviousInEditorPicker run it). With qn nil the picker keeps waiting or not as it was.

func (*Controller) OnChange

func (c *Controller) OnChange(f func()) (remove func())

OnChange calls f when the quick input is shown or hidden and when its picker is replaced; the picker tells of its own changes.

func (*Controller) Pick

func (c *Controller) Pick(opts PickOptions)

Pick shows a pick from a list of items that the caller owns. The item the user chooses has its Accept run after the picker hides.

func (*Controller) Picker

func (c *Controller) Picker() *Picker

Picker is the picker that is shown (or was shown last).

func (*Controller) PressPromptButton added in v1.0.0

func (c *Controller) PressPromptButton(i int)

PressPromptButton presses a button of the input box: its function gets the text and may replace it.

func (*Controller) Prompt

func (c *Controller) Prompt(opts PromptOptions)

Prompt shows an input box (see PromptOptions) in the place of the picker.

func (*Controller) PromptButtons added in v1.0.0

func (c *Controller) PromptButtons() []PromptButton

PromptButtons are the buttons inside the input box that is shown, none when it is not an input box.

func (*Controller) Prompting

func (c *Controller) Prompting() bool

Prompting tells whether the quick input shows an input box.

func (*Controller) Provider

func (c *Controller) Provider() Provider

Provider is the provider of the shown picker, or nil for a pick of the caller or no provider.

func (*Controller) QuickHeld

func (c *Controller) QuickHeld(held Modifiers) bool

QuickHeld tells whether the modifiers held now are those the quick navigate picker waits for the release of; false when it does not wait.

func (*Controller) QuickMode

func (c *Controller) QuickMode() bool

QuickMode tells whether the picker was opened as a switcher driven by held keys. It stays true when the release was never seen and the picker works as any other.

func (*Controller) QuickNavigateKeyUp

func (c *Controller) QuickNavigateKeyUp(released Modifier, held Modifiers) bool

QuickNavigateKeyUp tells the controller that a modifier key was released, with the modifiers held after it. When the picker waits for that key it chooses the active row and stops waiting (it waits for the release only once); it tells whether it did.

func (*Controller) QuickNavigating

func (c *Controller) QuickNavigating() bool

QuickNavigating tells whether the picker waits for the release of the keys that opened it.

func (*Controller) Registry

func (c *Controller) Registry() *Registry

Registry is the registry of the providers.

func (*Controller) RememberValue

func (c *Controller) RememberValue(prefix, value string)

RememberValue stores the value as the last input of the provider, for DefaultFilterLast.

func (*Controller) SetValue

func (c *Controller) SetValue(v string)

SetValue is the user typing: it changes the value of the input.

func (*Controller) Show

func (c *Controller) Show(value string, opts ShowOptions)

Show opens the quick input with a value (VS Code's quickAccess.show). When the provider of the value is the one that is on already, the value replaces the input if it says more than the prefix; the part after the prefix is selected, so that typing replaces it. A value for another provider starts that provider and keeps the text typed after the old prefix.

func (*Controller) Trigger

func (c *Controller) Trigger(row Row, button int, mods KeyMods)

Trigger runs the Trigger of a button of a row's item and does what it says.

func (*Controller) Visible

func (c *Controller) Visible() bool

Visible tells whether the quick input is shown.

type ControllerOptions

type ControllerOptions struct {
	// Registry holds the providers.
	Registry *Registry
	// Post runs a function on the UI thread; a provider that works in the background hands its
	// results over with it. Without it the function runs at once.
	Post func(func())
	// After runs a function once the picker is hidden and the focus is back where it was: an accepted
	// item runs with it. Without it the function runs at once.
	After func(func())
	// FallbackPlaceholder is the hint of the input while no provider takes the value (the file mode
	// is the default provider of VS Code and does not exist yet).
	FallbackPlaceholder string
	// Invoker gives the context keys of the widget that has the focus; the controller asks for them
	// when the quick input opens, before anything takes the focus, and keeps them while it is shown
	// (the keys the command palette looks at). Without it the keys are empty.
	Invoker func() contextkey.Context
}

ControllerOptions are the options of NewController.

type DefaultFilterKind

type DefaultFilterKind int

DefaultFilterKind says how a provider starts when it is opened with just its prefix.

const (
	// DefaultFilterPreserve keeps the value as it is given.
	DefaultFilterPreserve DefaultFilterKind = iota
	// DefaultFilterLast restores the value of the last accepted pick.
	DefaultFilterLast
)

The ways a provider can start.

type DefaultFilterer

type DefaultFilterer interface {
	// DefaultFilterValue says how the provider starts.
	DefaultFilterValue() DefaultFilterKind
}

DefaultFilterer is implemented by a provider that wants the controller to restore the last input (workbench.commandPalette.preserveInput).

type EditorEntry

type EditorEntry struct {
	// ID tells the entry from the others; it is not shown.
	ID string
	// GroupID is the group the editor is in.
	GroupID int
	// Label is the name of the editor and Description its folder; Path is the path of its file, which the
	// filter matches too.
	Label, Description, Path string
	// Dirty tells that the editor has changes that are not saved: its close button is a dot.
	Dirty bool
	// Preview tells that the editor is a preview editor, which is in italics.
	Preview bool
	// FileIcon gives the icon of the editor for the type of the color theme; false draws none.
	FileIcon func(theme.Type) (theme.FileIcon, bool)
	// Open shows the editor in its group.
	Open func()
	// Close closes the editor and tells whether it is gone (it stays when it has unsaved changes and the
	// user cancels).
	Close func() bool
}

EditorEntry is an open editor as the editor picker lists it.

type EditorsMode

type EditorsMode int

EditorsMode is which editors a provider lists, in which order.

const (
	// EditorsByAppearance lists the editors of all groups in the order of the groups and their tabs.
	EditorsByAppearance EditorsMode = iota
	// EditorsByRecentlyUsed lists the editors of all groups, the most recently used first.
	EditorsByRecentlyUsed
	// EditorsInActiveGroup lists the editors of the active group, the most recently used first.
	EditorsInActiveGroup
)

The modes.

type EditorsOptions

type EditorsOptions struct {
	// Entries lists the editors of a mode, in the order the mode shows them when nothing is typed.
	Entries func(mode EditorsMode) []EditorEntry
	// Groups lists the ids of the groups in the order of the grid; GroupLabel names one ("Group 1").
	Groups     func() []int
	GroupLabel func(id int) string
}

EditorsOptions connect the editor modes to the window.

type FileOpen

type FileOpen struct {
	// Path is the absolute path of the file.
	Path string
	// Side opens the file in the group beside the active one.
	Side bool
	// Pinned opens it as a kept editor, not a preview.
	Pinned bool
	// Line and Column are the position to reveal, counted from 1; 0 means none.
	Line, Column int
}

FileOpen asks the window to open a file chosen in the file mode.

type FilesOptions

type FilesOptions struct {
	// Search finds the files for a filter (the text typed without its position suffix). It runs on a
	// goroutine of its own and must return when ctx is done. A search for an empty filter lists the
	// recently opened files.
	Search func(ctx context.Context, filter string) (workspace.QuickOpenResult, error)
	// OnChange, when set, calls f when the list of files changed (the walk found more, the watcher
	// reported a change); f may be called on any goroutine and does not block. The picker then searches
	// again, so the rows grow while the folder is still being listed.
	OnChange func(f func()) (stop func())
	// Open opens a file; it is called on the UI thread, after the picker closed and the focus is back.
	Open func(FileOpen)
	// Icon gives the icon of a file for its path, its name and the type of the color theme (false: none).
	// It is called on the UI thread when a row is built.
	Icon func(path, name string, typ theme.Type) (theme.FileIcon, bool)
	// OpenPinned tells whether an editor chosen with Enter is kept: it is unless
	// workbench.editor.enablePreviewFromQuickOpen and workbench.editor.enablePreview are both on. It
	// also decides what Ctrl does: open to the side when it is true, keep the editor when it is false.
	OpenPinned func() bool
	// SideDirection is "right" or "down" (workbench.editor.openSideBySideDirection), which chooses the
	// icon and the tooltip of the button that opens to the side.
	SideDirection func() string
	// RemoveRecent forgets a recently opened file.
	RemoveRecent func(path string)
	// OnError is told of a search that failed for another reason than a newer keystroke.
	OnError func(err error)
}

FilesOptions connect the file mode to the window.

type GoToLineEditor

type GoToLineEditor interface {
	// LineCount is the number of lines of the text.
	LineCount() int
	// LineContent is the text of a line, without its line break.
	LineContent(line int) string
	// TabSize is the width of a tab, for the visible column the user types.
	TabSize() int
	// Length is the length of the text, in the units of an offset (bytes).
	Length() int
	// PositionAt is the line and the column of an offset.
	PositionAt(offset int) (line, col int)
	// Reveal scrolls to put the position in the middle of the editor and highlights its line.
	Reveal(line, col int)
	// ClearHighlight takes the highlight of the line away.
	ClearHighlight()
	// Go puts the cursor at the position, reveals it and gives the focus to the editor.
	Go(line, col int)
	// Restore puts back the cursors and the scroll the editor had when the mode opened.
	Restore()
}

GoToLineEditor is the editor the go to line modes work on. Lines and columns count from 1; a column is a byte column of the line. The provider reveals a line while the user types and puts the editor back as it was when the user gives up.

type GoToLinePosition

type GoToLinePosition struct {
	// Line and Column are the position to go to, from 1; Line is 0 when the text does not name one.
	Line, Column int
	// InOffsetMode tells that the text started with a second colon.
	InOffsetMode bool
	// Label is the text of the one pick.
	Label string
}

GoToLinePosition is what the text typed in the go to line mode means.

func ParseGoToLine

func ParseGoToLine(ed GoToLineEditor, value string) GoToLinePosition

ParseGoToLine reads the text typed after the first colon: a line and an optional column ("12", "12:5", "12,5", "12#5", a negative number counts from the end), or, after a second colon, a character offset ("::1024"). The column the user types is a visible column (tabs count to the next tab stop); the result is a byte column of the line.

Ported from VS Code: gotoLineQuickAccess.ts (parsePosition)

type GoToLineProvider

type GoToLineProvider struct {

	// Editor gives the editor to work on when the mode opens, or nil when no text editor is open.
	Editor func() GoToLineEditor
	// contains filtered or unexported fields
}

GoToLineProvider is the provider of the go to line modes: the one pick says what Enter does, the editor shows the line while the user types, and giving up puts the editor back.

func NewGoToLineProvider

func NewGoToLineProvider(prefix string, editor func() GoToLineEditor) *GoToLineProvider

NewGoToLineProvider makes the provider of ":" or of "::" (they share what they do).

func (*GoToLineProvider) Info

func (p *GoToLineProvider) Info() ProviderInfo

Info implements Provider.

func (*GoToLineProvider) Provide

func (p *GoToLineProvider) Provide(s *Session) Handler

Provide implements Provider.

type Handler

type Handler interface {
	// ValueChanged is called with the filter (the value without the prefix, trimmed) once after
	// Provide and on every change of the value.
	ValueChanged(filter string)
	// Accept is called when the user accepts the active row (Enter or a click).
	Accept(row Row, mods KeyMods)
	// Done is called when the session ends: the picker was hidden, or another provider took
	// over. accepted tells whether the user accepted an item.
	Done(accepted bool)
}

Handler is what a provider gives the controller to run its session: the controller calls it when the value changes, when the user accepts the active item and when the session ends.

type HelpEntry

type HelpEntry struct {
	// Prefix is what to type; the prefix of the provider when empty.
	Prefix string
	// Description says what the mode does.
	Description string
	// Command is the id of the command that opens the mode; its key is shown in the help.
	Command string
}

HelpEntry is a line of the help (the `?` mode) about a provider.

type Highlights

type Highlights struct {
	Label, Description, Detail []fuzzy.Match
}

Highlights are the parts of an item's texts that matched the filter, in runes.

type Host

type Host struct {
	widgets.StatefulWidget
	// contains filtered or unexported fields
}

Host puts the quick input over its child, which the workbench places once at its root (as kit.DialogHost does with dialogs): a widget centered at the top of the window, under the menu bar, with the input box above the list of the picker. It follows the Controller; when the quick input opens it takes the focus and when it closes it gives the focus back to the widget that had it.

Ported from VS Code: src/vs/platform/quickinput/browser/quickInputController.ts, quickInputList.ts and media/quickInput.css. Not ported: the title bar, the buttons and the message of the input, check boxes, the progress bar, dragging the widget.

func NewHost

func NewHost(child widgets.Widget, opts HostOptions) *Host

NewHost makes the host of the quick input of a controller over a child.

func (*Host) CreateState

func (h *Host) CreateState() widgets.State

CreateState implements widgets.StatefulWidget.

type HostOptions

type HostOptions struct {
	// Controller is what the host shows. Required.
	Controller *Controller
	// Keys is the root scope of the context keys of the window; the host makes a scope below it
	// for the quick input, with inQuickOpen, inQuickInput, inputFocus and quickInputType, and the
	// context key of the provider, set while the quick input is shown.
	Keys *contextkey.Scope
	// Scopes registers the focus node of the input with that scope, so that the key dispatcher
	// resolves keys in it.
	Scopes *kit.FocusScopes
	// Commands is the registry whose workbench.action.closeQuickOpen command the host takes over
	// while it is on screen.
	Commands *command.Registry
	// Settings gives workbench.quickOpen.closeOnFocusLost; without it the quick input closes when it
	// loses the focus.
	Settings *settings.Store
	// TopInset is the height of what the widget sits under: the menu bar.
	TopInset float64
}

HostOptions are the options of NewHost.

type Item

type Item struct {
	// ID identifies the item for the provider (the id of a command); it is not shown.
	ID string
	// Label is the main text; the filter matches it.
	Label string
	// Description is shown after the label in a dimmer color.
	Description string
	// Detail is shown on a second line below the label.
	Detail string
	// Icon is the code point of a Codicon shown before the label; 0 shows none.
	Icon int
	// FileIcon, when set, is asked for the icon of a file icon theme (Seti) to draw before the label in place
	// of Icon, for the type of the color theme; false draws none. It runs on the UI thread, when the row is
	// built.
	FileIcon func(typ theme.Type) (theme.FileIcon, bool)
	// Italic draws the label in italics: a preview editor in the editor picker.
	Italic bool
	// Separator makes the item the heading of the items after it: it cannot be chosen and its
	// Label is drawn at the right of the next item shown, with a line above that item.
	Separator bool
	// Keybinding is the label of the key of the item, such as "Ctrl+G", drawn as key caps.
	Keybinding string
	// Buttons are drawn at the right edge of the row.
	Buttons []Button
	// AlwaysShow keeps the item in the list when the filter does not match it.
	AlwaysShow bool
	// Highlights are the matches the provider found when it filters the items itself.
	Highlights Highlights
	// Data is the provider's own value.
	Data any
	// Accept runs when the item is chosen, after the picker has been hidden and the focus given
	// back (PickerQuickAccessProvider's accept). An item without it does nothing when chosen and
	// the picker stays open.
	Accept func(mods KeyMods)
	// Trigger runs when a button of the item is triggered; the index counts Buttons.
	Trigger func(button int, mods KeyMods) TriggerAction
}

Item is one row of a quick pick (VS Code's IQuickPickItem and IQuickPickSeparator). A separator item has only a Label: the list shows it on the row of the next item that is shown.

type ItemActivation

type ItemActivation int

ItemActivation says which item is active once the items of a picker are set (VS Code's ItemActivation). It applies to the first items that give a row and then goes back to ItemFirst: typing a filter later activates the first row as always.

const (
	// ItemFirst activates the first item that can be chosen.
	ItemFirst ItemActivation = iota
	// ItemSecond activates the second item, or the first when there is only one: the editor that was used
	// before the active one.
	ItemSecond
	// ItemLast activates the last item.
	ItemLast
	// ItemNone activates no item.
	ItemNone
)

The ways the first active item is chosen.

type KeyMods

type KeyMods struct {
	Ctrl, Alt bool
}

KeyMods are the modifier keys held when an item was accepted or a button triggered.

type ListProvider

type ListProvider struct {
	// Info describes the provider.
	ProviderInfo
	// NoResults is the label of the pick shown when there are no picks and the filter is not
	// empty ("No matching commands"); empty shows nothing.
	NoResults string
	// Picks makes the items for a filter (the value without the prefix, trimmed). It runs on the UI
	// thread.
	Picks func(filter string) []Item
	// PicksAsync, when set, is used in place of Picks. It runs in a goroutine and must stop when ctx
	// is done; its items are shown if the filter has not changed meanwhile.
	PicksAsync func(ctx context.Context, filter string) []Item
	// Start, when set, is called when the provider takes over, with the session, and its result is
	// called when the session ends.
	Start func(s *Session) (end func())
	// DefaultFilter says how the provider starts when it is opened with just its prefix.
	DefaultFilter func() DefaultFilterKind
}

ListProvider is a provider that makes its items itself for each filter (VS Code's PickerQuickAccessProvider): the picker's own filtering is off, the items come back with their highlights, and accepting an item hides the picker and then runs the item. Make the picks with Picks, or, for a long job, with PicksAsync, which runs in a goroutine, is cancelled when the filter changes or the picker hides, and hands its result over through the session's Post.

func NewCommandsProvider

func NewCommandsProvider(o CommandsOptions) *ListProvider

NewCommandsProvider makes the provider of the command palette: the commands that have a title and whose precondition holds, as "Category: Title" with their key, those that were used lately first (separated from the others by "recently used" and "other commands"), filtered by the words of the title.

func NewEditorsProvider

func NewEditorsProvider(mode EditorsMode, o EditorsOptions) *ListProvider

NewEditorsProvider makes the provider of one of the modes that list the open editors: the label of an item is the name of the editor and its description the folder, a dirty editor has a dot at the right that turns into a cross under the pointer (the cross closes the editor and takes the item out of the list, the picker stays), a preview editor is in italics. With more than one group the items are grouped under the name of their group. Choosing an item shows the editor.

func NewViewsProvider

func NewViewsProvider(o ViewsOptions) *ListProvider

NewViewsProvider makes the provider of the `view ` mode: the view containers of the side bar and of the panel, then their views, then the output channels, in groups named by their container ("Side Bar", "Side Bar / Explorer", "Panel / Output"). Choosing one opens it.

func (*ListProvider) DefaultFilterValue

func (p *ListProvider) DefaultFilterValue() DefaultFilterKind

DefaultFilterValue implements DefaultFilterer.

func (*ListProvider) Info

func (p *ListProvider) Info() ProviderInfo

Info implements Provider.

func (*ListProvider) Provide

func (p *ListProvider) Provide(s *Session) Handler

Provide implements Provider.

type Modifier

type Modifier int

Modifier names a modifier key.

const (
	// ModCtrl is the Ctrl key.
	ModCtrl Modifier = iota + 1
	// ModShift is the Shift key.
	ModShift
	// ModAlt is the Alt key.
	ModAlt
	// ModMeta is the Meta key (Super).
	ModMeta
)

The modifier keys.

type Modifiers

type Modifiers struct {
	Ctrl, Shift, Alt, Meta bool
}

Modifiers are the modifier keys of a chord.

type PickOptions

type PickOptions struct {
	// Title is a line centered above the input (VS Code's title); none when empty.
	Title string
	// Placeholder is the hint of the input.
	Placeholder string
	// Items are the items; each item's Accept runs when it is chosen.
	Items []Item
	// MatchOnDescription and MatchOnDetail let the filter look at those texts too.
	MatchOnDescription, MatchOnDetail bool
	// IgnoreFocusOut keeps the picker open when the user clicks elsewhere or the window loses the focus (VS Code's
	// ignoreFocusOut): a choice and Escape end it.
	IgnoreFocusOut bool
	// ActiveID, when it is the ID of one of the items, makes that item the active one when the picker opens
	// (VS Code's activeItem: the current end of line sequence, the current tab size).
	ActiveID string
	// OnCancel is called when the picker closes without a choice.
	OnCancel func()
	// OnActive is called when the active item changes while the picker is open, with the item (the arrow keys
	// and typing a filter move it; the pointer does not, as in VS Code's onDidChangeActive); ok is false when
	// no item is active. It is not called for the item that ActiveID made active: the caller knows it. The theme
	// pickers preview with it.
	OnActive func(item Item, ok bool)
	// OnHide is called once when the picker ends, whatever the way: chosen (accepted is true, before the item's
	// Accept runs), closed without a choice, or replaced by another quick input. It is called before OnCancel.
	OnHide func(accepted bool)
}

PickOptions describe a pick from a list of items that the caller owns: the Insert Snippet picker. The items filter by their label, and by their description and detail when asked.

type Picker

type Picker struct {
	// MatchOnLabel, MatchOnDescription, MatchOnDetail and SortByLabel are the switches of the
	// filter; NewPicker turns on the first and the last. Change them before the next SetValue or
	// SetItems.
	MatchOnLabel, MatchOnDescription, MatchOnDetail, SortByLabel bool
	// HideInput hides the input of the picker, which keeps the keyboard: the switcher that Ctrl+Tab opens.
	HideInput bool
	// Obscure shows a dot for each character typed in the input, as a password box does: an input box that asks for a password.
	Obscure bool
	// KeepScrollPosition keeps the first row in view when the items change instead of showing the
	// top of the list.
	KeepScrollPosition bool

	// IgnoreFocusOut keeps the picker open when the focus leaves it (VS Code's ignoreFocusOut); the controller sets it for a pick or a
	// prompt that asked for it.
	IgnoreFocusOut bool
	// contains filtered or unexported fields
}

Picker is the state of one quick pick: the text in its input, the items, which of them the filter lets through, and the active item. The filter is VS Code's: with MatchOnLabel (and MatchOnDescription, MatchOnDetail) an item shows when the filter matches the text, matches are highlighted and, with SortByLabel, the items with a match on the label come first in the order of fuzzy.CompareAnything. A provider that narrows the items itself switches the three off.

A Picker is used on the UI thread only.

func NewPicker

func NewPicker() *Picker

NewPicker makes an empty picker that filters by label and sorts by label.

func (*Picker) Active

func (p *Picker) Active() (Row, bool)

Active is the active row (VS Code's active item: the one the arrow keys moved to).

func (*Picker) ActiveIndex

func (p *Picker) ActiveIndex() int

ActiveIndex is the position in Rows of the active row, or -1 when there is none.

func (*Picker) ClearValueSelection

func (p *Picker) ClearValueSelection()

ClearValueSelection forgets the selection asked for, once the input has taken it.

func (*Picker) Filter

func (p *Picker) Filter() string

Filter is the text the items are filtered by: the value without the prefix of the provider and without white space around it.

func (*Picker) First

func (p *Picker) First()

First makes the first row that can be chosen active.

func (*Picker) Info added in v1.0.0

func (p *Picker) Info() string

Info is the line shown under the input of a prompt while it has no validation message (PromptOptions.Message, VS Code's prompt).

func (*Picker) Items

func (p *Picker) Items() []Item

Items are the items set, whatever the filter says.

func (*Picker) Last

func (p *Picker) Last()

Last makes the last row that can be chosen active.

func (*Picker) Message

func (p *Picker) Message() string

Message is the validation message shown under the input of a prompt (Controller.Prompt), or "".

func (*Picker) Move

func (p *Picker) Move(delta int)

Move moves the active row by delta rows, wrapping round at the ends. Moving down from the last row goes to the first and moving up from the first goes to the last, as the list of the quick pick does.

func (*Picker) OnChange

func (p *Picker) OnChange(f func()) (remove func())

OnChange calls f whenever what the picker shows changes: the rows, the active row, the placeholder, the value selection.

func (*Picker) OnDidChangeActive

func (p *Picker) OnDidChangeActive(f func(r Row, ok bool)) (remove func())

OnDidChangeActive calls f when the active row changes (VS Code's onDidChangeActive); ok is false when no row is active. The theme preview uses it.

func (*Picker) OnDidChangeValue

func (p *Picker) OnDidChangeValue(f func(string)) (remove func())

OnDidChangeValue calls f with the value when SetValue changes it (VS Code's onDidChangeValue).

func (*Picker) Page

func (p *Picker) Page(direction, rows int)

Page moves the active row by a page of rows without wrapping: down goes to the last row at most and up to the first. rows is the number of rows in view.

func (*Picker) Placeholder

func (p *Picker) Placeholder() string

Placeholder is the hint shown in the input while it is empty.

func (*Picker) RawFilter

func (p *Picker) RawFilter() string

RawFilter is the value without the prefix of the provider.

func (*Picker) Rows

func (p *Picker) Rows() []Row

Rows are the items the filter lets through, in the order they are shown.

func (*Picker) SetActive

func (p *Picker) SetActive(i int)

SetActive makes the row at an index active. An index out of range, or of a separator, does nothing.

func (*Picker) SetInfo added in v1.0.0

func (p *Picker) SetInfo(m string)

SetInfo sets the line under the input; "" takes it away.

func (*Picker) SetItemActivation

func (p *Picker) SetItemActivation(a ItemActivation)

SetItemActivation says which row becomes active when the items are set next.

func (*Picker) SetItems

func (p *Picker) SetItems(items []Item)

SetItems replaces the items. The filter is applied and the first item that can be chosen becomes active, as the list does after VS Code sets the items; with KeepScrollPosition the active item stays the same when it is still there.

func (*Picker) SetMessage

func (p *Picker) SetMessage(m string)

SetMessage sets the validation message under the input; "" takes it away.

func (*Picker) SetPlaceholder

func (p *Picker) SetPlaceholder(s string)

SetPlaceholder sets the hint of the input.

func (*Picker) SetPrefixLen

func (p *Picker) SetPrefixLen(n int)

SetPrefixLen sets how many bytes of the value the filter leaves out.

func (*Picker) SetTitle added in v1.0.0

func (p *Picker) SetTitle(s string)

SetTitle sets the line above the input; "" takes it away.

func (*Picker) SetValue

func (p *Picker) SetValue(v string)

SetValue changes the text of the input, filters the items and tells the listeners of the value.

func (*Picker) SetValueSelection

func (p *Picker) SetValueSelection(start, end int)

SetValueSelection asks for a part of the value to be selected.

func (*Picker) Title added in v1.0.0

func (p *Picker) Title() string

Title is the line centered above the input (PickOptions.Title), or "".

func (*Picker) Value

func (p *Picker) Value() string

Value is the text of the input, with the prefix of the provider.

func (*Picker) ValueSelection

func (p *Picker) ValueSelection() (start, end int, ok bool)

ValueSelection is the part of the value the input should select when it is shown, as byte offsets; ok is false when nobody asked for one. Reading it does not clear it.

func (*Picker) Version

func (p *Picker) Version() int

Version counts how many times the rows were made again, so that a list can start at the top when they are new.

type PromptButton added in v1.0.0

type PromptButton struct {
	// Icon is the code point of a Codicon.
	Icon int
	// Tooltip is the text of the hover.
	Tooltip string
	// OnClick is called when the button is pressed, with the text of the input and a function that replaces it. A button with none does
	// nothing.
	OnClick func(value string, set func(value string))
}

PromptButton is a button inside an input box.

type PromptOptions

type PromptOptions struct {
	// Placeholder is the hint of the input while it is empty.
	Placeholder string
	// Value is the text the input starts with; the caret is at its end.
	Value string
	// Password shows a dot for each character typed, as a password box does (VS Code's password option).
	Password bool
	// Message is a line shown under the input while the text is valid (VS Code's prompt; Placeholder is its placeHolder).
	Message string
	// IgnoreFocusOut keeps the input open when the user clicks elsewhere or the window loses the focus (VS Code's
	// ignoreFocusOut): Enter and Escape end it.
	IgnoreFocusOut bool
	// Validate, when set, checks the text on every change and when it is accepted: a message that is not empty is
	// shown under the input (as an error) and the text is not accepted (VS Code's validateInput).
	Validate func(value string) string
	// Buttons are buttons inside the input, after the text (VS Code's inline buttons of an input box): a folder icon that opens the chooser.
	Buttons []PromptButton
	// OnAccept is called with the text, after the input hides and the focus is back, when the user accepted a
	// text that is valid.
	OnAccept func(value string)
	// OnCancel is called when the input closes without an accepted text.
	OnCancel func()
}

PromptOptions describe an input box: a line of text that the user accepts with Enter or cancels with Escape (VS Code's showInputBox). It is how the Save As dialog of the editor asks for a path when the desktop has no file chooser.

type Provider

type Provider interface {
	// Info describes the provider.
	Info() ProviderInfo
	// Provide starts a session on the picker of s. The controller shows the picker after the
	// call; the provider sets what it needs (the matching switches of the picker) and returns the
	// handler of the session.
	Provide(s *Session) Handler
}

Provider fills a picker for a mode of the quick input.

func NewFilesProvider

func NewFilesProvider(opts FilesOptions) Provider

NewFilesProvider makes the provider of the file mode: the default mode of the quick input, with the empty prefix. It shows the recently opened files first and the files of the folder that match, scored on a goroutine for each keystroke (the newest one wins), and a position after the name ("main.go:12:5") is revealed in the file that is opened.

func NewHelpProvider

func NewHelpProvider(registry *Registry, keybinding func(commandID string) string) Provider

NewHelpProvider makes the provider of the `?` mode: it lists the modes the registry has, with what to type and the key of the command that opens each, and choosing one (or typing its prefix) opens that mode. keybinding gives the label of the key of a command, and may be nil.

type ProviderInfo

type ProviderInfo struct {
	// Prefix is the text that selects the provider when the value starts with it. The provider
	// with the longest matching prefix wins; the provider with the empty prefix is the default
	// and is used when no other matches.
	Prefix string
	// Placeholder is the hint of the input while the provider is active.
	Placeholder string
	// ContextKey, when set, is a context key that is true while the provider is active
	// ("inCommandsPicker").
	ContextKey string
	// Help are the lines the `?` mode lists for the provider.
	Help []HelpEntry
}

ProviderInfo describes a provider.

type QuickNavigate

type QuickNavigate struct {
	// Chords are the modifiers of the keybindings of the command that opened the picker; a chord of more than
	// one key press is not in the list.
	Chords []Modifiers
}

QuickNavigate is the state of a picker that is driven by keys that are held (VS Code's IQuickNavigateConfiguration): the chords of the keys that opened it, and the keys that move in it. Releasing the modifier of one of the chords chooses the active item.

type Registry

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

Registry maps prefixes to providers (VS Code's IQuickAccessRegistry).

func NewRegistry

func NewRegistry() *Registry

NewRegistry makes an empty registry.

func (*Registry) MustRegister

func (r *Registry) MustRegister(ps ...Provider)

MustRegister is Register for the table of built-in providers; it panics on a failure.

func (*Registry) Providers

func (r *Registry) Providers() []Provider

Providers lists the providers ordered by prefix (the default provider first).

func (*Registry) Register

func (r *Registry) Register(p Provider) error

Register adds a provider. Its prefix must not be registered yet.

func (*Registry) Resolve

func (r *Registry) Resolve(value string) Provider

Resolve finds the provider for a value: the one with the longest prefix the value starts with, else the default provider (the empty prefix), else nil.

func (*Registry) Unregister

func (r *Registry) Unregister(prefix string)

Unregister removes the provider of a prefix, if there is one.

type Row

type Row struct {
	// Item is the item.
	Item Item
	// Index is the position of the item among the items of the picker.
	Index int
	// Label, Description and Detail are the matches to highlight.
	Label, Description, Detail []fuzzy.Match
	// Separator is the label of the separator before the row, or "".
	Separator string
	// Border tells that a line is drawn above the row (a row with a separator that is not the first).
	Border bool
}

Row is an item as the list shows it: the matches of the current filter, the heading of its group and whether a line is drawn above it.

func (Row) Height

func (r Row) Height() float64

Height is the height of the row in the list: 22 px, or 44 px with a detail line.

type Session

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

Session is what a provider sees of the controller while its picker is shown. It ends when the picker is hidden or another provider takes over; then its context is cancelled and the functions given to OnEnd run.

func (*Session) After

func (s *Session) After(f func())

After runs f once the picker is hidden and the focus is back where it was (see ControllerOptions.After); a button of an item uses it to do its work after the picker closed.

func (*Session) Context

func (s *Session) Context() context.Context

Context is cancelled when the session ends; a provider that works in the background passes it on.

func (*Session) Hide

func (s *Session) Hide()

Hide closes the picker without accepting an item.

func (*Session) OnEnd

func (s *Session) OnEnd(f func())

OnEnd registers a function to run when the session ends.

func (*Session) Picker

func (s *Session) Picker() *Picker

Picker is the picker the provider fills.

func (*Session) Post

func (s *Session) Post(f func())

Post runs f on the UI thread, if the session is still on; a goroutine hands its results over with it.

func (*Session) Prefix

func (s *Session) Prefix() string

Prefix is the prefix of the provider.

func (*Session) Show

func (s *Session) Show(value string, opts ShowOptions)

Show opens the quick input again with another value, as the help does when a mode is chosen.

type ShowOptions

type ShowOptions struct {
	// PreserveValue takes the value as it is, instead of selecting what follows the prefix and
	// restoring the last input of a provider.
	PreserveValue bool
	// QuickNavigate opens the picker the way Ctrl+Tab does: it is a switcher that the keyboard drives while
	// the keys that opened it are held. The input is hidden, the second item is active (the first, when
	// Activation says so), and the active item is chosen when the held modifier key is released.
	QuickNavigate *QuickNavigate
	// Activation says which item is active when the items are set. In the quick navigate mode it is the
	// second item unless it says otherwise.
	Activation ItemActivation
	// OnFile, when it is set, is given the file that is chosen in the file mode of this session, in the place of
	// opening it: "Compare Active File With..." asks for a file this way. It is called on the UI thread, once the
	// picker is closed, as FilesOptions.Open is.
	OnFile func(FileOpen)
}

ShowOptions are the options of Controller.Show.

type TriggerAction

type TriggerAction int

TriggerAction says what happens after an item's button was triggered (VS Code's TriggerAction).

const (
	// TriggerNone does nothing.
	TriggerNone TriggerAction = iota
	// TriggerClose hides the picker.
	TriggerClose
	// TriggerRefresh asks the provider for the items again.
	TriggerRefresh
	// TriggerRemove takes the item out of the list.
	TriggerRemove
)

The things that can happen after a button was triggered.

type ViewsOptions

type ViewsOptions struct {
	// Views holds the view containers and the views in them.
	Views *command.ViewRegistry
	// Context gives the context keys the `when` of the views is evaluated in.
	Context func() contextkey.Context
	// OpenContainer shows a view container of the side bar or of the panel and gives it the focus.
	OpenContainer func(id string)
	// OpenView shows a view, and its container, and gives it the focus.
	OpenView func(id string)
	// Channels lists the names of the output channels, which the mode lists as views of the Output;
	// nil lists none.
	Channels func() []string
	// OpenChannel shows an output channel.
	OpenChannel func(name string)
}

ViewsOptions are what the provider of the views mode needs.

Jump to

Keyboard shortcuts

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