diff --git a/doc/devdocs.txt b/doc/devdocs.txt index 2a9471c..076bbde 100644 --- a/doc/devdocs.txt +++ b/doc/devdocs.txt @@ -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()* @@ -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)` @@ -55,7 +62,7 @@ Return ~ devdoc metadata Parameters ~ -{callback} `(function)` | nil +{callback} `(function | nil)` vim:tw=78:ts=8:noet:ft=help:norl: \ No newline at end of file diff --git a/doc/tags b/doc/tags index c569ddf..95d0414 100644 --- a/doc/tags +++ b/doc/tags @@ -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()* diff --git a/lua/devdocs/docs.lua b/lua/devdocs/docs.lua index f954fce..3b6eebc 100644 --- a/lua/devdocs/docs.lua +++ b/lua/devdocs/docs.lua @@ -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 diff --git a/lua/devdocs/init.lua b/lua/devdocs/init.lua index ef7bb40..dba0732 100644 --- a/lua/devdocs/init.lua +++ b/lua/devdocs/init.lua @@ -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 @@ -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 diff --git a/lua/devdocs/picker.lua b/lua/devdocs/picker.lua index 13c8833..fe0add1 100644 --- a/lua/devdocs/picker.lua +++ b/lua/devdocs/picker.lua @@ -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 = {}