Disable early validation of colorscheme option

Adding early validation of options in ReadSettings() caused a regression:
colorschemes registered by plugins via config.AddRuntimeFile() stopped
working, since ReadSettings() is called when plugins are not initialized
(or even loaded) yet, so a colorscheme is not registered yet and thus
its validation fails.

Fix that with an ad-hoc fix: treat the "colorscheme" option as a special
case and do not verify it early when reading settings.json, postponing
that until the moment when we try to load this colorscheme.
This commit is contained in:
Dmytro Maluka
2025-05-25 16:33:41 +02:00
parent bf255b6c35
commit 73066fb69b
2 changed files with 14 additions and 0 deletions

View File

@@ -55,6 +55,14 @@ func InitColorscheme() error {
c, err := LoadDefaultColorscheme() c, err := LoadDefaultColorscheme()
if err == nil { if err == nil {
Colorscheme = c Colorscheme = c
} else {
// The colorscheme setting seems broken (maybe because we have not validated
// it earlier, see comment in verifySetting()). So reset it to the default
// colorscheme and try again.
GlobalSettings["colorscheme"] = DefaultGlobalOnlySettings["colorscheme"]
if c, err2 := LoadDefaultColorscheme(); err2 == nil {
Colorscheme = c
}
} }
return err return err

View File

@@ -270,6 +270,12 @@ func verifySetting(option string, value interface{}, def interface{}) error {
return fmt.Errorf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", option, valType, def, defType) return fmt.Errorf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", option, valType, def, defType)
} }
if option == "colorscheme" {
// Plugins are not initialized yet, so do not verify if the colorscheme
// exists yet, since the colorscheme may be added by a plugin later.
return nil
}
if err := OptionIsValid(option, value); err != nil { if err := OptionIsValid(option, value); err != nil {
return err return err
} }