settings

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 18 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 settings holds the settings registry, its layers and change events (SPEC §11.1).

Index

Constants

View Source
const (
	// ModifiedFilter is the filter of the settings the file of the tab sets.
	ModifiedFilter = "@modified"
	// IDFilter is the prefix of the filter of exact setting ids.
	IDFilter = "@id:"
	// LanguageFilter is the prefix of the filter of the settings of a language.
	LanguageFilter = "@lang:"
	// ExtensionFilter is the prefix of the filter of the row of an extension (step 31.1).
	ExtensionFilter = "@ext:"
)

The search filters VS Code's settings editor knows. Emetos has @modified, @id:, @lang: and @ext:; the others are read and reported as not supported.

View Source
const (
	// MinZoomLevel is the lowest zoom level of a window.
	MinZoomLevel = -8.0
	// MaxZoomLevel is the highest zoom level of a window.
	MaxZoomLevel = 8.0
	// ZoomFactorPerLevel is how much larger a window is for each zoom level above 0 (Electron's rule:
	// the scale is 1.2 to the power of the level).
	ZoomFactorPerLevel = 1.2
)

The range of window.zoomLevel and the size of a step of the zoom commands (SPEC §10.9).

Ported from VS Code: src/vs/workbench/electron-browser/actions/windowActions.ts, src/vs/platform/window/electron-browser/window.ts (MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL) and src/vs/platform/window/common/window.ts (zoomLevelToZoomFactor)

View Source
const CommonlyUsedID = "commonlyUsed"

CommonlyUsedID is the id of the group of the settings most people change.

View Source
const DefaultWindowTitle = "${dirty}${activeEditorShort}${separator}${rootName}${separator}${profileName}${separator}${appName}"

DefaultWindowTitle is the default of window.title on Linux: VS Code's template, which the title of the window is made from (SPEC §10.1).

Ported from VS Code: src/vs/workbench/browser/parts/titlebar/windowTitle.ts (defaultWindowTitle)

View Source
const DefaultWindowTitleSeparator = " - "

DefaultWindowTitleSeparator is the default of window.titleSeparator on Linux.

View Source
const DisabledExtensionsKey = "extensions.disabled"

DisabledExtensionsKey is the setting that lists the extensions the user turned off.

View Source
const ExtensionRowPrefix = ExtensionFilter

ExtensionRowPrefix starts the key of the Row of an extension, "@ext:emetos.git": the key is no setting's, and it is also the search that finds the row (Copy Setting ID gives it).

View Source
const InstalledExtensionsID = extensionsID + "/installed"

InstalledExtensionsID is the id of the group of the extension rows, the first group under Extensions.

Variables

View Source
var SuggestKinds = []struct {
	Name  string
	Kinds []int
}{
	{"Methods", []int{2}}, {"Functions", []int{3}}, {"Constructors", []int{4}}, {"Fields", []int{5}}, {"Variables", []int{6}},
	{"Classes", []int{7}}, {"Structs", []int{22}}, {"Interfaces", []int{8}}, {"Modules", []int{9}}, {"Properties", []int{10}},
	{"Events", []int{23}}, {"Operators", []int{24}}, {"Units", []int{11}}, {"Values", []int{12}}, {"Constants", []int{21}},
	{"Enums", []int{13}}, {"EnumMembers", []int{20}}, {"Keywords", []int{14}}, {"Words", []int{1}}, {"Colors", []int{16}},
	{"Files", []int{17}}, {"References", []int{18}}, {"Folders", []int{19}}, {"TypeParameters", []int{25}}, {"Snippets", []int{15}},
}

SuggestKinds are the kinds of completion items that editor.suggest.show<Kind> turns off: the setting key suffix, in the order of VS Code's list, and the LSP kind numbers it covers.

Functions

func ClampZoomLevel

func ClampZoomLevel(level float64) float64

ClampZoomLevel keeps a zoom level in the range from MinZoomLevel to MaxZoomLevel; NaN is 0.

func DefaultSettingsJSON

func DefaultSettingsJSON(reg *Registry) string

DefaultSettingsJSON is the text of the default settings document ("Open Default Settings (JSON)", SPEC §11.1): a JSONC object with every registered setting once, grouped by the groups of the settings editor in their order (the Commonly Used group, which only repeats settings, is left out), each preceded by its description as `//` comments wrapped at 80 columns, the values it allows, its range and its deprecation message, and followed by its default value. Lines are separated by "\n" and indented with a tab, as VS Code's.

func DetectIndentation

func DetectIndentation(text string) (tabSize int, insertSpaces, ok bool)

DetectIndentation finds how a text is indented from its first indented line (see the indentation a settings file keeps when the store edits it): with tabs, or with that many spaces; ok is false when no line is indented or the indentation mixes both.

func ExtensionOfRowKey added in v1.3.0

func ExtensionOfRowKey(key string) (string, bool)

ExtensionOfRowKey is the id of the extension of a row key, and whether the key is the row of an extension.

func Float

func Float(v float64) *float64

