Skip to content

Commit

Permalink
action/command: Let reload really reload the settings.json
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKar committed Aug 18, 2024
1 parent fd3a002 commit 9afcb80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
18 changes: 14 additions & 4 deletions internal/action/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,16 @@ func reloadRuntime(reloadPlugins bool) {
err := config.ReadSettings()
if err != nil {
screen.TermMessage(err)
}
err = config.InitGlobalSettings()
if err != nil {
screen.TermMessage(err)
} else {
parsedSettings := config.ParsedSettings()
defaultSettings := config.DefaultAllSettings()
for k := range defaultSettings {
if _, ok := parsedSettings[k]; ok {
SetGlobalOptionNative(k, parsedSettings[k])
} else {
SetGlobalOptionNative(k, defaultSettings[k])
}
}
}

if reloadPlugins {
Expand Down Expand Up @@ -393,6 +399,10 @@ func reloadRuntime(reloadPlugins bool) {
screen.TermMessage(err)
}
for _, b := range buffer.OpenBuffers {
config.InitLocalSettings(b.Settings, b.Path)
for k, v := range b.Settings {
b.SetOptionNative(k, v)
}
b.UpdateRules()
}
}
Expand Down
10 changes: 9 additions & 1 deletion internal/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ var (
func init() {
ModifiedSettings = make(map[string]bool)
VolatileSettings = make(map[string]bool)
parsedSettings = make(map[string]interface{})
}

func ReadSettings() error {
parsedSettings = make(map[string]interface{})
filename := filepath.Join(ConfigDir, "settings.json")
if _, e := os.Stat(filename); e == nil {
input, err := ioutil.ReadFile(filename)
Expand Down Expand Up @@ -189,6 +189,14 @@ func ReadSettings() error {
return nil
}

func ParsedSettings() map[string]interface{} {
s := make(map[string]interface{})
for k, v := range parsedSettings {
s[k] = v
}
return s
}

func verifySetting(option string, value reflect.Type, def reflect.Type) bool {
var interfaceArr []interface{}
switch option {
Expand Down

0 comments on commit 9afcb80

Please sign in to comment.