Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit d6bd4dc

Browse files
update: add update picker
add telescope picker for :DevdocsUpdate
1 parent 15e36af commit d6bd4dc

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

lua/nvim-devdocs/init.lua

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ local pickers = require("nvim-devdocs.pickers")
88
local operations = require("nvim-devdocs.operations")
99
local plugin_config = require("nvim-devdocs.config").get()
1010

11+
local registery_path = path:new(plugin_config.dir_path, "registery.json")
12+
1113
M.fetch_registery = function() operations.fetch() end
1214

1315
M.install_doc = function(args)
14-
local registery_path = path:new(plugin_config.dir_path, "registery.json")
15-
1616
if registery_path:exists() then
1717
if vim.tbl_isempty(args.fargs) then pickers.installation_picker() end
1818

@@ -61,18 +61,16 @@ M.open_doc_float = function(args)
6161
end
6262

6363
M.update = function(args)
64-
local registery_path = path:new(plugin_config.dir_path, "registery.json")
65-
6664
if registery_path:exists() then
65+
if vim.tbl_isempty(args.fargs) then pickers.update_picker() end
66+
6767
operations.install_args(args.fargs, true, true)
6868
else
6969
notify.log_err("DevDocs registery not found, please run :DevdocsFetch")
7070
end
7171
end
7272

7373
M.update_all = function()
74-
local registery_path = path:new(plugin_config.dir_path, "registery.json")
75-
7674
if registery_path:exists() then
7775
local updatable = list.get_updatable()
7876

lua/nvim-devdocs/operations.lua

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local M = {}
33
local curl = require("plenary.curl")
44
local path = require("plenary.path")
55

6+
local list = require("nvim-devdocs.list")
67
local notify = require("nvim-devdocs.notify")
78
local transpiler = require("nvim-devdocs.transpiler")
89
local plugin_config = require("nvim-devdocs.config").get()
@@ -83,24 +84,29 @@ end
8384
M.install_args = function(args, verbose, is_update)
8485
if not registery_path:exists() then return end
8586

87+
local updatable = list.get_updatable()
8688
local content = registery_path:read()
8789
local parsed = vim.fn.json_decode(content)
8890

8991
for _, arg in ipairs(args) do
90-
local slug = arg:gsub("-", "~")
91-
local data = {}
92-
93-
for _, entry in ipairs(parsed) do
94-
if entry.slug == slug then
95-
data = entry
96-
break
92+
if is_update and not vim.tbl_contains(updatable, arg) then
93+
notify.log(arg .. " documentation is already up to date")
94+
else
95+
local slug = arg:gsub("-", "~")
96+
local data = {}
97+
98+
for _, entry in ipairs(parsed) do
99+
if entry.slug == slug then
100+
data = entry
101+
break
102+
end
97103
end
98-
end
99104

100-
if vim.tbl_isempty(data) then
101-
notify.log_err("No documentation available for " .. arg)
102-
else
103-
M.install(data, verbose, is_update)
105+
if vim.tbl_isempty(data) then
106+
notify.log_err("No documentation available for " .. arg)
107+
else
108+
M.install(data, verbose, is_update)
109+
end
104110
end
105111
end
106112
end

lua/nvim-devdocs/pickers.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ M.uninstallation_picker = function()
7777
picker:find()
7878
end
7979

80+
M.update_picker = function()
81+
local installed = list.get_updatable()
82+
local picker = new_docs_picker("Update documentation", installed, metadata_priewer, function()
83+
actions.select_default:replace(function(prompt_bufnr)
84+
local selection = action_state.get_selected_entry()
85+
local alias = selection.value.slug:gsub("~", "-")
86+
87+
actions.close(prompt_bufnr)
88+
operations.install(alias, true, true)
89+
end)
90+
return true
91+
end)
92+
93+
picker:find()
94+
end
95+
8096
M.open_doc_entry_picker = function(entries, float)
8197
local picker = pickers.new(plugin_config.telescope, {
8298
prompt_title = "Select an entry",

plugin/nvim-devdocs.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ M.setup = function(opts)
1818
cmd("DevdocsUninstall", M.uninstall_doc, { nargs = "*", complete = completion.get_installed })
1919
cmd("DevdocsOpen", M.open_doc, { nargs = "?", complete = completion.get_installed })
2020
cmd("DevdocsOpenFloat", M.open_doc_float, { nargs = "?", complete = completion.get_installed })
21-
cmd("DevdocsUpdate", M.update, { nargs = "+", complete = completion.get_updatable })
21+
cmd("DevdocsUpdate", M.update, { nargs = "*", complete = completion.get_updatable })
2222
cmd("DevdocsUpdateAll", M.update_all, {})
2323
end
2424

0 commit comments

Comments
 (0)