From 2d6527bab9ca28144e974f4da6c3ad82ce43dbd4 Mon Sep 17 00:00:00 2001 From: Pablo Fonseca Date: Wed, 22 May 2024 07:55:14 +0100 Subject: [PATCH] fix: replace tbl_flatten to flatten():totable() --- lua/neotest-go/init.lua | 12 ++++++------ lua/neotest-go/utils.lua | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lua/neotest-go/init.lua b/lua/neotest-go/init.lua index 54e12be..2de3ac3 100644 --- a/lua/neotest-go/init.lua +++ b/lua/neotest-go/init.lua @@ -46,7 +46,7 @@ function adapter._generate_position_id(position, namespaces) end end local name = utils.transform_test_name(position.name) - return table.concat(vim.tbl_flatten({ position.path, prefix, name }), "::") + return table.concat(utils.tbl_flatten({ position.path, prefix, name }), "::") end ---@async @@ -162,7 +162,7 @@ function adapter.build_spec(args) if fn.isdirectory(position.path) ~= 1 then location = fn.fnamemodify(position.path, ":h") end - local command = vim.tbl_flatten({ + local command = utils.tbl_flatten({ "cd", location, "&&", @@ -175,14 +175,14 @@ function adapter.build_spec(args) dir, }) local return_result = { - command = table.concat(command, ' '), + command = table.concat(command, " "), context = { results_path = results_path, - file = position.path - } + file = position.path, + }, } - if strategy == 'dap' then + if strategy == "dap" then return_result.strategy = utils.get_dap_config() end diff --git a/lua/neotest-go/utils.lua b/lua/neotest-go/utils.lua index cff7d40..82ddee3 100644 --- a/lua/neotest-go/utils.lua +++ b/lua/neotest-go/utils.lua @@ -24,11 +24,11 @@ end ---@return table | nil function utils.get_dap_config() return { - type = 'go', - name = 'Neotest Debugger', - request = 'launch', - mode = 'test', - program = './${relativeFileDirname}', + type = "go", + name = "Neotest Debugger", + request = "launch", + mode = "test", + program = "./${relativeFileDirname}", } end @@ -183,4 +183,11 @@ function utils.get_prefix(tree, name) return parent_name .. "/" .. name end +---@param t table +---@return table +function utils.tbl_flatten(t) + return vim.fn.has("nvim-0.11") == 1 and vim.iter(t):flatten(math.huge):totable() + or vim.tbl_flatten(t) +end + return utils