Float returns a pointer to v, for Minimum and Maximum.

func Get

func Get[T any](s *Store, key, languageID string) T

Get returns the value of a setting for a language ("" for none): a language block of the workspace or the user's file wins over the plain settings of both files, and the workspace wins over the user, which wins over the defaults. A value that the setting does not allow gives the default. T must be able to hold the setting's value (an int for a number, a []string for an array of strings); a key that is not registered, or a T that cannot hold the value, panics in debug builds and gives the zero value in release builds.

func IsOverrideKey

func IsOverrideKey(key string) bool

IsOverrideKey tells whether a key names a language block, such as "[go]".

func KeyToDisplayFormat

func KeyToDisplayFormat(key, groupID string) (category, label string)

KeyToDisplayFormat is the category and the label a setting is shown with: the key up to the last dot, and what follows it, both written as words. groupID is the id of the group the setting is shown in ("editor/font"); the part of the category that the group already says is left out, so "editor.fontSize" in the Font group is just "Font Size", and "Editor: Font Size" anywhere else (groupID empty).

func OverrideIdentifiers

func OverrideIdentifiers(key string) []string

OverrideIdentifiers returns the language ids in the key of a block, without repeats: "[x][y][x]" gives x and y. A key that is no block gives none.

Ported from VS Code: src/vs/platform/configuration/common/configurationRegistry.ts (overrideIdentifiersFromKey).

func OverrideKey

func OverrideKey(ids ...string) string

OverrideKey makes the key of a block for language ids: "[go]" or "[go]json".

func RenderDescription

func RenderDescription(markdown string) [][]Span

RenderDescription breaks the Markdown of a description into lines of spans: backtick code spans, [label](target) links and #setting.key# references (links to "#setting.key") are marked and their syntax removed, emphasis marks are dropped. It is the part of Markdown the descriptions of the settings use.

func SetExtensionEnabled added in v1.3.0

func SetExtensionEnabled(ctx context.Context, store *Store, id string, enable bool) error

SetExtensionEnabled turns an extension on or off by writing extensions.disabled in the user's file: the id is taken out of the list or added to it, the list is kept sorted, and an empty list removes the setting. The Extensions page and the rows of the settings editor both write through it, so they always agree.

func Title

func Title(category, label string) string

Title is "Category: Label", or the label alone while the category is empty.

func UserSettingsPath

func UserSettingsPath(paths storage.Paths, profile string) (string, error)

UserSettingsPath is the settings.json of a profile (SPEC §10.12).

func WordifyKey

func WordifyKey(key string) string

WordifyKey writes a part of a setting key as words: dots become " › ", camel case is split, the first letter and known acronyms are capitalized ("editor.fontSize" gives "Editor › Font Size").

func WorkspaceSettingsPath

func WorkspaceSettingsPath(folder string) string

WorkspaceSettingsPath is <folder>/.emetos/settings.json. Emetos reads no other folder's settings (SPEC decision D12).

func ZoomFactor

func ZoomFactor(level float64) float64

ZoomFactor is the scale of a window at a zoom level: 1.2 to the power of the level, so that level 0 is 1, level 1 is 120% and level -1 is about 83%. A level that is not a number is level 0; a level outside the range is clamped to it (ClampZoomLevel).

func ZoomStep

func ZoomStep(level float64, in bool) (next float64, ok bool)

ZoomStep is the level the zoom commands go to from a level: one more (in) or one less (out) than the level rounded to a whole number, as VS Code's actions round the level so that no fractional level is made. ok is false when the new level is outside the range, where the commands do nothing.

Types

type Category

type Category struct {
	// ID is the id of the group ("editor/font"); it is unique in a tree.
	ID string
	// Label is the text of the group.
	Label string
	// Level is how deep the group is: 1 for a top level group, 2 for a child. The header of the group
	// is the larger the lower the level.
	Level int
	// Keys are the keys of the settings of the group itself (not of its children), in display order.
	Keys []string
	// Children are the groups below.
	Children []*Category
	// Extensions are the ids of the extensions whose rows the group shows before its settings (only the group
	// Extensions > Installed has them, step 31.1).
	Extensions []string
}

Category is a group of the settings editor with the settings it holds, in display order.

func BuildCategories

func BuildCategories(toc []TOCEntry, settings []Setting) []*Category

BuildCategories places settings (the keys, with the setting each is) in the groups of toc, the way VS Code does: each group claims, after the groups below it have claimed theirs, the settings that match its patterns and that no group has taken, sorted by key. The groups left without settings and without groups are dropped. The settings no group claims are put in the group "Extensions", one child group per first key segment. The Commonly Used group comes first and takes copies of its settings.

func (*Category) Count

func (c *Category) Count() int

Count is the number of settings and extension rows in the group and below it.

func (*Category) Find

func (c *Category) Find(id string) *Category

Find returns the group with the id, in this one or below it.

func (*Category) Walk

func (c *Category) Walk(fn func(*Category))

Walk calls fn for the group and each group below it, in display order.

type ChangeEvent

