This repository was archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathinit.lua
More file actions
106 lines (86 loc) · 3.03 KB
/
init.lua
File metadata and controls
106 lines (86 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
local M = {}
local list = require("nvim-devdocs.list")
local notify = require("nvim-devdocs.notify")
local pickers = require("nvim-devdocs.pickers")
local operations = require("nvim-devdocs.operations")
local config = require("nvim-devdocs.config")
local completion = require("nvim-devdocs.completion")
local filetypes = require("nvim-devdocs.filetypes")
M.fetch_registery = function() operations.fetch() end
M.install_doc = function(args)
if vim.tbl_isempty(args.fargs) then
pickers.installation_picker()
else
operations.install_args(args.fargs, true)
end
end
M.uninstall_doc = function(args)
if vim.tbl_isempty(args.fargs) then pickers.uninstallation_picker() end
for _, arg in pairs(args.fargs) do
operations.uninstall(arg)
end
end
M.open_doc = function(args, float)
if vim.tbl_isempty(args.fargs) then
local entries = operations.get_all_entries()
pickers.open_picker(entries, float)
else
local alias = args.fargs[1]
pickers.open_picker_alias(alias, float)
end
end
M.open_doc_float = function(args) M.open_doc(args, true) end
M.open_doc_current_file = function(float)
local filetype = vim.bo.filetype
local alias = filetypes[filetype] or filetype
pickers.open_picker_alias(alias, float)
end
M.update = function(args)
if vim.tbl_isempty(args.fargs) then
pickers.update_picker()
else
operations.install_args(args.fargs, true, true)
end
end
M.update_all = function()
local updatable = list.get_updatable()
if vim.tbl_isempty(updatable) then
notify.log("All documentations are up to date")
else
operations.install_args(updatable, true, true)
end
end
M.keywordprg = function(args)
local keyword = args.fargs[1]
if keyword then
operations.keywordprg(keyword)
else
notify.log("No keyword provided")
end
end
M.grep = function(args)
if vim.tbl_isempty(args.fargs) then
pickers.open_picker_grep("")
else
local alias = args.fargs[1]
pickers.open_picker_grep(alias)
end
end
M.setup = function(opts)
config.setup(opts)
local ensure_installed = config.options.ensure_installed
vim.defer_fn(function() operations.install_args(ensure_installed) end, 3000)
local cmd = vim.api.nvim_create_user_command
cmd("DevdocsFetch", M.fetch_registery, {})
cmd("DevdocsInstall", M.install_doc, { nargs = "*", complete = completion.get_non_installed })
cmd("DevdocsUninstall", M.uninstall_doc, { nargs = "*", complete = completion.get_installed })
cmd("DevdocsOpen", M.open_doc, { nargs = "?", complete = completion.get_installed })
cmd("DevdocsOpenFloat", M.open_doc_float, { nargs = "?", complete = completion.get_installed })
cmd("DevdocsGrep", M.grep, { nargs = "?", complete = completion.get_installed })
cmd("DevdocsOpenCurrent", function() M.open_doc_current_file() end, {})
cmd("DevdocsOpenCurrentFloat", function() M.open_doc_current_file(true) end, {})
cmd("DevdocsKeywordprg", M.keywordprg, { nargs = "?" })
cmd("DevdocsUpdate", M.update, { nargs = "*", complete = completion.get_updatable })
cmd("DevdocsUpdateAll", M.update_all, {})
end
return M