refactor: use vim.system instead of pleanry (#85)

* refactor!: migrate to vim.system

* refactor(gotests): use vim.system

* refactor(iferr): use vim.system

* refactor(impl): use vim.system

* refactor(installer): use vim.system and add sync mode

* test: fix gotests' tests

* refactor(struct_tags): use vim.system

* chore(ci): install all deps explicitly

* refactor(installer)!: add sync as an option

* docs: update readme
This commit is contained in:
Smirnov Oleksandr 2025-03-02 16:31:50 +02:00 committed by GitHub
parent 837897a79d
commit 6016ca57d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 169 additions and 126 deletions

View file

@ -3,8 +3,9 @@ local log = require "gopher._utils.log"
local utils = {}
---@param msg string
---@param lvl number
---@param lvl? number
function utils.deferred_notify(msg, lvl)
lvl = lvl or vim.log.levels.INFO
vim.defer_fn(function()
vim.notify(msg, lvl, {
title = c.___plugin_name,
@ -23,4 +24,22 @@ function utils.notify(msg, lvl)
log.debug(msg)
end
---@param path string
---@return string
function utils.readfile_joined(path)
return table.concat(vim.fn.readfile(path), "\n")
end
---@param t string[]
---@return string[]
function utils.remove_empty_lines(t)
local res = {}
for _, line in ipairs(t) do
if line ~= "" then
table.insert(res, line)
end
end
return res
end
return utils

View file

@ -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