From d7d88a2037b51c7dc6c9280152649dc96add5bc8 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Sun, 6 Mar 2022 19:34:12 -0400 Subject: [PATCH 1/2] init: load core views before user plugins --- data/core/init.lua | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 0d8c8e51..27257b20 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -238,11 +238,11 @@ local function refresh_directory(topdir, target, expanded) -- If we're expecting to keep track of everything, go through the list and iteratively deal with directories. files = dirwatch.get_directory_files(topdir, topdir.name, directory, {}, 0, function() return false end) end - + local new_idx, old_idx = 1, index local new_directories = {} local last_dir = nil - while old_idx <= n or new_idx <= #files do + while old_idx <= n or new_idx <= #files do local old_info, new_info = topdir.files[old_idx], files[new_idx] if not new_info or not old_info or not last_dir or old_info.filename:sub(1, #last_dir + 1) ~= last_dir .. "/" then if not new_info or not old_info or not files_info_equal(new_info, old_info) then @@ -282,7 +282,7 @@ local function refresh_directory(topdir, target, expanded) if change then core.redraw = true topdir.is_dirty = true - end + end return change end end @@ -301,8 +301,8 @@ function core.add_project_directory(path) watch_thread = nil, watch = dirwatch.new() } - table.insert(core.project_directories, topdir) - + table.insert(core.project_directories, topdir) + local fstype = PLATFORM == "Linux" and system.get_fs_type(topdir.name) or "unknown" topdir.force_scans = (fstype == "nfs" or fstype == "fuse") local t, complete, entries_count = dirwatch.get_directory_files(topdir, topdir.name, "", {}, 0, timed_max_files_pred) @@ -320,13 +320,13 @@ function core.add_project_directory(path) topdir.watch:watch(topdir.name) -- each top level directory gets a watch thread. if the project is small, or -- if the ablity to use directory watches hasn't been compromised in some way - -- either through error, or amount of files, then this should be incredibly + -- either through error, or amount of files, then this should be incredibly -- quick; essentially one syscall per check. Otherwise, this may take a bit of -- time; the watch will yield in this coroutine after 0.01 second, for 0.1 seconds. topdir.watch_thread = core.add_thread(function() while true do topdir.watch:check(function(target) - if target == topdir.name then return refresh_directory(topdir, "", true) end + if target == topdir.name then return refresh_directory(topdir, "", true) end local dirpath = target:sub(#topdir.name + 2) local abs_dirpath = topdir.name .. PATHSEP .. dirpath if dirpath then @@ -339,7 +339,7 @@ function core.add_project_directory(path) coroutine.yield(0.05) end end) - + if path == core.project_dir then core.project_files = topdir.files end @@ -719,7 +719,18 @@ function core.init() core.threads = setmetatable({}, { __mode = "k" }) core.blink_start = system.get_time() core.blink_timer = core.blink_start - + core.redraw = true + core.visited_files = {} + core.restart_request = false + core.quit_request = false + + -- We load core views before plugins who may need them. + core.root_view = RootView() + core.command_view = CommandView() + core.status_view = StatusView() + core.nag_view = NagView() + core.title_view = TitleView() + local got_user_error, got_project_error = not core.load_user_directory() local project_dir_abs = system.absolute_path(project_dir) @@ -736,7 +747,7 @@ function core.init() update_recents_project("remove", project_dir) end project_dir_abs = system.absolute_path(".") - if not core.set_project_dir(project_dir_abs, function() + if not core.set_project_dir(project_dir_abs, function() got_project_error = not core.load_project_module() end) then system.show_fatal_error("Lite XL internal error", "cannot set project directory to cwd") @@ -744,17 +755,6 @@ function core.init() end end - core.redraw = true - core.visited_files = {} - core.restart_request = false - core.quit_request = false - - core.root_view = RootView() - core.command_view = CommandView() - core.status_view = StatusView() - core.nag_view = NagView() - core.title_view = TitleView() - local cur_node = core.root_view.root_node cur_node.is_primary_node = true cur_node:split("up", core.title_view, {y = true}) From 9d4e475a2cbedace1064a06a7f51bd58e19e8e2a Mon Sep 17 00:00:00 2001 From: jgmdev Date: Sun, 6 Mar 2022 21:21:00 -0400 Subject: [PATCH 2/2] init: also load default nodes and commands before user plugins and project module. --- data/core/init.lua | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 27257b20..1a2cf61f 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -724,13 +724,27 @@ function core.init() core.restart_request = false core.quit_request = false - -- We load core views before plugins who may need them. + -- We load core views before plugins that may need them. core.root_view = RootView() core.command_view = CommandView() core.status_view = StatusView() core.nag_view = NagView() core.title_view = TitleView() + -- Some plugins (eg: console) require the nodes to be initialized to defaults + local cur_node = core.root_view.root_node + cur_node.is_primary_node = true + cur_node:split("up", core.title_view, {y = true}) + cur_node = cur_node.b + cur_node:split("up", core.nag_view, {y = true}) + cur_node = cur_node.b + cur_node = cur_node:split("down", core.command_view, {y = true}) + cur_node = cur_node:split("down", core.status_view, {y = true}) + + -- Load defaiult commands first so plugins can override them + command.add_defaults() + + -- Load user module, plugins and project module local got_user_error, got_project_error = not core.load_user_directory() local project_dir_abs = system.absolute_path(project_dir) @@ -755,16 +769,7 @@ function core.init() end end - local cur_node = core.root_view.root_node - cur_node.is_primary_node = true - cur_node:split("up", core.title_view, {y = true}) - cur_node = cur_node.b - cur_node:split("up", core.nag_view, {y = true}) - cur_node = cur_node.b - cur_node = cur_node:split("down", core.command_view, {y = true}) - cur_node = cur_node:split("down", core.status_view, {y = true}) - - command.add_defaults() + -- Load core plugins after user ones to let the user override them local plugins_success, plugins_refuse_list = core.load_plugins() do