all repos

gopher.nvim @ dec6ff445fad35f8091d008992f3c1a3b1abfa9a

Minimalistic plugin for Go development

gopher.nvim/lua/gopher/_utils/runner.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
27
28
29
30
31
32
33
34
35
36
37
38
39
local c = require "gopher.config"
local runner = {}

---@class gopher.RunnerOpts
---@field cwd? string
---@field timeout? number
---@field stdin? boolean|string|string[]
---@field text? boolean

---@param cmd (string|number)[]
---@param on_exit fun(out:vim.SystemCompleted)
---@param opts? gopher.RunnerOpts
---@return vim.SystemObj
function runner.async(cmd, on_exit, opts)
  opts = opts or {}
  return vim.system(cmd, {
    cwd = opts.cwd or nil,
    timeout = opts.timeout or c.timeout,
    stdin = opts.stdin or nil,
    text = opts.text or true,
  }, on_exit)
end

---@param cmd (string|number)[]
---@param opts? gopher.RunnerOpts
---@return vim.SystemCompleted
function runner.sync(cmd, opts)
  opts = opts or {}
  return vim
    .system(cmd, {
      cwd = opts.cwd or nil,
      timeout = opts.timeout or c.timeout,
      stdin = opts.stdin or nil,
      text = opts.text or true,
    })
    :wait()
end

return runner