From 8c0685d440ef7e0afbc383e2292280b61570c65c Mon Sep 17 00:00:00 2001 From: Dheisom Gomes Date: Fri, 28 Jan 2022 11:53:30 -0300 Subject: [PATCH 1/4] Added support to pass extra arguments to functions on core.add_thread --- data/core/init.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 91fc59e8..ae766f57 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -953,9 +953,11 @@ function core.show_title_bar(show) end -function core.add_thread(f, weak_ref) +function core.add_thread(f, weak_ref, ...) local key = weak_ref or #core.threads + 1 - local fn = function() return core.try(f) end + local args = {...} + local unpack = unpack or table.unpack + local fn = function() return core.try(f, unpack(args)) end core.threads[key] = { cr = coroutine.create(fn), wake = 0 } return key end From 6331a23c6b4de4926052b9d8d68e5bcab409a4c9 Mon Sep 17 00:00:00 2001 From: Dheisom Gomes Date: Fri, 28 Jan 2022 12:02:30 -0300 Subject: [PATCH 2/4] Added support to use a array of regex to ignore files --- data/core/common.lua | 13 +++++++++++++ data/core/config.lua | 2 +- data/core/init.lua | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/data/core/common.lua b/data/core/common.lua index 37d30436..dc61553b 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -1,3 +1,5 @@ +local config = require 'core.config' + local common = {} @@ -445,4 +447,15 @@ function common.rm(path, recursively) return true end +---@param filename string +---@return boolean +function common.match_ignore_files(filename) + for _, pattern in ipairs(config.ignore_files) do + if common.match_pattern(filename, pattern) then + return true + end + end + return false +end + return common diff --git a/data/core/config.lua b/data/core/config.lua index 1233595b..02c68f5e 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -6,7 +6,7 @@ config.message_timeout = 5 config.mouse_wheel_scroll = 50 * SCALE config.scroll_past_end = true config.file_size_limit = 10 -config.ignore_files = "^%." +config.ignore_files = { "^%.", "node_modules" } config.symbol_pattern = "[%a_][%w_]*" config.non_word_chars = " \t\n/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-" config.undo_merge_timeout = 0.3 diff --git a/data/core/init.lua b/data/core/init.lua index ae766f57..6a1f306e 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -100,7 +100,7 @@ local function get_project_file_info(root, file) if info then info.filename = strip_leading_path(file) return (info.size < config.file_size_limit * 1e6 and - not common.match_pattern(common.basename(info.filename), config.ignore_files) + not common.match_ignore_files(common.basename(info.filename)) and info) end end @@ -462,7 +462,7 @@ end local function project_scan_add_file(dir, filepath) for fragment in string.gmatch(filepath, "([^/\\]+)") do - if common.match_pattern(fragment, config.ignore_files) then + if common.match_ignore_files(fragment) then return end end From 22d8f69b5c12f59c126f07ee91614900428849f9 Mon Sep 17 00:00:00 2001 From: Dheisom Gomes Date: Fri, 28 Jan 2022 12:13:52 -0300 Subject: [PATCH 3/4] Error correction getting "unpack" function --- data/core/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 6a1f306e..6cd0b2d8 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -956,8 +956,8 @@ end function core.add_thread(f, weak_ref, ...) local key = weak_ref or #core.threads + 1 local args = {...} - local unpack = unpack or table.unpack - local fn = function() return core.try(f, unpack(args)) end + local table_unpack = rawget(_G, 'unpack') or rawget(_G.table, 'unpack') + local fn = function() return core.try(f, table_unpack(args)) end core.threads[key] = { cr = coroutine.create(fn), wake = 0 } return key end From 13adedb23a5b98bf4c147a8b7fad4a367222f170 Mon Sep 17 00:00:00 2001 From: Dheisom Gomes Date: Fri, 28 Jan 2022 18:30:19 -0300 Subject: [PATCH 4/4] Go back to `common.match_pattern` and use `table.unpack` directly on function `core.add_thread` --- data/core/common.lua | 14 +------------- data/core/config.lua | 12 ++++++------ data/core/init.lua | 7 +++---- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/data/core/common.lua b/data/core/common.lua index dc61553b..6a25cae2 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -1,5 +1,3 @@ -local config = require 'core.config' - local common = {} @@ -24,7 +22,7 @@ function common.merge(a, b) for k, v in pairs(a) do t[k] = v end if b then for k, v in pairs(b) do t[k] = v end end return t -end +end function common.round(n) @@ -447,15 +445,5 @@ function common.rm(path, recursively) return true end ----@param filename string ----@return boolean -function common.match_ignore_files(filename) - for _, pattern in ipairs(config.ignore_files) do - if common.match_pattern(filename, pattern) then - return true - end - end - return false -end return common diff --git a/data/core/config.lua b/data/core/config.lua index 02c68f5e..d8a0bbd1 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -6,7 +6,7 @@ config.message_timeout = 5 config.mouse_wheel_scroll = 50 * SCALE config.scroll_past_end = true config.file_size_limit = 10 -config.ignore_files = { "^%.", "node_modules" } +config.ignore_files = { "^%." } config.symbol_pattern = "[%a_][%w_]*" config.non_word_chars = " \t\n/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-" config.undo_merge_timeout = 0.3 @@ -32,11 +32,11 @@ config.max_clicks = 3 config.plugins = {} -- Allow you to set plugin configs even if we haven't seen the plugin before. -setmetatable(config.plugins, { - __index = function(t, k) - if rawget(t, k) == nil then rawset(t, k, {}) end - return rawget(t, k) - end +setmetatable(config.plugins, { + __index = function(t, k) + if rawget(t, k) == nil then rawset(t, k, {}) end + return rawget(t, k) + end }) -- Disable these plugins by default. diff --git a/data/core/init.lua b/data/core/init.lua index 6cd0b2d8..85bbaf19 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -100,7 +100,7 @@ local function get_project_file_info(root, file) if info then info.filename = strip_leading_path(file) return (info.size < config.file_size_limit * 1e6 and - not common.match_ignore_files(common.basename(info.filename)) + not common.match_pattern(common.basename(info.filename), config.ignore_files) and info) end end @@ -462,7 +462,7 @@ end local function project_scan_add_file(dir, filepath) for fragment in string.gmatch(filepath, "([^/\\]+)") do - if common.match_ignore_files(fragment) then + if common.match_pattern(fragment, config.ignore_files) then return end end @@ -956,8 +956,7 @@ end function core.add_thread(f, weak_ref, ...) local key = weak_ref or #core.threads + 1 local args = {...} - local table_unpack = rawget(_G, 'unpack') or rawget(_G.table, 'unpack') - local fn = function() return core.try(f, table_unpack(args)) end + local fn = function() return core.try(f, table.unpack(args)) end core.threads[key] = { cr = coroutine.create(fn), wake = 0 } return key end