@@ -93,6 +93,21 @@ local function setup_colorscheme_handler(config)
9393 })
9494end
9595
96+ --- Normalize a single option field that can be boolean or table
97+ --- @param value any User-provided value
98+ --- @param default_value table Default table value
99+ --- @param boolean_key string Key to set when value is boolean (e.g. , " enabled" or " messages" )
100+ --- @return table Normalized table value
101+ local function normalize_option (value , default_value , boolean_key )
102+ if type (value ) == " boolean" then
103+ return vim .tbl_deep_extend (" force" , default_value , { [boolean_key ] = value })
104+ elseif type (value ) == " table" then
105+ return vim .tbl_deep_extend (" force" , default_value , value )
106+ else
107+ return vim .deepcopy (default_value )
108+ end
109+ end
110+
96111--- Normalize configuration values
97112local function normalize_config (config )
98113 if config .options .overflow and config .options .overflow .mode then
@@ -107,44 +122,29 @@ local function normalize_config(config)
107122 config = vim .tbl_deep_extend (" force" , config , preset )
108123 end
109124
110- if type (config .options .multilines ) == " boolean" then
111- config .options .multilines = vim .tbl_deep_extend (" force" , default_config .options .multilines , {
112- enabled = config .options .multilines ,
113- })
114- elseif type (config .options .multilines ) == " table" then
115- config .options .multilines =
116- vim .tbl_deep_extend (" force" , default_config .options .multilines , config .options .multilines )
117- end
118-
119- if type (config .options .add_messages ) == " boolean" then
120- config .options .add_messages =
121- vim .tbl_deep_extend (" force" , default_config .options .add_messages , {
122- messages = config .options .add_messages ,
123- })
124- elseif type (config .options .add_messages ) == " table" then
125- config .options .add_messages =
126- vim .tbl_deep_extend (" force" , default_config .options .add_messages , config .options .add_messages )
127- end
128-
129- if type (config .options .show_source ) == " boolean" then
130- config .options .show_source =
131- vim .tbl_deep_extend (" force" , default_config .options .show_source , {
132- enabled = config .options .show_source ,
133- })
134- elseif type (config .options .show_source ) == " table" then
135- config .options .show_source =
136- vim .tbl_deep_extend (" force" , default_config .options .show_source , config .options .show_source )
137- end
138-
139- if type (config .options .show_related ) == " boolean" then
140- config .options .show_related =
141- vim .tbl_deep_extend (" force" , default_config .options .show_related , {
142- enabled = config .options .show_related ,
143- })
144- elseif type (config .options .show_related ) == " table" then
145- config .options .show_related =
146- vim .tbl_deep_extend (" force" , default_config .options .show_related , config .options .show_related )
147- end
125+ config .options .multilines = normalize_option (
126+ config .options .multilines ,
127+ default_config .options .multilines ,
128+ " enabled"
129+ )
130+
131+ config .options .add_messages = normalize_option (
132+ config .options .add_messages ,
133+ default_config .options .add_messages ,
134+ " messages"
135+ )
136+
137+ config .options .show_source = normalize_option (
138+ config .options .show_source ,
139+ default_config .options .show_source ,
140+ " enabled"
141+ )
142+
143+ config .options .show_related = normalize_option (
144+ config .options .show_related ,
145+ default_config .options .show_related ,
146+ " enabled"
147+ )
148148
149149 return config
150150end
0 commit comments