Documentation
¶
Overview ¶
Package settings holds the settings registry, its layers and change events (SPEC §11.1).
Index ¶
- Constants
- Variables
- func ClampZoomLevel(level float64) float64
- func DefaultSettingsJSON(reg *Registry) string
- func DetectIndentation(text string) (tabSize int, insertSpaces, ok bool)
- func ExtensionOfRowKey(key string) (string, bool)
- func Float(v float64) *float64
- func Get[T any](s *Store, key, languageID string) T
- func IsOverrideKey(key string) bool
- func KeyToDisplayFormat(key, groupID string) (category, label string)
- func OverrideIdentifiers(key string) []string
- func OverrideKey(ids ...string) string
- func RenderDescription(markdown string) [][]Span
- func SetExtensionEnabled(ctx context.Context, store *Store, id string, enable bool) error
- func Title(category, label string) string
- func UserSettingsPath(paths storage.Paths, profile string) (string, error)
- func WordifyKey(key string) string
- func WorkspaceSettingsPath(folder string) string
- func ZoomFactor(level float64) float64
- func ZoomStep(level float64, in bool) (next float64, ok bool)
- type Category
- type ChangeEvent
- type Choice
- type ExtensionInfo
- type ExtensionRow
- type Inspected
- type Inspection
- type LanguageResolver
- type Model
- func (m *Model) AddValue(key string, value any)
- func (m *Model) Contents() map[string]any
- func (m *Model) GetOverrideValue(section, languageID string) (any, bool)
- func (m *Model) GetValue(section string) (any, bool)
- func (m *Model) Inspect(section, languageID string) Inspection
- func (m *Model) IsEmpty() bool
- func (m *Model) Keys() []string
- func (m *Model) KeysForOverride(languageID string) []string
- func (m *Model) Merge(others ...*Model) *Model
- func (m *Model) Override(languageID string) *Model
- func (m *Model) OverrideIdentifiers() []string
- func (m *Model) Overrides() []Override
- func (m *Model) RemoveValue(key string)
- func (m *Model) SetValue(key string, value any)
- type Optional
- type Override
- type OverrideValue
- type ParseOptions
- type ParseResult
- type Problem
- type ProblemKind
- type Query
- type Registry
- func (r *Registry) All() []Setting
- func (r *Registry) Categories() []string
- func (r *Registry) Lookup(key string) (Setting, bool)
- func (r *Registry) MustRegister(settings ...Setting)
- func (r *Registry) ParseMap(values map[string]any, opts ParseOptions) ParseResult
- func (r *Registry) ParseModel(text string, opts ParseOptions) ParseResult
- func (r *Registry) Register(s Setting) error
- func (r *Registry) RegisterLanguageDefaults(languageID string, values map[string]any) error
- func (r *Registry) Unregister(key string) bool
- func (r *Registry) UnregisterLanguageDefaults(languageID string, keys []string) bool
- func (r *Registry) Validate(key string, value any) string
- func (r *Registry) Version() int
- type Row
- type RowKind
- type Scope
- type SearchResult
- type Setting
- type Source
- type Span
- type Store
- func (s *Store) Inspect(key, languageID string) Inspected
- func (s *Store) Keys(target Target) []string
- func (s *Store) OnChange(fn func(ChangeEvent)) (unsubscribe func())
- func (s *Store) Paths() (user, workspace string)
- func (s *Store) Problems() []Problem
- func (s *Store) Registry() *Registry
- func (s *Store) Reload(ctx context.Context) (ChangeEvent, error)
- func (s *Store) Remove(ctx context.Context, key string, target Target) error
- func (s *Store) RemoveForLanguage(ctx context.Context, key, languageID string, target Target) error
- func (s *Store) Section(section string) (any, bool)
- func (s *Store) SetTextSource(src TextSource)
- func (s *Store) SetUserPath(ctx context.Context, path string) (ChangeEvent, error)
- func (s *Store) SetWorkspacePath(ctx context.Context, path string) (ChangeEvent, error)
- func (s *Store) Update(ctx context.Context, key string, value any, target Target) error
- func (s *Store) UpdateForLanguage(ctx context.Context, key, languageID string, value any, target Target) error
- type StoreOptions
- type TOCEntry
- type Target
- type TextSource
- type Type
- type UIModel
- func (m *UIModel) Categories(target Target, match func(Row) bool) []*Category
- func (m *UIModel) ExtensionRow(id string) (ExtensionRow, bool)
- func (m *UIModel) ExtensionSettingRow(id string) (Row, bool)
- func (m *UIModel) Reset(ctx context.Context, key string, target Target) error
- func (m *UIModel) ResetFor(ctx context.Context, key string, target Target, language string) error
- func (m *UIModel) Row(key string, target Target, groupID string) (Row, bool)
- func (m *UIModel) RowFor(key string, target Target, language, groupID string) (Row, bool)
- func (m *UIModel) Search(target Target, text string, resolve LanguageResolver) SearchResult
- func (m *UIModel) SetExtensions(list []ExtensionInfo)
- func (m *UIModel) SetText(ctx context.Context, key string, target Target, text string) error
- func (m *UIModel) SetTextFor(ctx context.Context, key string, target Target, language, text string) error
- func (m *UIModel) SetValue(ctx context.Context, key string, target Target, value any) error
- func (m *UIModel) SetValueFor(ctx context.Context, key string, target Target, language string, value any) error
- func (m *UIModel) Store() *Store
Constants ¶
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.
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)
const CommonlyUsedID = "commonlyUsed"
CommonlyUsedID is the id of the group of the settings most people change.
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)
const DefaultWindowTitleSeparator = " - "
DefaultWindowTitleSeparator is the default of window.titleSeparator on Linux.
const DisabledExtensionsKey = "extensions.disabled"
DisabledExtensionsKey is the setting that lists the extensions the user turned off.
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).
const InstalledExtensionsID = extensionsID + "/installed"
InstalledExtensionsID is the id of the group of the extension rows, the first group under Extensions.
Variables ¶
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 ¶
ClampZoomLevel keeps a zoom level in the range from MinZoomLevel to MaxZoomLevel; NaN is 0.
func DefaultSettingsJSON ¶
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 ¶
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
ExtensionOfRowKey is the id of the extension of a row key, and whether the key is the row of an extension.
func Get ¶
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 ¶
IsOverrideKey tells whether a key names a language block, such as "[go]".
func KeyToDisplayFormat ¶
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 ¶
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 ¶
OverrideKey makes the key of a block for language ids: "[go]" or "[go]json".
func RenderDescription ¶
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
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 UserSettingsPath ¶
UserSettingsPath is the settings.json of a profile (SPEC §10.12).
func WordifyKey ¶
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 ¶
WorkspaceSettingsPath is <folder>/.emetos/settings.json. Emetos reads no other folder's settings (SPEC decision D12).
func ZoomFactor ¶
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 ¶
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 ¶
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 ¶
Count is the number of settings and extension rows in the group and below it.
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 ¶
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 ¶
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 ¶
AddValue sets a dotted key and puts it at the end of the keys, even if it is there.
func (*Model) GetOverrideValue ¶
GetOverrideValue returns the value the blocks for a language give a section.
func (*Model) GetValue ¶
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) KeysForOverride ¶
KeysForOverride returns the names written in the blocks that include the language.
func (*Model) Merge ¶
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 ¶
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 ¶
OverrideIdentifiers returns the language ids of all the blocks, without repeats.
func (*Model) RemoveValue ¶
RemoveValue removes a dotted key; nothing happens when it is not one of the keys.
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 ¶
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 ¶
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.
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) Categories ¶
Categories returns the categories of the settings, sorted.
func (*Registry) MustRegister ¶
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 ¶
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 ¶
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
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
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.
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) ChoiceIndex ¶
ChoiceIndex is the index of the choice that is the value of an enum row, or -1.
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 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) Keys ¶
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 ¶
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) 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) RemoveForLanguage ¶
RemoveForLanguage removes a setting from the block of a language.
func (*Store) Section ¶ added in v1.0.0
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 ¶
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 ¶
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 ¶
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.
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 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 ¶
NewUIModel makes the UI model of the settings editor over a store, with the table of contents of VS Code (DefaultTOC).
func (*UIModel) Categories ¶
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
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 ¶
Reset removes the setting from the file of the target ("Reset Setting"): the layers below show again.
func (*UIModel) ResetFor ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.