Skip to content
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
19 changes: 12 additions & 7 deletions lua/devdocs/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ local C = require('devdocs.constants')

---Creates a directory using a shell command native to the platform
---@param dir string Directory to create
M.Mkdir = function (dir)
M.Mkdir = function(dir)
os.execute('mkdir -p ' .. dir)
end

-- Update for windows
if vim.fn.has('win32') == 1 or vim.fn.has('win64') == 1 or os.getenv('OS') == 'Windows_NT' then
M.Mkdir = function (dir)
M.Mkdir = function(dir)
os.execute(
"powershell.exe -NoLogo -NonInteractive -NoProfile -Command New-Item -ErrorAction SilentlyContinue -ItemType Directory -Force -Path '" .. dir .."'"
"powershell.exe -NoLogo -NonInteractive -NoProfile -Command New-Item -ErrorAction SilentlyContinue -ItemType Directory -Force -Path '"
.. dir
.. "'"
)
end
end
Expand All @@ -42,8 +44,8 @@ end
M.InitializeDirectories = function()
M.Mkdir(C.DEVDOCS_DATA_DIR)
M.Mkdir(C.DOCS_DIR)
local dataDirExists = vim.fn.mkdir(C.DEVDOCS_DATA_DIR, 'p')
local docsDirExists = vim.fn.mkdir(C.DOCS_DIR, 'p')
local dataDirExists = vim.fn.mkdir(C.DEVDOCS_DATA_DIR, 'p') == 1
local docsDirExists = vim.fn.mkdir(C.DOCS_DIR, 'p') == 1
assert(dataDirExists and docsDirExists, 'Error initializing DevDocs directories')
end

Expand Down Expand Up @@ -162,7 +164,10 @@ M.ExtractDocs = function(slug, callback)
local htmlContent = entry.value
local parts = vim.split(title, '/', { trimempty = true, plain = true })
local filename = table.remove(parts, #parts) .. '.md'
local dir = C.DOCS_DIR .. '/' .. slug .. (#parts > 0 and '/' .. table.concat(parts, '/') or '')
local dir = C.DOCS_DIR
.. '/'
.. slug
.. (#parts > 0 and '/' .. table.concat(parts, '/') or '')
local outputFile = dir .. '/' .. filename

M.Mkdir(dir)
Expand All @@ -185,7 +190,7 @@ M.ExtractDocs = function(slug, callback)
downloaded = true,
extracted = true,
})
vim.schedule(function ()
vim.schedule(function()
vim.notify('Downloaded Docs for ' .. slug .. ' successfully')
end)
if callback ~= nil then
Expand Down
5 changes: 4 additions & 1 deletion lua/devdocs/picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ M.ViewDoc = function(doc, callback)
prettifiedFilenames,
{ prompt = ('Select Doc' .. '( ' .. doc .. ' )') },
function(_, index)
if not index then
return
end
local file = files[index]
vim.cmd('split ' .. file .. ' | setlocal readonly')
vim.cmd('split ' .. file .. ' | setlocal readonly nomodifiable nobuflisted')
vim.diagnostic.enable(false, { bufnr = 0 })
end
)
Expand Down