diff options
| author | Raphael <glepnir@neovim.pro> | 2023-06-18 16:53:49 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-18 16:53:49 +0800 |
| commit | 9a2cc569c88662fa41d414bdb65b13ea72349f86 (patch) | |
| tree | fac7323b154c261ca8254f919a3192ae46d2dbba /lua/lspconfig/util.lua | |
| parent | docs: update server_configurations.md (diff) | |
| download | nvim-lspconfig-9a2cc569c88662fa41d414bdb65b13ea72349f86.tar nvim-lspconfig-9a2cc569c88662fa41d414bdb65b13ea72349f86.tar.gz nvim-lspconfig-9a2cc569c88662fa41d414bdb65b13ea72349f86.tar.bz2 nvim-lspconfig-9a2cc569c88662fa41d414bdb65b13ea72349f86.tar.lz nvim-lspconfig-9a2cc569c88662fa41d414bdb65b13ea72349f86.tar.xz nvim-lspconfig-9a2cc569c88662fa41d414bdb65b13ea72349f86.tar.zst nvim-lspconfig-9a2cc569c88662fa41d414bdb65b13ea72349f86.zip | |
perf(gopls): make get go mod cache path async (#2673)
Diffstat (limited to 'lua/lspconfig/util.lua')
| -rw-r--r-- | lua/lspconfig/util.lua | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 6a231308..f4e2ab78 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -580,4 +580,38 @@ function M.strip_archive_subpath(path) return path end +function M.async_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 + return M |
