Skip to content

Delete docs #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 9, 2025
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
15 changes: 11 additions & 4 deletions doc/devdocs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Class ~
`M.GetAllDocs`
all downloadable devdocs
Return ~
{doc:Devdoc}
`({doc:Devdoc})`

------------------------------------------------------------------------------
*M.GetInstalledDocs*
`M.GetInstalledDocs`
all installed docs
Return ~
{doc: doc}
`({doc: doc})`

------------------------------------------------------------------------------
*M.GetDoc()*
Expand All @@ -40,12 +40,19 @@ Install Doc
@async
@param doc string

------------------------------------------------------------------------------
*M.DeleteDoc()*
`M.DeleteDoc`({doc})
Delete Doc
Parameters ~
{doc} `(string)`

------------------------------------------------------------------------------
*M.GetDownloadLinkForDoc()*
`M.GetDownloadLinkForDoc`({slug})
download link for a doc(slug)
Parameters ~
{slug} doc
{slug} `(doc)`
Return ~
`(string)`

Expand All @@ -55,7 +62,7 @@ Return ~
devdoc metadata

Parameters ~
{callback} `(function)` | nil
{callback} `(function | nil)`


vim:tw=78:ts=8:noet:ft=help:norl:
1 change: 1 addition & 0 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
M devdocs.txt /*M*
M.DeleteDoc() devdocs.txt /*M.DeleteDoc()*
M.FetchDevdocs() devdocs.txt /*M.FetchDevdocs()*
M.GetAllDocs devdocs.txt /*M.GetAllDocs*
M.GetDoc() devdocs.txt /*M.GetDoc()*
Expand Down
16 changes: 16 additions & 0 deletions lua/devdocs/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,22 @@ M.ValidateDocsAvailability = function(docs)
return { validDocs = validDocs, invalidDocs = invalidDocs }
end

M.DeleteDoc = function(doc)
local docFile = C.DOCS_DIR .. '/' .. doc .. '.json'
local docDir = C.DOCS_DIR .. '/' .. doc

local deleteExtracted = vim.fn.delete(docDir, 'rf')
local deleteDownloaded = vim.fn.delete(docFile)

assert(deleteExtracted == 0, 'Error deleting extracted files for ' .. doc)
assert(deleteDownloaded == 0, 'Error deleting downloaded files for ' .. doc)

require('devdocs.state'):Update(doc, {
downloaded = false,
extracted = false,
})
end

---Returns doc filepaths
---@param doc doc
---@return string[] | nil
Expand Down
12 changes: 12 additions & 0 deletions lua/devdocs/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ local function setupCommands()
else
P.ViewDoc(doc)
end
elseif subcmd == 'delete' then
local doc = opts.fargs[2]
if doc then
return M.DeleteDoc(doc)
end
P.DeleteDoc()
end
end, { nargs = '*' })
end
Expand Down Expand Up @@ -157,6 +163,12 @@ M.InstallDoc = function(doc)
return D.InstallDocs(doc)
end

--- Delete Doc
---@param doc string
M.DeleteDoc = function(doc)
D.DeleteDoc(doc)
end

---Get download link for a doc(slug)
---@param slug doc
---@return string
Expand Down
11 changes: 11 additions & 0 deletions lua/devdocs/picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ M.ViewDocs = function()
end)
end

M.DeleteDoc = function()
local docs = D.GetInstalledDocs()
vim.ui.select(docs, { prompt = 'Select Doc to Delete' }, function(selected)
if not selected then
return
end
D.DeleteDoc(selected)
vim.notify('Deleted docs for ' .. selected .. ' successfully', vim.log.levels.INFO)
end)
end

M.ShowAllDocs = function()
local docs = D.GetDownloadableDocs()
local items = {}
Expand Down