type ChangeEvent struct {
	// Targets are the files whose settings changed.
	Targets []Target
	// Keys are the dotted keys whose value changed, in no language, sorted.
	Keys []string
	// Languages are, for each language that has blocks of its own, the keys whose value
	// changed for that language.
	Languages map[string][]string
}

ChangeEvent tells which settings a reload or an update changed.

func (ChangeEvent) Affects

func (e ChangeEvent) Affects(section, languageID string) bool

Affects tells whether the change touches a section, such as "editor" or "editor.tabSize": the section is a changed key, or contains one, or is inside one (a changed "files.exclude" affects "files.exclude.node_modules"). With a language it looks at the value for that language; with "" at the value in any language.

Ported from VS Code: src/vs/platform/configuration/common/configurationModels.ts (ConfigurationChangeEvent.affectsConfiguration).

func (ChangeEvent) IsEmpty

func (e ChangeEvent) IsEmpty() bool

IsEmpty tells whether nothing changed.

type Choice

type Choice struct {
	// Value is the JSON value to write.
	Value any
	// Label is what the list shows: the value as text.
	Label string
	// Description is the text of the choice (EnumDescriptions), or empty.
	Description string
}

Choice is a value of an enum setting.

type ExtensionInfo added in v1.3.0

type ExtensionInfo struct {
	// ID is the id of the extension ("emetos.git").
	ID string
	// Name is its name ("Git").
	Name string
	// Description is what it does, in one sentence.
	Description string
}

ExtensionInfo is an extension as the settings editor lists it.

type ExtensionRow added in v1.3.0

type ExtensionRow struct {
	ExtensionInfo
	// Enabled is false while the id is in extensions.disabled. A disabled extension's row is modified.
	Enabled bool
}

ExtensionRow is the row of an extension: the extension, and whether it is on.

type Inspected

type Inspected struct {
	// Default, User and Workspace are the values of the layers without language blocks.
	Default, User, Workspace Optional
	// DefaultLanguage, UserLanguage and WorkspaceLanguage are the values of the language
	// blocks of the language asked about.
	DefaultLanguage, UserLanguage, WorkspaceLanguage Optional
	// Effective is the value Get returns, and Source the layer it comes from.
	Effective Optional
	Source    Source
	// WorkspaceIgnored is true when the workspace file sets the setting but its scope does
	// not allow it, so the value does not count.
	WorkspaceIgnored bool
}

Inspected is where the value of a setting comes from, for the settings UI.

type Inspection

type Inspection struct {
	// Value is the value of the model without the language blocks.
	Value Optional
	// Override is the value the blocks for the language give, when a language was asked about.
	Override Optional
	// Merged is the value for the language, the blocks over the rest.
	Merged Optional
	// Overrides are the values of all the blocks that set the section.
	Overrides []OverrideValue
}

Inspection says where a value comes from.

type LanguageResolver

type LanguageResolver func(name string) (id, display string, ok bool)

LanguageResolver finds a language by what the user wrote after @lang: (its id or its name, whatever the case): the id, the name to show, and whether there is such a language.

type Model

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

Model is the settings of one file (or of several merged), as a tree of values with the language blocks apart. Values are what the JSON parser gives: nil, bool, float64, string, []any and map[string]any. A Model is read by many goroutines; SetValue, AddValue and RemoveValue change it and must not run at the same time as anything else.

Ported from VS Code: src/vs/platform/configuration/common/configurationModels.ts (ConfigurationModel).

func NewModel

func NewModel(contents map[string]any, keys []string, overrides []Override) *Model

NewModel makes a model of a tree of values, the keys as they were written and the language blocks. The model owns the arguments.

func (*Model) AddValue

func (m *Model) AddValue(key string, value any)

AddValue sets a dotted key and puts it at the end of the keys, even if it is there.

func (*Model) Contents

func (m *Model) Contents() map[string]any

Contents is the tree of values. Do not change it.

func (*Model) GetOverrideValue

func (m *Model) GetOverrideValue(section, languageID string) (any, bool)

GetOverrideValue returns the value the blocks for a language give a section.

func (*Model) GetValue

func (m *Model) GetValue(section string) (any, bool)

GetValue returns the value of a dotted section, or false when there is none. An empty section is the whole tree.

func (*Model) Inspect

func (m *Model) Inspect(section, languageID string) Inspection

Inspect looks at a section: its value, its value in the language blocks of the language (when not empty), and in every block. It looks at the unfiltered settings when the model was parsed with some left out.

func (*Model) IsEmpty

func (m *Model) IsEmpty() bool

IsEmpty tells whether the model has no settings at all.

func (*Model) Keys

func (m *Model) Keys() []string

Keys are the names of the settings as they were written, in order.

func (*Model) KeysForOverride

func (m *Model) KeysForOverride(languageID string) []string

KeysForOverride returns the names written in the blocks that include the language.

func (*Model) Merge

func (m *Model) Merge(others ...*Model) *Model

Merge returns a model with the settings of the others over its own, values of objects merged one by one. The language blocks with the same ids are merged too.

