[mirror] Make your go dev experience better github.com/olexsmir/gopher.nvim
neovim golang
at main 1.2 kB view raw
1local c = require "gopher.config" 2local u = require "gopher._utils" 3local r = require "gopher._utils.runner" 4local go = {} 5 6local function run(subcmd, args) 7 local rs = r.sync { c.commands.go, subcmd, unpack(args) } 8 if rs.code ~= 0 then 9 error("go " .. subcmd .. " failed: " .. rs.stderr) 10 end 11 12 u.notify(c.commands.go .. " " .. subcmd .. " ran successful") 13 return rs.stdout 14end 15 16---@param args string[] 17function go.get(args) 18 for i, arg in ipairs(args) do 19 local m = string.match(arg, "^https://(.*)$") or string.match(arg, "^http://(.*)$") or arg 20 table.remove(args, i) 21 table.insert(args, i, m) 22 end 23 24 run("get", args) 25end 26 27---@param args string[] 28function go.mod(args) 29 run("mod", args) 30end 31 32---@param args string[] 33function go.work(args) 34 -- TODO: use `gopls.tidy` 35 36 run("work", args) 37end 38 39---Executes `go generate` 40---If only argument is `%` it's going to be equivalent to `go generate <path to current file>` 41---@param args string[] 42function go.generate(args) 43 -- TODO: use `gopls.generate` 44 45 if #args == 0 then 46 error "please provide arguments" 47 end 48 49 if #args == 1 and args[1] == "%" then 50 args[1] = vim.fn.expand "%" 51 end 52 53 run("generate", args) 54end 55 56return go