Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lua/devdocs/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,18 @@ end
---@param slug string Doc to be downloaded
---@param callback function Function called after download
M.DownloadDocs = function(slug, callback)
local downloadLink = 'https://documents.devdocs.io/' .. slug .. '/db.json'
local downloadLink = M.ConstructDownloadLink(slug)
vim.system({
'curl',
'-s',
'-sS',
downloadLink,
}, { text = false }, function(res)
assert(res.code == 0, 'Error downloading docs')
if res.code ~= 0 then
vim.schedule(function()
vim.notify('Error downloading doc for ' .. slug .. ': ' .. res.stderr)
end)
return
end
vim.system({
'jq',
'-c',
Expand Down
14 changes: 9 additions & 5 deletions lua/devdocs/picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,19 @@ M.ShowAllDocs = function()
local docs = D.GetDownloadableDocs()
local items = {}
for _, doc in ipairs(docs) do
table.insert(items, doc.slug)
local text = doc.slug
local size_in_mb = (math.ceil(doc.db_size / (1024 * 1024)))
text = text .. ' (' .. size_in_mb .. 'MB)'
table.insert(items, text)
end
---@diagnostic disable-next-line: redundant-parameter -- documentation error
vim.ui.select(items, { prompt = 'Select Doc to Download' }, function(selected)
if not selected then
vim.ui.select(items, { prompt = 'Select Doc to Download' }, function(_, index)
if not index then
return
end
vim.notify('Downloading docs for ' .. selected, vim.log.levels.INFO)
D.InstallDocs(selected)
local slug = docs[index].slug
vim.notify('Downloading docs for ' .. slug, vim.log.levels.INFO)
D.InstallDocs(slug)
end)
end

Expand Down