@@ -227,12 +227,6 @@ local function merge_global_components_config(components, config)
227
227
if name == " indent" then
228
228
indent_exists = true
229
229
end
230
- if name == " container" then
231
- for i , child in ipairs (component .content ) do
232
- component .content [i ] = do_merge (child )
233
- end
234
- return component
235
- end
236
230
local merged = { name }
237
231
local global_config = config .default_component_configs [name ]
238
232
if global_config then
@@ -243,6 +237,11 @@ local function merge_global_components_config(components, config)
243
237
for k , v in pairs (component ) do
244
238
merged [k ] = v
245
239
end
240
+ if name == " container" then
241
+ for i , child in ipairs (component .content ) do
242
+ merged .content [i ] = do_merge (child )
243
+ end
244
+ end
246
245
return merged
247
246
else
248
247
log .error (" component name is the wrong type" , component )
@@ -267,11 +266,51 @@ local function merge_global_components_config(components, config)
267
266
return merged_components
268
267
end
269
268
270
- M .merge_config = function (config , is_auto_config )
269
+ local merge_renderers = function (default_config , source_default_config , user_config )
270
+ -- This can't be a deep copy/merge. If a renderer is specified in the target it completely
271
+ -- replaces the base renderer.
272
+
273
+ if source_default_config == nil then
274
+ -- first override the default config global renderer with the user's global renderers
275
+ for name , renderer in pairs (user_config .renderers or {}) do
276
+ log .debug (" overriding global renderer for " .. name )
277
+ default_config .renderers [name ] = renderer
278
+ end
279
+ else
280
+ -- then override the global renderers with the source specific renderers
281
+ source_default_config .renderers = source_default_config .renderers or {}
282
+ for name , renderer in pairs (default_config .renderers or {}) do
283
+ if source_default_config .renderers [name ] == nil then
284
+ log .debug (" overriding source renderer for " .. name )
285
+ local r = {}
286
+ -- Only copy components that exist in the target source.
287
+ -- This alllows us to specify global renderers that include components from all sources,
288
+ -- even if some of those components are not universal
289
+ for _ , value in ipairs (renderer ) do
290
+ if value [1 ] and source_default_config .components [value [1 ]] ~= nil then
291
+ table.insert (r , value )
292
+ end
293
+ end
294
+ source_default_config .renderers [name ] = r
295
+ end
296
+ end
297
+
298
+ -- if user sets renderers, completely wipe the default ones
299
+ local source_name = source_default_config .name
300
+ for name , _ in pairs (source_default_config .renderers ) do
301
+ local user = utils .get_value (user_config , source_name .. " .renderers." .. name )
302
+ if user then
303
+ source_default_config .renderers [name ] = nil
304
+ end
305
+ end
306
+ end
307
+ end
308
+
309
+ M .merge_config = function (user_config , is_auto_config )
271
310
local default_config = vim .deepcopy (defaults )
272
- config = vim .deepcopy (config or {})
311
+ user_config = vim .deepcopy (user_config or {})
273
312
274
- local migrations = require (" neo-tree.setup.deprecations" ).migrate (config )
313
+ local migrations = require (" neo-tree.setup.deprecations" ).migrate (user_config )
275
314
if # migrations > 0 then
276
315
-- defer to make sure it is the last message printed
277
316
vim .defer_fn (function ()
@@ -281,10 +320,10 @@ M.merge_config = function(config, is_auto_config)
281
320
end , 50 )
282
321
end
283
322
284
- if config .log_level ~= nil then
285
- M .set_log_level (config .log_level )
323
+ if user_config .log_level ~= nil then
324
+ M .set_log_level (user_config .log_level )
286
325
end
287
- log .use_file (config .log_to_file , true )
326
+ log .use_file (user_config .log_to_file , true )
288
327
log .debug (" setup" )
289
328
290
329
events .clear_all_events ()
@@ -296,8 +335,8 @@ M.merge_config = function(config, is_auto_config)
296
335
handler = M .buffer_enter_event ,
297
336
})
298
337
299
- if config .event_handlers ~= nil then
300
- for _ , handler in ipairs (config .event_handlers ) do
338
+ if user_config .event_handlers ~= nil then
339
+ for _ , handler in ipairs (user_config .event_handlers ) do
301
340
events .subscribe (handler )
302
341
end
303
342
end
@@ -306,6 +345,7 @@ M.merge_config = function(config, is_auto_config)
306
345
307
346
-- setup the default values for all sources
308
347
normalize_mappings (default_config )
348
+ merge_renderers (default_config , nil , user_config )
309
349
for _ , source_name in ipairs (sources ) do
310
350
local source_default_config = default_config [source_name ]
311
351
local mod_root = " neo-tree.sources." .. source_name
@@ -315,47 +355,29 @@ M.merge_config = function(config, is_auto_config)
315
355
316
356
-- Make sure all the mappings are normalized so they will merge properly.
317
357
normalize_mappings (source_default_config )
318
- normalize_mappings (config [source_name ])
358
+ normalize_mappings (user_config [source_name ])
319
359
320
360
local use_default_mappings = default_config .use_default_mappings
321
- if type (config .use_default_mappings ) ~= " nil" then
322
- use_default_mappings = config .use_default_mappings
361
+ if type (user_config .use_default_mappings ) ~= " nil" then
362
+ use_default_mappings = user_config .use_default_mappings
323
363
end
324
364
if use_default_mappings then
325
365
-- merge the global config with the source specific config
326
366
source_default_config .window = vim .tbl_deep_extend (
327
367
" force" ,
328
368
default_config .window or {},
329
369
source_default_config .window or {},
330
- config .window or {}
370
+ user_config .window or {}
331
371
)
332
372
else
333
- source_default_config .window = config .window
334
- end
335
- source_default_config .renderers = source_default_config .renderers or {}
336
- -- if source does not specify a renderer, use the global default
337
- for name , renderer in pairs (default_config .renderers or {}) do
338
- if source_default_config .renderers [name ] == nil then
339
- local r = {}
340
- for _ , value in ipairs (renderer ) do
341
- if value [1 ] and source_default_config .components [value [1 ]] ~= nil then
342
- table.insert (r , value )
343
- end
344
- end
345
- source_default_config .renderers [name ] = r
346
- end
347
- end
348
- -- if user sets renderers, completely wipe the default ones
349
- for name , _ in pairs (source_default_config .renderers ) do
350
- local user = utils .get_value (config , source_name .. " .renderers." .. name )
351
- if user then
352
- source_default_config .renderers [name ] = nil
353
- end
373
+ source_default_config .window = user_config .window
354
374
end
355
375
376
+ merge_renderers (default_config , source_default_config , user_config )
377
+
356
378
-- validate the window.position
357
379
local pos_key = source_name .. " .window.position"
358
- local position = utils .get_value (config , pos_key , " left" , true )
380
+ local position = utils .get_value (user_config , pos_key , " left" , true )
359
381
local valid_positions = {
360
382
left = true ,
361
383
right = true ,
@@ -366,13 +388,13 @@ M.merge_config = function(config, is_auto_config)
366
388
}
367
389
if not valid_positions [position ] then
368
390
log .error (" Invalid value for " , pos_key , " : " , position )
369
- config [source_name ].window .position = " left"
391
+ user_config [source_name ].window .position = " left"
370
392
end
371
393
end
372
394
-- print(vim.inspect(default_config.filesystem))
373
395
374
396
-- apply the users config
375
- M .config = vim .tbl_deep_extend (" force" , default_config , config )
397
+ M .config = vim .tbl_deep_extend (" force" , default_config , user_config )
376
398
if not M .config .enable_git_status then
377
399
M .config .git_status_async = false
378
400
end
0 commit comments