diff --git a/README.md b/README.md index 49cb8ed..04f44c2 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,8 @@ Requirements: { "olexsmir/gopher.nvim", ft = "go", - -- branch = "develop", -- if you want develop branch - -- keep in mind, it might break everything + -- branch = "develop" dependencies = { - "nvim-lua/plenary.nvim", "nvim-treesitter/nvim-treesitter", }, -- (optional) will update plugin's deps on every update diff --git a/lua/gopher/_utils/runner/init.lua b/lua/gopher/_utils/runner/init.lua index 3c08f7f..15eaa42 100644 --- a/lua/gopher/_utils/runner/init.lua +++ b/lua/gopher/_utils/runner/init.lua @@ -1,33 +1,39 @@ -local Job = require "plenary.job" +local c = require "gopher.config" local runner = {} ---@class gopher.RunnerOpts ----@field args? string[] ----@field cwd? string? ----@field on_exit? fun(data:string, status:number) +---@field cwd? string +---@field timeout? number +---@field stdin? boolean|string|string[] +---@field text? boolean ----@param cmd string ----@param opts gopher.RunnerOpts ----@return string[]|nil +---@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) - local output - Job:new({ - command = cmd, - args = opts.args, - cwd = opts.cwd, - on_stderr = function(_, data) - vim.print(data) - end, - on_exit = function(data, status) - 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 + 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 diff --git a/lua/gopher/config.lua b/lua/gopher/config.lua index 18c08c3..94dbab9 100644 --- a/lua/gopher/config.lua +++ b/lua/gopher/config.lua @@ -33,6 +33,10 @@ local default_config = { ---@type number log_level = vim.log.levels.INFO, + -- timeout for running commands + ---@type number + timeout = 2000, + -- user specified paths to binaries ---@class gopher.ConfigCommand commands = { diff --git a/lua/gopher/health.lua b/lua/gopher/health.lua index 9fa0bed..4438c8a 100644 --- a/lua/gopher/health.lua +++ b/lua/gopher/health.lua @@ -4,9 +4,7 @@ local u = require "gopher._utils.health_util" local deps = { plugin = { - { lib = "dap", msg = "required for `gopher.dap`", optional = true }, - { lib = "plenary", msg = "required for everything in gopher.nvim", optional = false }, - { lib = "nvim-treesitter", msg = "required for everything in gopher.nvim", optional = false }, + { lib = "nvim-treesitter", msg = "required for everything in gopher.nvim" }, }, bin = { { @@ -14,17 +12,17 @@ local deps = { msg = "required for `:GoGet`, `:GoMod`, `:GoGenerate`, `:GoWork`, `:GoInstallDeps`", optional = false, }, - { bin = cmd.gomodifytags, msg = "required for `:GoTagAdd`, `:GoTagRm`", optional = false }, - { bin = cmd.impl, msg = "required for `:GoImpl`", optional = false }, - { bin = cmd.iferr, msg = "required for `:GoIfErr`", optional = false }, + { bin = cmd.gomodifytags, msg = "required for `:GoTagAdd`, `:GoTagRm`", optional = true }, + { bin = cmd.impl, msg = "required for `:GoImpl`", optional = true }, + { bin = cmd.iferr, msg = "required for `:GoIfErr`", optional = true }, { bin = cmd.gotests, msg = "required for `:GoTestAdd`, `:GoTestsAll`, `:GoTestsExp`", - optional = false, + optional = true, }, }, treesitter = { - { parser = "go", msg = "required for `gopher.nvim`", optional = false }, + { parser = "go", msg = "required for `gopher.nvim`" }, }, } @@ -34,11 +32,7 @@ function health.check() if u.is_lualib_found(plugin.lib) then u.ok(plugin.lib .. " installed") else - if plugin.optional then - u.warn(plugin.lib .. " not found, " .. plugin.msg) - else - u.error(plugin.lib .. " not found, " .. plugin.msg) - end + u.error(plugin.lib .. " not found, " .. plugin.msg) end end diff --git a/scripts/minimal_init.lua b/scripts/minimal_init.lua index e59f06a..6b4a032 100644 --- a/scripts/minimal_init.lua +++ b/scripts/minimal_init.lua @@ -8,17 +8,23 @@ local function install_plug(plugin) local package_root = root ".tests/site/pack/deps/start/" if not vim.uv.fs_stat(package_root .. name) then print("Installing " .. plugin) - vim.fn.mkdir(package_root, "p") - vim.fn.system { - "git", - "clone", - "--depth=1", - "https://github.com/" .. plugin .. ".git", - package_root .. "/" .. name, - } + vim + .system({ + "git", + "clone", + "--depth=1", + "https://github.com/" .. plugin .. ".git", + package_root .. "/" .. name, + }) + :wait() 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_DATA_HOME = root ".tests/data" vim.env.XDG_STATE_HOME = root ".tests/state" @@ -29,11 +35,6 @@ vim.opt.runtimepath:append(root()) vim.opt.packpath = { root ".tests/site" } 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 require("nvim-treesitter.install").ensure_installed_sync "go"