[mirror] Make your go dev experience better github.com/olexsmir/gopher.nvim
neovim golang
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: move requires in place where they used (#22)

* refactor(comment): move require to a function

* refactor(gotests): move requires inside of functions

* refactor(health): move requires inside of function

* refactor(iferr): move requires inside of a function

* refactor(impl): move some requires inside of functions

* refactor(installer): move requires inside of function

* refactor(struct_tags): move requires into function

* refactor(dap): move import into function

* refactor(utils): move import into functions

authored by

Smirnov Oleksandr and committed by
GitHub
2f0edbfd e8fe6c5b

+43 -34
+4 -4
lua/gopher/_utils/commands.lua
··· 1 - local Job = require "plenary.job" 2 - local c = require("gopher.config").config.commands 3 - local u = require "gopher._utils" 4 - 5 1 ---Run any go commands like `go generate`, `go get`, `go mod` 6 2 ---@param cmd string 7 3 ---@param ... string|string[] 8 4 return function(cmd, ...) 5 + local Job = require "plenary.job" 6 + local c = require("gopher.config").config.commands 7 + local u = require "gopher._utils" 8 + 9 9 local args = { ... } 10 10 if #args == 0 then 11 11 u.notify("please provice any arguments", "error")
+6 -4
lua/gopher/_utils/ts/nodes.lua
··· 1 - local ts_query = require "nvim-treesitter.query" 2 - local parsers = require "nvim-treesitter.parsers" 3 - local locals = require "nvim-treesitter.locals" 4 - local u = require "gopher._utils" 5 1 local M = {} 6 2 7 3 local function intersects(row, col, sRow, sCol, eRow, eCol) ··· 57 53 ---@param pos_row string 58 54 ---@return string 59 55 function M.get_all_nodes(query, lang, _, bufnr, pos_row, _) 56 + local ts_query = require "nvim-treesitter.query" 57 + local parsers = require "nvim-treesitter.parsers" 58 + local locals = require "nvim-treesitter.locals" 59 + 60 60 bufnr = bufnr or 0 61 61 pos_row = pos_row or 30000 62 62 ··· 113 113 ---@param col string 114 114 ---@return table 115 115 function M.nodes_at_cursor(query, default, bufnr, row, col) 116 + local u = require "gopher._utils" 117 + 116 118 bufnr = bufnr or vim.api.nvim_get_current_buf() 117 119 local ft = vim.api.nvim_buf_get_option(bufnr, "ft") 118 120 if row == nil or col == nil then
+1 -2
lua/gopher/comment.lua
··· 1 - local ts_utils = require "gopher._utils.ts" 2 - 3 1 local function generate(row, col) 2 + local ts_utils = require "gopher._utils.ts" 4 3 local comment, ns = nil, nil 5 4 6 5 ns = ts_utils.get_package_node_at_pos(row, col, nil, false)
+3 -2
lua/gopher/dap/init.lua
··· 1 - local cfg = require "gopher.dap.config" 2 - local u = require "gopher._utils" 3 1 local M = {} 4 2 5 3 ---setup nvim-dap for golang using 6 4 function M.setup() 5 + local cfg = require "gopher.dap.config" 6 + local u = require "gopher._utils" 7 + 7 8 local dap = u.sreq "dap" 8 9 dap.adapters.go = cfg.adapter 9 10 dap.configurations.go = cfg.configuration
+5 -3
lua/gopher/gotests.lua
··· 1 - local Job = require "plenary.job" 2 - local ts_utils = require "gopher._utils.ts" 3 - local c = require("gopher.config").config.commands 4 1 local u = require "gopher._utils" 5 2 local M = {} 6 3 7 4 ---@param cmd_args table 8 5 local function run(cmd_args) 6 + local Job = require "plenary.job" 7 + local c = require("gopher.config").config.commands 8 + 9 9 Job:new({ 10 10 command = c.gotests, 11 11 args = cmd_args, ··· 31 31 ---generate unit test for one function 32 32 ---@param parallel boolean 33 33 function M.func_test(parallel) 34 + local ts_utils = require "gopher._utils.ts" 35 + 34 36 local ns = ts_utils.get_func_method_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) 35 37 if ns == nil or ns.name == nil then 36 38 u.notify("cursor on func/method and execute the command again", "info")
+8 -7
lua/gopher/health.lua
··· 1 - local health = vim.health or require "health" 2 - local utils = require "gopher._utils._health" 3 1 local c = require("gopher.config").config.commands 4 2 5 - local requried = "Gopher.nvim will not work without it!" 3 + local requried_for_work_msg = "Gopher.nvim will not work without it!" 6 4 local M = { 7 5 _required = { 8 6 plugins = { 9 - { lib = "plenary", help = requried }, 10 - { lib = "nvim-treesitter", help = requried }, 7 + { lib = "plenary", help = requried_for_work_msg }, 8 + { lib = "nvim-treesitter", help = requried_for_work_msg }, 11 9 { lib = "dap", help = "Required for set upping debugger" }, 12 10 }, 13 11 binarys = { ··· 21 19 } 22 20 23 21 function M.check() 22 + local health = vim.health or require "health" 23 + local u = require "gopher._utils._health" 24 + 24 25 health.report_start "Required plugins" 25 26 for _, plugin in ipairs(M._required.plugins) do 26 - if utils.lualib_is_found(plugin.lib) then 27 + if u.lualib_is_found(plugin.lib) then 27 28 health.report_ok(plugin.lib .. " installed.") 28 29 else 29 30 health.report_error(plugin.lib .. " not found. " .. plugin.help) ··· 32 33 33 34 health.report_start "Required go tools" 34 35 for _, binary in ipairs(M._required.binarys) do 35 - if utils.binary_is_found(binary.bin) then 36 + if u.binary_is_found(binary.bin) then 36 37 health.report_ok(binary.bin .. " installed") 37 38 else 38 39 health.report_warn(binary.bin .. " is not installed but " .. binary.help)
+3 -3
lua/gopher/iferr.lua
··· 1 - local c = require("gopher.config").config.commands 2 - local u = require "gopher._utils" 3 - 4 1 ---Add iferr declaration 5 2 ---That's Lua of vimscript implementation of: 6 3 ---github.com/koron/iferr 7 4 return function() 5 + local c = require("gopher.config").config.commands 6 + local u = require "gopher._utils" 7 + 8 8 local boff = vim.fn.wordcount().cursor_bytes 9 9 local cmd = (c.iferr .. " -pos " .. boff) 10 10 local data = vim.fn.systemlist(cmd, vim.fn.bufnr "%")
+5 -3
lua/gopher/impl.lua
··· 1 - local Job = require "plenary.job" 2 - local ts_utils = require "gopher._utils.ts" 3 - local c = require("gopher.config").config.commands 4 1 local u = require "gopher._utils" 5 2 6 3 ---@return string 7 4 local function get_struct() 5 + local ts_utils = require "gopher._utils.ts" 6 + 8 7 local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) 9 8 if ns == nil then 10 9 u.notify("put cursor on a struct or specify a receiver", "info") ··· 20 19 end 21 20 22 21 return function(...) 22 + local c = require("gopher.config").config.commands 23 + local Job = require "plenary.job" 24 + 23 25 local args = { ... } 24 26 local iface, recv_name = "", "" 25 27 local recv = get_struct()
+3 -2
lua/gopher/installer.lua
··· 1 - local Job = require "plenary.job" 2 - local u = require "gopher._utils" 3 1 local urls = { 4 2 gomodifytags = "github.com/fatih/gomodifytags", 5 3 impl = "github.com/josharian/impl", ··· 10 8 11 9 ---@param pkg string 12 10 local function install(pkg) 11 + local Job = require "plenary.job" 12 + local u = require "gopher._utils" 13 + 13 14 local url = urls[pkg] .. "@latest" 14 15 15 16 Job:new({
+5 -4
lua/gopher/struct_tags.lua
··· 1 - local Job = require "plenary.job" 2 - local ts_utils = require "gopher._utils.ts" 3 - local u = require "gopher._utils" 4 - local c = require("gopher.config").config.commands 5 1 local M = {} 6 2 7 3 local function modify(...) 4 + local ts_utils = require "gopher._utils.ts" 5 + local Job = require "plenary.job" 6 + local c = require("gopher.config").config.commands 7 + local u = require "gopher._utils" 8 + 8 9 local fpath = vim.fn.expand "%" ---@diagnostic disable-line: missing-parameter 9 10 local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) 10 11 if ns == nil then