aboutsummaryrefslogtreecommitdiffstats
path: root/lua/lspconfig/async.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-08-22 12:23:55 +0100
committerLewis Russell <lewis6991@gmail.com>2023-08-22 13:22:08 +0100
commit875d7e84d01f834f336a33a54673151819bea415 (patch)
tree4cba843a743afba50fc7d1548c8860dbb2661be0 /lua/lspconfig/async.lua
parentrefactor: add sanitize_cmd() (diff)
downloadnvim-lspconfig-875d7e84d01f834f336a33a54673151819bea415.tar
nvim-lspconfig-875d7e84d01f834f336a33a54673151819bea415.tar.gz
nvim-lspconfig-875d7e84d01f834f336a33a54673151819bea415.tar.bz2
nvim-lspconfig-875d7e84d01f834f336a33a54673151819bea415.tar.lz
nvim-lspconfig-875d7e84d01f834f336a33a54673151819bea415.tar.xz
nvim-lspconfig-875d7e84d01f834f336a33a54673151819bea415.tar.zst
nvim-lspconfig-875d7e84d01f834f336a33a54673151819bea415.zip
refactor: move async_run_command()
Diffstat (limited to 'lua/lspconfig/async.lua')
-rw-r--r--lua/lspconfig/async.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/lua/lspconfig/async.lua b/lua/lspconfig/async.lua
index 8a160c82..3421ccc5 100644
--- a/lua/lspconfig/async.lua
+++ b/lua/lspconfig/async.lua
@@ -9,6 +9,42 @@ function M.run(func)
end))
end
+--- @param cmd string|string[]
+--- @return string[]?
+function M.run_command(cmd)
+ local co = assert(coroutine.running())
+
+ local stdout = {}
+ local stderr = {}
+ local jobid = vim.fn.jobstart(cmd, {
+ on_stdout = function(_, data, _)
+ data = table.concat(data, '\n')
+ if #data > 0 then
+ stdout[#stdout + 1] = data
+ end
+ end,
+ on_stderr = function(_, data, _)
+ stderr[#stderr + 1] = table.concat(data, '\n')
+ end,
+ on_exit = function()
+ coroutine.resume(co)
+ end,
+ stdout_buffered = true,
+ stderr_buffered = true,
+ })
+
+ if jobid <= 0 then
+ vim.notify(('[lspconfig] cmd go failed:\n%s'):format(table.concat(stderr, '')), vim.log.levels.WARN)
+ return
+ end
+
+ coroutine.yield()
+ if next(stdout) == nil then
+ return nil
+ end
+ return stdout and stdout or nil
+end
+
function M.reenter()
if vim.in_fast_event() then
local co = assert(coroutine.running())