···201201 -- timeout for running internal commands
202202 timeout = 2000,
203203204204+ -- timeout for running installer commands(e.g :GoDepsInstall, :GoDepsInstallSync)
205205+ installer_timeout = 999999,
206206+207207+ -- restart gopls server after commands like `:GoMod`, `:GoGet`, `:GoWork`
208208+ restart_lsp = false,
209209+204210 commands = {
205211 go = "go",
206212 gomodifytags = "gomodifytags",
+12-1
doc/gopher.nvim.txt
···45454646==============================================================================
4747------------------------------------------------------------------------------
4848+ *config*
4949+ `config`
5050+Type ~
5151+`(gopher.Config)`
5252+5353+------------------------------------------------------------------------------
4854 *gopher.nvim-config*
4955 `default_config`
5056>lua
···5763 ---@type number
5864 timeout = 2000,
59656060- --- timeout for running installer commands(e.g :GoDepsInstall, :GoDepsInstallSync)
6666+ -- timeout for running installer commands(e.g :GoDepsInstall, :GoDepsInstallSync)
6167 installer_timeout = 999999,
6868+6969+ -- restart gopls server after commands like `:GoMod`, `:GoGet`, `:GoWork`
7070+ restart_lsp = false,
62716372 -- user specified paths to binaries
6473 ---@class gopher.ConfigCommand
···96105<
97106Class ~
98107{gopher.Config}
108108+Fields ~
109109+{setup} `(fun(user_config?: gopher.Config))`
99110100111101112==============================================================================
-51
lua/gopher/_utils/gocmd.lua
···11-local r = require "gopher._utils.runner"
22-local c = require("gopher.config").commands
33-local u = require "gopher._utils"
44-local gocmd = {}
55-66----@param args string[]
77----@return string[]
88-local function if_get(args)
99- for i, arg in ipairs(args) do
1010- local m = string.match(arg, "^https://(.*)$") or string.match(arg, "^http://(.*)$") or arg
1111- table.remove(args, i)
1212- table.insert(args, i, m)
1313- end
1414- return args
1515-end
1616-1717----@param args unknown[]
1818----@return string[]
1919-local function if_generate(args)
2020- if #args == 1 and args[1] == "%" then
2121- args[1] = vim.fn.expand "%"
2222- end
2323- return args
2424-end
2525-2626----@param subcmd string
2727----@param args string[]
2828----@return string
2929-function gocmd.run(subcmd, args)
3030- if #args == 0 and subcmd ~= "generate" then
3131- error "please provide any arguments"
3232- end
3333-3434- if subcmd == "get" then
3535- args = if_get(args)
3636- end
3737-3838- if subcmd == "generate" then
3939- args = if_generate(args)
4040- end
4141-4242- local rs = r.sync { c.go, subcmd, unpack(args) }
4343- if rs.code ~= 0 then
4444- error("go " .. subcmd .. " failed: " .. rs.stderr)
4545- end
4646-4747- u.notify(c.go .. " " .. subcmd .. " ran successful")
4848- return rs.stdout
4949-end
5050-5151-return gocmd
···11+local c = require "gopher.config"
22+local u = require "gopher._utils"
33+local lsp = require "gopher._utils.lsp"
44+local r = require "gopher._utils.runner"
55+local go = {}
66+77+local function run(subcmd, args)
88+ local rs = r.sync { c.commands.go, subcmd, unpack(args) }
99+ if rs.code ~= 0 then
1010+ error("go " .. subcmd .. " failed: " .. rs.stderr)
1111+ end
1212+1313+ u.notify(c.commands.go .. " " .. subcmd .. " ran successful")
1414+ return rs.stdout
1515+end
1616+1717+local function restart_lsp()
1818+ if c.restart_lsp then
1919+ lsp.restart()
2020+ end
2121+end
2222+2323+---@param args string[]
2424+function go.get(args)
2525+ for i, arg in ipairs(args) do
2626+ local m = string.match(arg, "^https://(.*)$") or string.match(arg, "^http://(.*)$") or arg
2727+ table.remove(args, i)
2828+ table.insert(args, i, m)
2929+ end
3030+3131+ run("get", args)
3232+ restart_lsp()
3333+end
3434+3535+---@param args string[]
3636+function go.mod(args)
3737+ run("mod", args)
3838+ restart_lsp()
3939+end
4040+4141+---@param args string[]
4242+function go.work(args)
4343+ -- TODO: use `gopls.tidy`
4444+4545+ run("work", args)
4646+ restart_lsp()
4747+end
4848+4949+---Executes `go generate`
5050+---If only argument is `%` it's going to be equivalent to `go generate <path to current file>`
5151+---@param args string[]
5252+function go.generate(args)
5353+ -- TODO: use `gopls.generate`
5454+5555+ if #args == 0 then
5656+ error "please provide arguments"
5757+ end
5858+5959+ if #args == 1 and args[1] == "%" then
6060+ args[1] = vim.fn.expand "%"
6161+ end
6262+6363+ run("generate", args)
6464+end
6565+6666+return go