From 8db459e84e6c642707a6bc41154a3f51723f9a0a Mon Sep 17 00:00:00 2001 From: Jaezmien Naejara Date: Wed, 3 Apr 2024 07:39:29 +0800 Subject: [PATCH 1/5] fix: Use show-line-numbers instead of line-numbers --- lua/charm-freeze/init.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/charm-freeze/init.lua b/lua/charm-freeze/init.lua index de2fdbe..4dfd64d 100644 --- a/lua/charm-freeze/init.lua +++ b/lua/charm-freeze/init.lua @@ -93,6 +93,9 @@ M.get_arguments = function(args, options) table.insert(cmd, "--" .. k) table.insert(cmd, table.concat(v, ",")) end + -- handle --show-line-numbers + elseif k == "line_numbers" then + table.insert(cmd, '--show-line-numbers') -- table options ('border', 'font', 'shadow') elseif type(v) == "table" and not is_array(v) then for _k, _v in pairs(v) do From f2af1885a58c227704ed3336d98bb609882651c8 Mon Sep 17 00:00:00 2001 From: Jaezmien Naejara Date: Wed, 3 Apr 2024 18:48:03 +0800 Subject: [PATCH 2/5] fix: Separate cmd table generation and fix boolean options --- lua/charm-freeze/init.lua | 41 ++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/lua/charm-freeze/init.lua b/lua/charm-freeze/init.lua index 01e60e5..644770d 100644 --- a/lua/charm-freeze/init.lua +++ b/lua/charm-freeze/init.lua @@ -79,46 +79,43 @@ M.parse_options = function(opts) return options end --- Generate the command line arguments -M.get_arguments = function(args, options) - local cmd = {} - local value = nil - - table.insert(cmd, options.command) - - for k, v in pairs(options) do - -- handle margin and padding sepreatly as tables +local function populate_cmd(cmd, args, tbl) + for k,v in pairs(tbl) do + -- handle margin and padding separately as tables if k == "margin" or k == "padding" then if type(v) == "table" then table.insert(cmd, "--" .. k) table.insert(cmd, table.concat(v, ",")) end - -- handle --show-line-numbers - elseif k == "line_numbers" then - table.insert(cmd, '--show-line-numbers') -- table options ('border', 'font', 'shadow') elseif type(v) == "table" and not is_array(v) then - for _k, _v in pairs(v) do - table.insert(cmd, "--" .. k .. "." .. string.gsub(_k, "_", "-")) - table.insert(cmd, _v) - end - -- handle boolean options, they are just flags with no value - elseif type(v) == "boolean" then - if v then - table.insert(cmd, "--" .. string.gsub(k, "_", "-")) - end + populate_cmd(cmd, args, v) -- handle anything that is not the command or language option elseif k ~= "command" and k ~= "language" then table.insert(cmd, "--" .. string.gsub(k, "_", "-")) + -- if the value is a function, call it with the args, otherwise just use the value + local value = nil if type(v) == "function" then value = v(args) else value = v end - table.insert(cmd, value) + + -- Don't append the value if it's a boolean option. + if type(v) ~= "boolean" then + table.insert(cmd, value) + end end end +end + +-- Generate the command line arguments +M.get_arguments = function(args, options) + local cmd = {} + + table.insert(cmd, options.command) + populate_cmd(cmd, args, options) return cmd end From 8074bc9d8124647d636e14bd4aabe3446edfb65f Mon Sep 17 00:00:00 2001 From: Jaezmien Naejara Date: Wed, 3 Apr 2024 18:48:50 +0800 Subject: [PATCH 3/5] fix: Use show_line_numbers sintead of line_numbers --- lua/charm-freeze/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/charm-freeze/init.lua b/lua/charm-freeze/init.lua index 644770d..f0da4a2 100644 --- a/lua/charm-freeze/init.lua +++ b/lua/charm-freeze/init.lua @@ -23,7 +23,7 @@ M.allowed_opts = { margin = { "string", "table" }, background = "string", theme = "string", - line_numbers = "boolean", + show_line_numbers = "boolean", line_height = "number", language = "string", font = { From 3d0fa7c877024583bfd0b6a644879530a9cdc5b0 Mon Sep 17 00:00:00 2001 From: Jaezmien Naejara Date: Wed, 3 Apr 2024 18:57:06 +0800 Subject: [PATCH 4/5] fix: Update test in accordance to 8074bc9d --- tests/charm-freeze/test_all.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/charm-freeze/test_all.lua b/tests/charm-freeze/test_all.lua index 58ac0a7..ed8431f 100644 --- a/tests/charm-freeze/test_all.lua +++ b/tests/charm-freeze/test_all.lua @@ -35,7 +35,7 @@ end T["invalid_options.boolean"] = function() e(function() - child.lua([[P.setup({line_numbers = "chesee"})]]) + child.lua([[P.setup({show_line_numbers = "chesee"})]]) end) end @@ -78,7 +78,7 @@ end T["valid_options.boolean"] = function() ne(function() - child.lua([[P.setup({line_numbers = false})]]) + child.lua([[P.setup({show_line_numbers = false})]]) end) end From a1a1875b01d73ab0642577079863ea82629b356e Mon Sep 17 00:00:00 2001 From: Jaezmien Naejara Date: Wed, 3 Apr 2024 19:08:04 +0800 Subject: [PATCH 5/5] fix: Fix populate_cmd not handling argument prefixes for tables --- lua/charm-freeze/init.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lua/charm-freeze/init.lua b/lua/charm-freeze/init.lua index f0da4a2..83d86cc 100644 --- a/lua/charm-freeze/init.lua +++ b/lua/charm-freeze/init.lua @@ -79,20 +79,20 @@ M.parse_options = function(opts) return options end -local function populate_cmd(cmd, args, tbl) +local function populate_cmd(cmd, args, tbl, prefix) for k,v in pairs(tbl) do -- handle margin and padding separately as tables if k == "margin" or k == "padding" then if type(v) == "table" then - table.insert(cmd, "--" .. k) + table.insert(cmd, "--" .. prefix .. k) table.insert(cmd, table.concat(v, ",")) end -- table options ('border', 'font', 'shadow') elseif type(v) == "table" and not is_array(v) then - populate_cmd(cmd, args, v) + populate_cmd(cmd, args, v, prefix .. k .. '.') -- handle anything that is not the command or language option elseif k ~= "command" and k ~= "language" then - table.insert(cmd, "--" .. string.gsub(k, "_", "-")) + table.insert(cmd, "--" .. prefix .. string.gsub(k, "_", "-")) -- if the value is a function, call it with the args, otherwise just use the value local value = nil @@ -115,7 +115,7 @@ M.get_arguments = function(args, options) local cmd = {} table.insert(cmd, options.command) - populate_cmd(cmd, args, options) + populate_cmd(cmd, args, options, '') return cmd end