diff --git a/lua/gopher/comment.lua b/lua/gopher/comment.lua index 0a146fb..41e3f75 100644 --- a/lua/gopher/comment.lua +++ b/lua/gopher/comment.lua @@ -1,5 +1,6 @@ +local ts_utils = require "gopher._utils.ts" + local function generate(row, col) - local ts_utils = require "gopher._utils.ts" local comment, ns = nil, nil ns = ts_utils.get_package_node_at_pos(row, col, nil, false) diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index 724971c..673fbfe 100644 --- a/lua/gopher/gotests.lua +++ b/lua/gopher/gotests.lua @@ -1,11 +1,11 @@ +local Job = require "plenary.job" +local ts_utils = require "gopher._utils.ts" +local c = require("gopher.config").config.commands local u = require "gopher._utils" -local M = {} +local tests = {} ---@param cmd_args table local function run(cmd_args) - local Job = require "plenary.job" - local c = require("gopher.config").config.commands - Job:new({ command = c.gotests, args = cmd_args, @@ -30,9 +30,7 @@ end ---generate unit test for one function ---@param parallel boolean -function M.func_test(parallel) - local ts_utils = require "gopher._utils.ts" - +function tests.func_test(parallel) local ns = ts_utils.get_func_method_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) if ns == nil or ns.name == nil then u.notify("cursor on func/method and execute the command again", "info") @@ -49,7 +47,7 @@ end ---generate unit tests for all functions in current file ---@param parallel boolean -function M.all_tests(parallel) +function tests.all_tests(parallel) local cmd_args = { "-all" } if parallel then table.insert(cmd_args, "-parallel") @@ -60,7 +58,7 @@ end ---generate unit tests for all exported functions ---@param parallel boolean -function M.all_exported_tests(parallel) +function tests.all_exported_tests(parallel) local cmd_args = {} if parallel then table.insert(cmd_args, "-parallel") @@ -70,4 +68,4 @@ function M.all_exported_tests(parallel) add_test(cmd_args) end -return M +return tests diff --git a/lua/gopher/impl.lua b/lua/gopher/impl.lua index a279889..e04dd4e 100644 --- a/lua/gopher/impl.lua +++ b/lua/gopher/impl.lua @@ -1,9 +1,10 @@ +local c = require("gopher.config").config.commands +local Job = require "plenary.job" +local ts_utils = require "gopher._utils.ts" local u = require "gopher._utils" ---@return string local function get_struct() - local ts_utils = require "gopher._utils.ts" - local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) if ns == nil then u.notify("put cursor on a struct or specify a receiver", "info") @@ -19,9 +20,6 @@ local function get_struct() end return function(...) - local c = require("gopher.config").config.commands - local Job = require "plenary.job" - local args = { ... } local iface, recv_name = "", "" local recv = get_struct()