func (*Model) Override

func (m *Model) Override(languageID string) *Model

Override returns the model for a language: the settings with the blocks of the language over them. A language without blocks gets the model itself.

func (*Model) OverrideIdentifiers

func (m *Model) OverrideIdentifiers() []string

OverrideIdentifiers returns the language ids of all the blocks, without repeats.

func (*Model) Overrides

func (m *Model) Overrides() []Override

Overrides are the language blocks.

func (*Model) RemoveValue

func (m *Model) RemoveValue(key string)

RemoveValue removes a dotted key; nothing happens when it is not one of the keys.

func (*Model) SetValue

func (m *Model) SetValue(key string, value any)

SetValue sets a dotted key, keeping its place among the keys when it is there already.

type Optional

type Optional struct {
	Value any
	Ok    bool
}

Optional is a value that may be absent: nil is a value (JSON null) when Ok is set.

type Override

type Override struct {
	// Identifiers are the language ids of the block.
	Identifiers []string
	// Keys are the names of the settings as they are written in the block.
	Keys []string
	// Contents are the settings as a tree, "editor.tabSize" being {"editor": {"tabSize": …}}.
	Contents map[string]any
}

Override is a language block of a settings file: the settings for the languages of Identifiers.

type OverrideValue

type OverrideValue struct {
	Identifiers []string
	Value       any
}

OverrideValue is the value a language block gives.

type ParseOptions

type ParseOptions struct {
	// SkipUnregistered leaves out the settings that are not registered.
	SkipUnregistered bool
	// Scopes, when not nil, leaves out the settings whose scope is not in the list.
	Scopes []Scope
	// Include keeps the listed keys whatever their scope; Exclude drops them, and wins.
	Include, Exclude []string
}

ParseOptions leave settings out when a file is parsed.

type ParseResult

type ParseResult struct {
	// Model has the settings that were kept.
	Model *Model
	// Errors are the syntax errors; the parser goes on after them.
	Errors []jsonc.ParseError
	// Conflicts say which keys were ignored because another key made their place a
	// value that is not an object ("a.b" after "a": 1).
	Conflicts []string
	// NotObject is true when the file holds a value that is not an object.
	NotObject bool
}

ParseResult is a parsed settings file.

type Problem

type Problem struct {
	Target  Target
	Kind    ProblemKind
	Key     string
	Message string
	// Offset and Length are set for ProblemSyntax.
	Offset, Length int
}

Problem is something wrong in a settings file, for the UI to show.

type ProblemKind

type ProblemKind int

ProblemKind says what is wrong with a setting in a file.

const (
	// ProblemSyntax is a syntax error of the file; Offset and Length say where.
	ProblemSyntax ProblemKind = iota + 1
	// ProblemNotObject is a file that holds something else than an object.
	ProblemNotObject
	// ProblemConflict is a key ignored because another one made its place a value that is
	// not an object.
	ProblemConflict
	// ProblemUnknownKey is a key that is not registered. It is kept in the file.
	ProblemUnknownKey
	// ProblemInvalidValue is a value the setting does not allow; the default is used.
	ProblemInvalidValue
	// ProblemNotInWorkspace is a setting a workspace cannot set; it is ignored.
	ProblemNotInWorkspace
)

type Query

type Query struct {
	// Text is what is left of the search once the filters are taken out, cleaned of quotes and colons.
	Text string
	// Words are the words of Text, in lower case.
	Words []string
	// Modified is true for @modified: only the settings the file of the tab sets.
	Modified bool
	// IDs are the ids of @id:, a comma separated list; an id ending in "*" is a prefix.
	IDs []string
	// Language is the value of the first @lang:, as it was written ("go", "Go"), or empty.
	Language string
	// Extensions are the ids of @ext:, a comma separated list: only the rows of those extensions are shown (the
	// settings do not record the extension that registered them, so none is shown with it).
	Extensions []string
	// Unsupported are the filters that VS Code has and Emetos has not (@tag:, @feature:, @hasPolicy, @stable), as
	// they were written; they are ignored.
	Unsupported []string
}

