forked from maskudo/devdocs.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicker.lua
More file actions
71 lines (67 loc) · 1.89 KB
/
picker.lua
File metadata and controls
71 lines (67 loc) · 1.89 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
local M = {}
local C = require('devdocs.constants')
---@class Docs
local D = require('devdocs.docs')
local H = require('devdocs.helpers')
---Show list of all available docs for a DevDoc
---@param doc doc
---@param callback function?
M.ViewDoc = function(doc, callback)
local files = D.GetDocFiles(doc)
if not files then
vim.notify("Doc doesn't have associated documents", vim.log.levels.WARN)
return
end
local prettifiedFilenames = {}
for i, file in ipairs(files) do
local name = file
name = name:gsub(C.DOCS_DIR .. '/' .. doc, '')
name = name:gsub('/index', '')
name = name:gsub('/', ' ')
name = name:gsub('.md', '')
name = H.toTitleCase(name)
name = vim.fn.trim(name)
if #name == 0 then
name = 'Index'
end
prettifiedFilenames[i] = name
end
vim.ui.select(
prettifiedFilenames,
{ prompt = ('Select Doc' .. '( ' .. doc .. ' )') },
function(_, index)
if not index then
return
end
local file = files[index]
vim.cmd('split ' .. file .. ' | setlocal readonly nomodifiable nobuflisted')
vim.diagnostic.enable(false, { bufnr = 0 })
end
)
end
M.ViewDocs = function()
local docs = D.GetInstalledDocs()
---@diagnostic disable-next-line: redundant-parameter -- documentation error
vim.ui.select(docs, { prompt = 'Select Doc' }, function(selected)
if not selected then
return
end
M.ViewDoc(selected)
end)
end
M.ShowAllDocs = function()
local docs = D.GetDownloadableDocs()
local items = {}
for _, doc in ipairs(docs) do
table.insert(items, doc.slug)
end
---@diagnostic disable-next-line: redundant-parameter -- documentation error
vim.ui.select(items, { prompt = 'Select Doc to Download' }, function(selected)
if not selected then
return
end
vim.notify('Downloading docs for ' .. selected, vim.log.levels.INFO)
D.InstallDocs(selected)
end)
end
return M