diff --git a/lua/gopher/_utils/commands.lua b/lua/gopher/_utils/commands.lua index 4f5a59a..33926a4 100644 --- a/lua/gopher/_utils/commands.lua +++ b/lua/gopher/_utils/commands.lua @@ -1,11 +1,11 @@ -local Job = require "plenary.job" -local c = require("gopher.config").config.commands -local u = require "gopher._utils" - ---Run any go commands like `go generate`, `go get`, `go mod` ---@param cmd string ---@param ... string|string[] return function(cmd, ...) + local Job = require "plenary.job" + local c = require("gopher.config").config.commands + local u = require "gopher._utils" + local args = { ... } if #args == 0 then u.notify("please provice any arguments", "error") diff --git a/lua/gopher/_utils/ts/nodes.lua b/lua/gopher/_utils/ts/nodes.lua index 9b5b813..8a217a5 100644 --- a/lua/gopher/_utils/ts/nodes.lua +++ b/lua/gopher/_utils/ts/nodes.lua @@ -1,7 +1,3 @@ -local ts_query = require "nvim-treesitter.query" -local parsers = require "nvim-treesitter.parsers" -local locals = require "nvim-treesitter.locals" -local u = require "gopher._utils" local M = {} local function intersects(row, col, sRow, sCol, eRow, eCol) @@ -57,6 +53,10 @@ end ---@param pos_row string ---@return string function M.get_all_nodes(query, lang, _, bufnr, pos_row, _) + local ts_query = require "nvim-treesitter.query" + local parsers = require "nvim-treesitter.parsers" + local locals = require "nvim-treesitter.locals" + bufnr = bufnr or 0 pos_row = pos_row or 30000 @@ -113,6 +113,8 @@ end ---@param col string ---@return table function M.nodes_at_cursor(query, default, bufnr, row, col) + local u = require "gopher._utils" + bufnr = bufnr or vim.api.nvim_get_current_buf() local ft = vim.api.nvim_buf_get_option(bufnr, "ft") if row == nil or col == nil then diff --git a/lua/gopher/comment.lua b/lua/gopher/comment.lua index 41e3f75..0a146fb 100644 --- a/lua/gopher/comment.lua +++ b/lua/gopher/comment.lua @@ -1,6 +1,5 @@ -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/dap/init.lua b/lua/gopher/dap/init.lua index 0c6ff7a..9b0b626 100644 --- a/lua/gopher/dap/init.lua +++ b/lua/gopher/dap/init.lua @@ -1,9 +1,10 @@ -local cfg = require "gopher.dap.config" -local u = require "gopher._utils" local M = {} ---setup nvim-dap for golang using function M.setup() + local cfg = require "gopher.dap.config" + local u = require "gopher._utils" + local dap = u.sreq "dap" dap.adapters.go = cfg.adapter dap.configurations.go = cfg.configuration diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index 2e43017..724971c 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 = {} ---@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, @@ -31,6 +31,8 @@ end ---generate unit test for one function ---@param parallel boolean function M.func_test(parallel) + local ts_utils = require "gopher._utils.ts" + 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") diff --git a/lua/gopher/health.lua b/lua/gopher/health.lua index f1cc979..17d76ec 100644 --- a/lua/gopher/health.lua +++ b/lua/gopher/health.lua @@ -1,13 +1,11 @@ -local health = vim.health or require "health" -local utils = require "gopher._utils._health" local c = require("gopher.config").config.commands -local requried = "Gopher.nvim will not work without it!" +local requried_for_work_msg = "Gopher.nvim will not work without it!" local M = { _required = { plugins = { - { lib = "plenary", help = requried }, - { lib = "nvim-treesitter", help = requried }, + { lib = "plenary", help = requried_for_work_msg }, + { lib = "nvim-treesitter", help = requried_for_work_msg }, { lib = "dap", help = "Required for set upping debugger" }, }, binarys = { @@ -21,9 +19,12 @@ local M = { } function M.check() + local health = vim.health or require "health" + local u = require "gopher._utils._health" + health.report_start "Required plugins" for _, plugin in ipairs(M._required.plugins) do - if utils.lualib_is_found(plugin.lib) then + if u.lualib_is_found(plugin.lib) then health.report_ok(plugin.lib .. " installed.") else health.report_error(plugin.lib .. " not found. " .. plugin.help) @@ -32,7 +33,7 @@ function M.check() health.report_start "Required go tools" for _, binary in ipairs(M._required.binarys) do - if utils.binary_is_found(binary.bin) then + if u.binary_is_found(binary.bin) then health.report_ok(binary.bin .. " installed") else health.report_warn(binary.bin .. " is not installed but " .. binary.help) diff --git a/lua/gopher/iferr.lua b/lua/gopher/iferr.lua index 24d4041..7f43318 100644 --- a/lua/gopher/iferr.lua +++ b/lua/gopher/iferr.lua @@ -1,10 +1,10 @@ -local c = require("gopher.config").config.commands -local u = require "gopher._utils" - ---Add iferr declaration ---That's Lua of vimscript implementation of: ---github.com/koron/iferr return function() + local c = require("gopher.config").config.commands + local u = require "gopher._utils" + local boff = vim.fn.wordcount().cursor_bytes local cmd = (c.iferr .. " -pos " .. boff) local data = vim.fn.systemlist(cmd, vim.fn.bufnr "%") diff --git a/lua/gopher/impl.lua b/lua/gopher/impl.lua index ee0aa3c..8af87f8 100644 --- a/lua/gopher/impl.lua +++ b/lua/gopher/impl.lua @@ -1,10 +1,9 @@ -local Job = require "plenary.job" -local ts_utils = require "gopher._utils.ts" -local c = require("gopher.config").config.commands 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") @@ -20,6 +19,9 @@ 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() diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index 355562b..fdd6242 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -1,5 +1,3 @@ -local Job = require "plenary.job" -local u = require "gopher._utils" local urls = { gomodifytags = "github.com/fatih/gomodifytags", impl = "github.com/josharian/impl", @@ -10,6 +8,9 @@ local urls = { ---@param pkg string local function install(pkg) + local Job = require "plenary.job" + local u = require "gopher._utils" + local url = urls[pkg] .. "@latest" Job:new({ diff --git a/lua/gopher/struct_tags.lua b/lua/gopher/struct_tags.lua index 11488b0..a91901a 100644 --- a/lua/gopher/struct_tags.lua +++ b/lua/gopher/struct_tags.lua @@ -1,10 +1,11 @@ -local Job = require "plenary.job" -local ts_utils = require "gopher._utils.ts" -local u = require "gopher._utils" -local c = require("gopher.config").config.commands local M = {} local function modify(...) + local ts_utils = require "gopher._utils.ts" + local Job = require "plenary.job" + local c = require("gopher.config").config.commands + local u = require "gopher._utils" + local fpath = vim.fn.expand "%" ---@diagnostic disable-line: missing-parameter local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) if ns == nil then