refactor!: migrate to vim.system
This commit is contained in:
parent
837897a79d
commit
ec91e6efcc
5 changed files with 57 additions and 54 deletions
|
|
@ -20,10 +20,8 @@ Requirements:
|
||||||
{
|
{
|
||||||
"olexsmir/gopher.nvim",
|
"olexsmir/gopher.nvim",
|
||||||
ft = "go",
|
ft = "go",
|
||||||
-- branch = "develop", -- if you want develop branch
|
-- branch = "develop"
|
||||||
-- keep in mind, it might break everything
|
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"nvim-lua/plenary.nvim",
|
|
||||||
"nvim-treesitter/nvim-treesitter",
|
"nvim-treesitter/nvim-treesitter",
|
||||||
},
|
},
|
||||||
-- (optional) will update plugin's deps on every update
|
-- (optional) will update plugin's deps on every update
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,39 @@
|
||||||
local Job = require "plenary.job"
|
local c = require "gopher.config"
|
||||||
local runner = {}
|
local runner = {}
|
||||||
|
|
||||||
---@class gopher.RunnerOpts
|
---@class gopher.RunnerOpts
|
||||||
---@field args? string[]
|
---@field cwd? string
|
||||||
---@field cwd? string?
|
---@field timeout? number
|
||||||
---@field on_exit? fun(data:string, status:number)
|
---@field stdin? boolean|string|string[]
|
||||||
|
---@field text? boolean
|
||||||
|
|
||||||
---@param cmd string
|
---@param cmd (string|number)[]
|
||||||
---@param opts gopher.RunnerOpts
|
---@param on_exit fun(out:vim.SystemCompleted)
|
||||||
---@return string[]|nil
|
---@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)
|
function runner.sync(cmd, opts)
|
||||||
local output
|
opts = opts or {}
|
||||||
Job:new({
|
return vim
|
||||||
command = cmd,
|
.system(cmd, {
|
||||||
args = opts.args,
|
cwd = opts.cwd or nil,
|
||||||
cwd = opts.cwd,
|
timeout = opts.timeout or c.timeout,
|
||||||
on_stderr = function(_, data)
|
stdin = opts.stdin or nil,
|
||||||
vim.print(data)
|
text = opts.text or true,
|
||||||
end,
|
})
|
||||||
on_exit = function(data, status)
|
:wait()
|
||||||
output = data:result()
|
|
||||||
vim.schedule(function()
|
|
||||||
if opts.on_exit then
|
|
||||||
opts.on_exit(output, status)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end,
|
|
||||||
}):sync(60000 --[[1 min]])
|
|
||||||
return output
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return runner
|
return runner
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,10 @@ local default_config = {
|
||||||
---@type number
|
---@type number
|
||||||
log_level = vim.log.levels.INFO,
|
log_level = vim.log.levels.INFO,
|
||||||
|
|
||||||
|
-- timeout for running commands
|
||||||
|
---@type number
|
||||||
|
timeout = 2000,
|
||||||
|
|
||||||
-- user specified paths to binaries
|
-- user specified paths to binaries
|
||||||
---@class gopher.ConfigCommand
|
---@class gopher.ConfigCommand
|
||||||
commands = {
|
commands = {
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@ local u = require "gopher._utils.health_util"
|
||||||
|
|
||||||
local deps = {
|
local deps = {
|
||||||
plugin = {
|
plugin = {
|
||||||
{ lib = "dap", msg = "required for `gopher.dap`", optional = true },
|
{ lib = "nvim-treesitter", msg = "required for everything in gopher.nvim" },
|
||||||
{ lib = "plenary", msg = "required for everything in gopher.nvim", optional = false },
|
|
||||||
{ lib = "nvim-treesitter", msg = "required for everything in gopher.nvim", optional = false },
|
|
||||||
},
|
},
|
||||||
bin = {
|
bin = {
|
||||||
{
|
{
|
||||||
|
|
@ -14,17 +12,17 @@ local deps = {
|
||||||
msg = "required for `:GoGet`, `:GoMod`, `:GoGenerate`, `:GoWork`, `:GoInstallDeps`",
|
msg = "required for `:GoGet`, `:GoMod`, `:GoGenerate`, `:GoWork`, `:GoInstallDeps`",
|
||||||
optional = false,
|
optional = false,
|
||||||
},
|
},
|
||||||
{ bin = cmd.gomodifytags, msg = "required for `:GoTagAdd`, `:GoTagRm`", optional = false },
|
{ bin = cmd.gomodifytags, msg = "required for `:GoTagAdd`, `:GoTagRm`", optional = true },
|
||||||
{ bin = cmd.impl, msg = "required for `:GoImpl`", optional = false },
|
{ bin = cmd.impl, msg = "required for `:GoImpl`", optional = true },
|
||||||
{ bin = cmd.iferr, msg = "required for `:GoIfErr`", optional = false },
|
{ bin = cmd.iferr, msg = "required for `:GoIfErr`", optional = true },
|
||||||
{
|
{
|
||||||
bin = cmd.gotests,
|
bin = cmd.gotests,
|
||||||
msg = "required for `:GoTestAdd`, `:GoTestsAll`, `:GoTestsExp`",
|
msg = "required for `:GoTestAdd`, `:GoTestsAll`, `:GoTestsExp`",
|
||||||
optional = false,
|
optional = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
treesitter = {
|
treesitter = {
|
||||||
{ parser = "go", msg = "required for `gopher.nvim`", optional = false },
|
{ parser = "go", msg = "required for `gopher.nvim`" },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,14 +31,10 @@ function health.check()
|
||||||
for _, plugin in ipairs(deps.plugin) do
|
for _, plugin in ipairs(deps.plugin) do
|
||||||
if u.is_lualib_found(plugin.lib) then
|
if u.is_lualib_found(plugin.lib) then
|
||||||
u.ok(plugin.lib .. " installed")
|
u.ok(plugin.lib .. " installed")
|
||||||
else
|
|
||||||
if plugin.optional then
|
|
||||||
u.warn(plugin.lib .. " not found, " .. plugin.msg)
|
|
||||||
else
|
else
|
||||||
u.error(plugin.lib .. " not found, " .. plugin.msg)
|
u.error(plugin.lib .. " not found, " .. plugin.msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
u.start "required binaries"
|
u.start "required binaries"
|
||||||
u.info "all those binaries can be installed by `:GoInstallDeps`"
|
u.info "all those binaries can be installed by `:GoInstallDeps`"
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,23 @@ local function install_plug(plugin)
|
||||||
local package_root = root ".tests/site/pack/deps/start/"
|
local package_root = root ".tests/site/pack/deps/start/"
|
||||||
if not vim.uv.fs_stat(package_root .. name) then
|
if not vim.uv.fs_stat(package_root .. name) then
|
||||||
print("Installing " .. plugin)
|
print("Installing " .. plugin)
|
||||||
vim.fn.mkdir(package_root, "p")
|
vim
|
||||||
vim.fn.system {
|
.system({
|
||||||
"git",
|
"git",
|
||||||
"clone",
|
"clone",
|
||||||
"--depth=1",
|
"--depth=1",
|
||||||
"https://github.com/" .. plugin .. ".git",
|
"https://github.com/" .. plugin .. ".git",
|
||||||
package_root .. "/" .. name,
|
package_root .. "/" .. name,
|
||||||
}
|
})
|
||||||
|
:wait()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
install_plug "nvim-lua/plenary.nvim"
|
||||||
|
install_plug "nvim-treesitter/nvim-treesitter"
|
||||||
|
install_plug "echasnovski/mini.doc" -- used for docs generation
|
||||||
|
install_plug "echasnovski/mini.test"
|
||||||
|
|
||||||
vim.env.XDG_CONFIG_HOME = root ".tests/config"
|
vim.env.XDG_CONFIG_HOME = root ".tests/config"
|
||||||
vim.env.XDG_DATA_HOME = root ".tests/data"
|
vim.env.XDG_DATA_HOME = root ".tests/data"
|
||||||
vim.env.XDG_STATE_HOME = root ".tests/state"
|
vim.env.XDG_STATE_HOME = root ".tests/state"
|
||||||
|
|
@ -29,11 +35,6 @@ vim.opt.runtimepath:append(root())
|
||||||
vim.opt.packpath = { root ".tests/site" }
|
vim.opt.packpath = { root ".tests/site" }
|
||||||
vim.notify = print
|
vim.notify = print
|
||||||
|
|
||||||
install_plug "nvim-lua/plenary.nvim"
|
|
||||||
install_plug "nvim-treesitter/nvim-treesitter"
|
|
||||||
install_plug "echasnovski/mini.doc" -- used for docs generation
|
|
||||||
install_plug "echasnovski/mini.test"
|
|
||||||
|
|
||||||
-- install go treesitter parse
|
-- install go treesitter parse
|
||||||
require("nvim-treesitter.install").ensure_installed_sync "go"
|
require("nvim-treesitter.install").ensure_installed_sync "go"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue