diff --git a/lua/devdocs/docs.lua b/lua/devdocs/docs.lua index 7aedc64..5151d88 100644 --- a/lua/devdocs/docs.lua +++ b/lua/devdocs/docs.lua @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/lua/devdocs/picker.lua b/lua/devdocs/picker.lua index aa01b67..d02060a 100644 --- a/lua/devdocs/picker.lua +++ b/lua/devdocs/picker.lua @@ -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 )