Question about using plugin's internal functions #856
-
Hi, I'm trying to use some internal functions from the plugin to complement a LSP server and I'm not sure how to deal with the futures/promises that all functions return. Basically for rust-tools there's a possibility to improve the debugging experience by providing the location of a vscode extension installation to the LSP client. I was willing to automate this for:
Instead of implementing everything by hand I thought of using functions of lsp installer but I'm stuck on how to deal with the futures. Basically I start by checking if there are updates. I basically create a folder with the version as the name. I the All this calls from what I could see are Any help would be appreciated. Here's my current code... I only get the prints of "install folder created" and "finished". local repo = 'vadimcn/vscode-lldb'
local github_client = require('nvim-lsp-installer.core.managers.github.client')
local spawn = require('nvim-lsp-installer.core.spawn')
local async = require('nvim-lsp-installer.core.async')
local fetch = require('nvim-lsp-installer.core.fetch')
local install_path = vim.fn.stdpath('data') .. '/vscode-lldb/'
local function exists(file)
local ok, err, code = os.rename(file, file)
if not ok then
if code == 13 then
-- Permission denied, but it exists
return true
end
end
return ok, err
end
local function check_download_new_release()
local latest = github_client.fetch_latest_release(repo)
local tag_name = latest.tag_name
print('tag name ' .. tag_name)
if not exists(install_path .. tag_name) then
spawn.rm({ '-rf ', install_path .. '*' })
spawn.mkdir({ install_path .. tag_name })
print('directories created')
local download_url = ('https://github.com/%s/releases/download/%s/%s'):format(
repo,
tag_name,
'codelldb-aarch64-darwin.vsix'
)
fetch(download_url, {
out_file = install_path .. 'codelldb.zip',
})
:map_err(function(err)
return ('Failed to download file %q.\n%s'):format(download_url, err)
end)
:get_or_throw()
return install_path .. tag_name, install_path .. 'codelldb.zip'
else
return false
end
end
local function create_install_dir()
if not exists(install_path) then
spawn.mkdir({ install_path })
end
end
local function install(file, target_dir)
spawn.unzip({ '-j', file, 'extension/adapter/codelldb', 'extension/lldb/lib/liblldb.dylib', '-d', target_dir })
spawn.rm({ '-rf', file })
end
return {
install_codelldb = function()
async.run(function()
create_install_dir()
print('install folder created')
local new_release_dir, zip_file = check_download_new_release()
if new_release_dir then
print('installing')
install(zip_file, new_release_dir)
end
end, function()
print('finished')
end)
end,
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
Hello! I just happened to make https://github.com/williamboman/mason.nvim public the other day. It provides
The second argument to return {
install_codelldb = async.scope(function()
create_install_dir()
print('install folder created')
local new_release_dir, zip_file = check_download_new_release()
if new_release_dir then
print('installing')
install(zip_file, new_release_dir)
end)
end),
} |
Beta Was this translation helpful? Give feedback.
Hello! I just happened to make https://github.com/williamboman/mason.nvim public the other day. It provides
codelldb
as a package available for installation, might be of interest.The second argument to
async.run()
is a callback that'll be invoked with 2 arguments pcall-style(success, value)
. Most likely there's an error occurring somewhere, which won't bubble up to the main event loop. I'd actually recommend using theasync.scope
function instead if you don't need to access the return value of the async function - it will ensure to log errors for you: