From e15fb602b5287d4678626f75e0029758c731eb57 Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Sun, 23 Feb 2025 12:45:55 +0800 Subject: [PATCH 1/4] fix: quit when cancel select --- lua/devdocs/picker.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/devdocs/picker.lua b/lua/devdocs/picker.lua index aa01b67..8b98954 100644 --- a/lua/devdocs/picker.lua +++ b/lua/devdocs/picker.lua @@ -31,6 +31,9 @@ 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.diagnostic.enable(false, { bufnr = 0 }) From 9b94e89b92245cd1e46b0878f406f10c49c4b10c Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Sun, 23 Feb 2025 12:47:08 +0800 Subject: [PATCH 2/4] fix: don't use buflist when open doc --- lua/devdocs/picker.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/devdocs/picker.lua b/lua/devdocs/picker.lua index 8b98954..d02060a 100644 --- a/lua/devdocs/picker.lua +++ b/lua/devdocs/picker.lua @@ -35,7 +35,7 @@ M.ViewDoc = function(doc, callback) 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 ) From 742832529513dece8f7e58f82b47bc6ea26411e8 Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Sun, 23 Feb 2025 15:01:24 +0800 Subject: [PATCH 3/4] fix: handle fn.mkdir correctly --- lua/devdocs/docs.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/devdocs/docs.lua b/lua/devdocs/docs.lua index 7aedc64..357b434 100644 --- a/lua/devdocs/docs.lua +++ b/lua/devdocs/docs.lua @@ -42,8 +42,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 From a24ffb76606ccc96140b97a465973d1151dd4813 Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Sun, 23 Feb 2025 15:01:37 +0800 Subject: [PATCH 4/4] chore: fmt with stylua --- lua/devdocs/docs.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lua/devdocs/docs.lua b/lua/devdocs/docs.lua index 357b434..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 @@ -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