Query is a search text taken apart (VS Code's parseQuery): the filters and the free words.

func ParseQuery

func ParseQuery(text string) Query

ParseQuery takes the filters out of the text of the search box: @modified, @id:a,b, @lang:go, and the filters that are not supported. The value of a filter is a word, or text between quotes.

func (Query) Empty

func (q Query) Empty() bool

Empty tells that the query has no filter and no word: the editor then shows all the settings.

type Registry

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

Registry holds the settings, with their defaults (SPEC §11.1). It is safe for concurrent use.

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry makes a registry with the settings Emetos has. Each step that reads a setting adds it here (or to a function it calls) with the values of VS Code.

func NewRegistry

func NewRegistry() *Registry

NewRegistry makes an empty registry; DefaultRegistry makes one with the settings Emetos has.

func (*Registry) All

func (r *Registry) All() []Setting

All returns the settings in the order they were registered.

func (*Registry) Categories

func (r *Registry) Categories() []string

Categories returns the categories of the settings, sorted.

func (*Registry) Lookup

func (r *Registry) Lookup(key string) (Setting, bool)

Lookup returns the setting with the key.

func (*Registry) MustRegister

func (r *Registry) MustRegister(settings ...Setting)

MustRegister is Register for settings written in the code: it panics on an error.

func (*Registry) ParseMap

func (r *Registry) ParseMap(values map[string]any, opts ParseOptions) ParseResult

ParseMap makes a model of settings given as a map, as ParseModel does of a file.

func (*Registry) ParseModel

func (r *Registry) ParseModel(text string, opts ParseOptions) ParseResult

ParseModel parses the text of a settings file. A text with nothing in it gives an empty model.

Ported from VS Code: src/vs/platform/configuration/common/configurationModels.ts (ConfigurationModelParser).

func (*Registry) Register

func (r *Registry) Register(s Setting) error

Register adds a setting. It fails with the tags SettingKeyInvalid (an empty key, a key with an empty segment or one that looks like a language block), SettingDuplicate, SettingTypeMissing and SettingDefaultInvalid (the default does not satisfy the setting's own types, enum and range).

func (*Registry) RegisterLanguageDefaults

func (r *Registry) RegisterLanguageDefaults(languageID string, values map[string]any) error

RegisterLanguageDefaults sets the defaults a language has for settings (what a language contributes with configurationDefaults, such as "editor.insertSpaces": false for Go). Calling it again for a language merges the values, the later winning.

func (*Registry) Unregister added in v1.0.0

func (r *Registry) Unregister(key string) bool

Unregister removes a setting and reports whether it was registered. It is how the settings of an extension go when the extension is deactivated (SPEC §10.15); the settings of the editor are never removed. A value the user wrote for the key stays in their file.

func (*Registry) UnregisterLanguageDefaults added in v1.0.0

func (r *Registry) UnregisterLanguageDefaults(languageID string, keys []string) bool

UnregisterLanguageDefaults takes back the defaults that RegisterLanguageDefaults gave a language for the keys, and reports whether there was anything to take. It is how the defaults of a language pack go when the pack is turned off (SPEC §10.15). A value the user wrote stays in their file. A language with no default left is forgotten.

func (*Registry) Validate

func (r *Registry) Validate(key string, value any) string

Validate tells whether value is allowed for the setting with the key; the message says why not, and is empty for a valid value. A key that is not registered has no rules.

func (*Registry) Version

func (r *Registry) Version() int

Version changes whenever something is registered.

type Row

type Row struct {
	// Key is the setting's key.
	Key string
	// Category and Label are the title of the setting in two parts ("Editor", "Font Size"); the category
	// is empty where the group of the setting says it already.
	Category, Label string
	// Description is the Markdown text of the setting.
	Description string
	// Kind is how the setting is edited.
	Kind RowKind
	// Value is the value shown: the value in the file of the target when it sets the setting, else the default.
	Value any
	// Default is the default of the setting.
	Default any
	// Modified is true when the file of the target sets the setting (VS Code's "isConfigured"): the row
	// gets the modified mark and "Reset Setting".
	Modified bool
	// AlsoModifiedIn names the other files that set the setting ("User", "Workspace").
	AlsoModifiedIn []string
	// Choices are the values of an enum.
	Choices []Choice
	// Minimum and Maximum bound a number.
	Minimum, Maximum *float64
	// Deprecated is the message of a deprecated setting.
	Deprecated string
	// Invalid is a message when the value in the file is not allowed by the setting (the editor shows the default).
	Invalid string
	// Language is the language id of a row that shows the language block of a file ("go" for "[go]": {...}), or
	// empty for the plain settings.
	Language string
	// contains filtered or unexported fields
}

Row is one setting as the settings editor shows it for a target (a tab): the texts, how to edit it, the value it shows and whether the file of the tab sets it.

func (Row) Checked

func (r Row) Checked() bool

Checked is the value of a boolean row.

func (Row) ChoiceIndex

func (r Row) ChoiceIndex() int

ChoiceIndex is the index of the choice that is the value of an enum row, or -1.

func (Row) Parse

func (r Row) Parse(text string) (value any, message string)

Parse turns the text of an input box into the value to write, or says why it is not allowed (the message VS Code shows under the box). Only the kinds of the input boxes (numbers and strings) parse text.

func (Row) Setting

func (r Row) Setting() Setting

Setting is the registered setting of the row.

func (Row) Title

func (r Row) Title() string

Title is "Category: Label".

func (Row) ValueText

func (r Row) ValueText() string

ValueText is the value of a number or a string as the text of its input box.

type RowKind

type RowKind int

RowKind is how the settings editor edits a setting.

const (
	// KindBool is a check box.
	KindBool RowKind = iota + 1
	// KindNumber is a box for a number.
	KindNumber
	// KindInteger is a box for a whole number.
	KindInteger
	// KindString is a box for a text.
	KindString
	// KindEnum is a list of the values the setting allows.
	KindEnum
	// KindComplex is a value the editor does not edit itself (an array, an object, a value of several
	// types): it links to the JSON file.
	KindComplex
)

type Scope

type Scope int

Scope says where a setting can be set and whether a language can override it (VS Code's ConfigurationScope).

const (
	// ScopeWindow is the default: a setting for the window, from the user and the workspace.
	ScopeWindow Scope = iota
	// ScopeApplication is a setting of the user only: a workspace cannot set it.
	ScopeApplication
	// ScopeMachine is a setting of the machine: a workspace cannot set it.
	ScopeMachine
	// ScopeResource is a setting that can differ per file, from the user and the workspace.
	ScopeResource
	// ScopeLanguageOverridable is a resource setting that a [language] block can set (the
	// settings UI lists it for each language).
	ScopeLanguageOverridable
)

type SearchResult

type SearchResult struct {
	// Query is the parsed text.
	Query Query
	// Active is true when the text has a filter or a word: the editor then shows a list of results (and not the
	// Commonly Used group, which only repeats settings).
	Active bool
	// Categories are the groups with the settings found, in the order of the layout; inside a group the
	// settings are in the order of their relevance (layout order among equals).
	Categories []*Category
	// Count is the number of settings found.
	Count int
	// Language and LanguageName are the id and the name of the language of @lang:, empty without that filter or
	// with a language that does not exist.
	Language, LanguageName string
	// Hints say what part of the text was ignored or found nothing, such as an unsupported filter.
	Hints []string
}

SearchResult is what the settings editor shows for a search text.

func (SearchResult) Summary

func (r SearchResult) Summary() string

Summary is the line under the search box: "No Settings Found", "1 Setting Found" or "N Settings Found".

type Setting

type Setting struct {
	// Key is the dotted name, such as "editor.tabSize".
	Key string
	// Types are the JSON types the value may have; the first is the main one.
	Types []Type
	// Default is the value when nothing sets it. It is a Go value that encoding/json
	// writes as a value of Types (an int is fine; it is stored as a float64).
	Default any
	// Description tells what the setting does (Markdown may be used).
	Description string
	// Enum lists the only values allowed, when it is not empty.
	Enum []any
	// EnumDescriptions describe the values of Enum, in the same order.
	EnumDescriptions []string
	// Minimum and Maximum bound a number, when not nil.
	Minimum, Maximum *float64
	// ItemTypes are the types an element of an array may have, when not empty.
	ItemTypes []Type
	// ItemEnum lists the only values an element of an array may have, when not empty.
	ItemEnum []any
	// Scope is where the setting may be set.
	Scope Scope
	// Category is the group of the settings UI, such as "Text Editor".
	Category string
	// Deprecated is a message that says what to use instead; empty for a setting in use.
	Deprecated string
}

Setting describes one registered setting (SPEC §11.1).

type Source

type Source int

Source says which layer a value comes from.

const (
	// SourceDefault is the registry's default.
	SourceDefault Source = iota
	// SourceUser is the user's settings.json.
	SourceUser
	// SourceWorkspace is the workspace's settings.json.
	SourceWorkspace
)

type Span

type Span struct {
	Text string
	// Code marks text between backticks.
	Code bool
	// Link, when not empty, is the target of a Markdown link; Text is its label.
	Link string
}

Span is a piece of a description: plain text, a code span or a link.

type Store

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

Store holds the layers of settings (defaults, user, workspace) and answers for a language (SPEC §11.1). It is safe for concurrent use.

func NewStore

func NewStore(reg *Registry, opts StoreOptions) *Store

NewStore makes a store with the defaults of the registry and empty files; call Reload to read the files.

func (*Store) Inspect

func (s *Store) Inspect(key, languageID string) Inspected

Inspect says what each layer has for a setting.

func (*Store) Keys

func (s *Store) Keys(target Target) []string

Keys returns the dotted keys set in a file, sorted; the settings UI lists them.

func (*Store) OnChange

func (s *Store) OnChange(fn func(ChangeEvent)) (unsubscribe func())

OnChange registers fn to be called, in the goroutine that changed the settings, after every change. The returned function removes it.

func (*Store) Paths

func (s *Store) Paths() (user, workspace string)

Paths are the files of the user's and the workspace's settings; the workspace's is empty while no folder is open.

func (*Store) Problems

func (s *Store) Problems() []Problem

Problems lists what is wrong in the files read last, for the UI.

func (*Store) Registry

func (s *Store) Registry() *Registry

Registry returns the registry of the store.

func (*Store) Reload

func (s *Store) Reload(ctx context.Context) (ChangeEvent, error)

Reload reads both files again and tells the listeners what changed. A file that cannot be read keeps its old settings and the error is returned after the other one is applied. The file watcher calls it when a file changes (SPEC §10.5).

func (*Store) Remove

func (s *Store) Remove(ctx context.Context, key string, target Target) error

Remove removes a setting from a file, so the layers below show again.

func (*Store) RemoveForLanguage

func (s *Store) RemoveForLanguage(ctx context.Context, key, languageID string, target Target) error

RemoveForLanguage removes a setting from the block of a language.

func (*Store) Section added in v1.0.0

func (s *Store) Section(section string) (any, bool)

Section returns the value of a dotted section of the consolidated settings, whether or not a setting is registered under it, or false when there is none: "go.gopls" gives the object that "go.gopls": {...} and "go.gopls.ui.x": 1 make together, defaults under the user's and the workspace's values. It is how a language server is given the settings of a section it asks for (SPEC §9.12 "As built (step 12.3)"). The value is a copy the caller may keep. An empty section is the whole tree.

func (*Store) SetTextSource

func (s *Store) SetTextSource(src TextSource)

SetTextSource makes the store read and edit open documents through src; nil goes back to the files alone. It does not read the files again: call Reload for the layers to follow the documents that are open already.

func (*Store) SetUserPath

func (s *Store) SetUserPath(ctx context.Context, path string) (ChangeEvent, error)

SetUserPath moves the user layer to another settings.json, that of another profile (SPEC §10.12), and reads the files again: the listeners hear of the settings that change with it (the targets of the event include the user's settings when its keys differ), so a window that follows the settings takes the new profile's values in place. An empty path leaves the store with no user layer. The errors are those of Reload. The layer of the old file is dropped even when the new file cannot be read.

func (*Store) SetWorkspacePath

func (s *Store) SetWorkspacePath(ctx context.Context, path string) (ChangeEvent, error)

SetWorkspacePath moves the workspace layer to another settings.json, that of the folder a window opens (an empty path is no folder), and reads the files again: the listeners hear of the settings that change with it. The window calls it when its folder changes (SPEC §10.11); the errors are those of Reload. The layer of the old folder is dropped even when the new file cannot be read.

func (*Store) Update

func (s *Store) Update(ctx context.Context, key string, value any, target Target) error

Update sets a setting in a file, keeping the comments and the layout of the file, and creates the file and its folder when they do not exist. The store reloads and the listeners are told. It fails with the tags SettingUnregistered, SettingValueInvalid, SettingScopeInvalid, SettingsNoWorkspace and SettingsFileInvalid (the file has syntax errors, which an edit would make worse), and with those of core/fileio.

func (*Store) UpdateForLanguage

func (s *Store) UpdateForLanguage(ctx context.Context, key, languageID string, value any, target Target) error

UpdateForLanguage is Update inside the block of a language, "[go]": {…}.

type StoreOptions

type StoreOptions struct {
	// UserPath is the user's settings.json; empty means the store has no user layer.
	UserPath string
	// WorkspacePath is the workspace's settings.json; empty means no folder is open.
	WorkspacePath string
}

StoreOptions say where the files of a Store are.

type TOCEntry

type TOCEntry struct {
	// ID names the group, such as "editor/font"; it is VS Code's id.
	ID string
	// Label is the text of the group in the tree and as the header of its settings.
	Label string
	// Patterns are the key patterns of the settings of the group.
	Patterns []string
	// Children are the groups below.
	Children []TOCEntry
}

TOCEntry is a group of the table of contents of the settings editor: a label, the key patterns of the settings it holds (`*` matches anything, case does not matter) and the groups below it.

func DefaultTOC

func DefaultTOC() []TOCEntry

DefaultTOC is VS Code's table of contents for the groups Emetos can have settings in. The groups of VS Code that no setting of Emetos can belong to (Chat, Notebook, Debug and so on) are left out until a setting needs one.

type Target

type Target int

Target is a settings file that can be written.

const (
	// TargetUser is the user's settings.json of the profile.
	TargetUser Target = iota + 1
	// TargetWorkspace is <folder>/.emetos/settings.json.
	TargetWorkspace
)

func (Target) String

func (t Target) String() string

type TextSource

type TextSource interface {
	// OpenText gives the current text of the document that shows the file at path, and true while
	// one is open. The store calls it from any goroutine (a reload comes from the file watcher), so
	// an implementation keeps a copy of the text that it updates on the thread of the document.
	OpenText(path string) (text string, open bool)
	// EditText applies the edits to the document that shows the file at path; their offsets are in
	// the text OpenText gave. It saves the document when it was not dirty before the edit. It
	// returns false, and changes nothing, when no document is open for the path any more (the
	// store then writes the file). An error with true says that the document has the edit but could
	// not be saved. It is called on the thread that owns the documents.
	EditText(ctx context.Context, path string, edits []jsonc.Edit) (applied bool, err error)
}

TextSource lets a Store use a document that an editor has open in place of a settings file (SPEC §11.1 "Settings in an open editor"). The app implements it over the documents of the window; a Store without one reads and writes the files.

The rule is VS Code's (JSONEditingService.write): the store computes its edit against the text of the open document and the source applies it to the document, as one undo step. A document that was not dirty before the edit is saved at once, so the editor and the disk agree; a dirty document stays dirty and the disk is left alone until the user saves. The store reads the text of an open document, not the file, as the layer of its settings.

type Type

type Type string

Type is a JSON type a setting's value can have.

const (
	// String is a JSON string.
	String Type = "string"
	// Number is any JSON number.
	Number Type = "number"
	// Integer is a JSON number without a fraction.
	Integer Type = "integer"
	// Boolean is true or false.
	Boolean Type = "boolean"
	// Array is a JSON array.
	Array Type = "array"
	// Object is a JSON object.
	Object Type = "object"
	// Null is null.
	Null Type = "null"
)

The JSON types.

type UIModel

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

UIModel is what the settings editor shows (SPEC §11.1): the groups of the registered settings, the rows of a target and the edits. It holds no state of its own besides the groups, which it builds again when something is registered.

func NewUIModel

func NewUIModel(store *Store) *UIModel

NewUIModel makes the UI model of the settings editor over a store, with the table of contents of VS Code (DefaultTOC).

func (*UIModel) Categories

func (m *UIModel) Categories(target Target, match func(Row) bool) []*Category

Categories are the groups of the settings a target shows, in order: for the workspace only the settings a workspace may set (VS Code hides the application and machine settings there). Empty groups are not in it. match, when not nil, keeps the settings it accepts (the search).

func (*UIModel) ExtensionRow added in v1.3.0

func (m *UIModel) ExtensionRow(id string) (ExtensionRow, bool)

ExtensionRow is the row of an extension of SetExtensions; false for an id the model does not list.

func (*UIModel) ExtensionSettingRow added in v1.3.0

func (m *UIModel) ExtensionSettingRow(id string) (Row, bool)

ExtensionSettingRow is the row of an extension as a check box: the name as the category, "Enabled" as the label, the description with the id, checked while the extension is on and modified while it is off. It reports false for an id the model does not list.

func (*UIModel) Reset

func (m *UIModel) Reset(ctx context.Context, key string, target Target) error

Reset removes the setting from the file of the target ("Reset Setting"): the layers below show again.

func (*UIModel) ResetFor

func (m *UIModel) ResetFor(ctx context.Context, key string, target Target, language string) error

ResetFor is Reset inside the block of a language when language is not empty: the key leaves the block, and the block goes when it has no other setting. The row of an extension is reset by turning the extension on.

func (*UIModel) Row

func (m *UIModel) Row(key string, target Target, groupID string) (Row, bool)

Row describes a setting for a target, in the group the setting is shown in (the group says which part of the title is left out; "" is none). It reports false for a key that is not registered.

func (*UIModel) RowFor

func (m *UIModel) RowFor(key string, target Target, language, groupID string) (Row, bool)

RowFor is Row for the language block of a language ("@lang:go"): the value shown is the one the "[go]" block of the file of the target sets, else the one the defaults give the language, else the default; the row is modified when the block of that file sets the setting. A language "" is Row.

func (*UIModel) Search

func (m *UIModel) Search(target Target, text string, resolve LanguageResolver) SearchResult

Search finds the settings of a target for the text of the search box (SPEC §11.1).

The filters narrow the settings: @modified keeps those that the file of the target sets (inside the block of the language with @lang:), @id: those with an id in its list, and @lang: the settings a language can set (ScopeLanguageOverridable), shown with the value of the block of that language; a language that does not exist finds nothing. The words must all be found in a setting: in its key (written as words, so "font size" finds editor.fontSize, and whole, without dots or case), in its title, in the values of an enum or in its description. A setting is scored by its words (a key or title match 3, a whole word of the key 4, a value 2, a whole word of the description 2, a part of it 1) and the key typed whole scores 1000. The groups keep the order of the layout and the settings inside a group the order of their scores (the layout order among equal ones); VS Code lists the results flat in the order of its match types, which a list with headers cannot show.

func (*UIModel) SetExtensions added in v1.3.0

func (m *UIModel) SetExtensions(list []ExtensionInfo)

SetExtensions gives the model the extensions to list, in the order to list them (the order of the Extensions page).

func (*UIModel) SetText

func (m *UIModel) SetText(ctx context.Context, key string, target Target, text string) error

SetText parses the text of an input box and writes the value; a text the setting does not allow fails with the tag SettingInputInvalid, whose message is the one to show, and writes nothing.

func (*UIModel) SetTextFor

func (m *UIModel) SetTextFor(ctx context.Context, key string, target Target, language, text string) error

SetTextFor is SetText inside the block of a language when language is not empty.

func (*UIModel) SetValue

func (m *UIModel) SetValue(ctx context.Context, key string, target Target, value any) error

SetValue writes a value of a setting in the file of the target. It fails with the tags of Store.Update.

func (*UIModel) SetValueFor

func (m *UIModel) SetValueFor(ctx context.Context, key string, target Target, language string, value any) error

SetValueFor is SetValue inside the block of a language ("[go]": {...}) when language is not empty. The key of the row of an extension (ExtensionSettingRow) turns the extension on (true) or off (false) through SetExtensionEnabled, whatever the target: the choice is the user's.

func (*UIModel) Store

func (m *UIModel) Store() *Store

Store is the store the model edits.

Jump to

Keyboard shortcuts

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