all repos

gopher.nvim @ 94f5b610124ec2f5ab20510df3252a364baef737

Minimalistic plugin for Go development

gopher.nvim/lua/gopher/gogenerate.lua(view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
local Job = require "plenary.job"
local c = require("gopher.config").config.commands
local u = require "gopher._utils"

---run "go generate"
return function(...)
  local args = { ... }
  if #args == 1 and args[1] == "%" then
    args[1] = vim.fn.expand "%" ---@diagnostic disable-line: missing-parameter
  end

  local cmd_args = vim.list_extend({ "generate" }, args)

  Job:new({
    command = c.go,
    args = cmd_args,
    on_exit = function(_, retval)
      if retval ~= 0 then
        u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
        return
      end

      u.notify("go generate was success runned", "info")
    end,
  }):start()
end