From 33da9e1aebe13ed6eadcc4c1f0d92b996fb84b4d Mon Sep 17 00:00:00 2001 From: Aiden Loyd Date: Mon, 23 Sep 2024 15:11:03 -0500 Subject: [PATCH] Confirm that `recent_projects` is not null before using --- lua/project_nvim/utils/history.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lua/project_nvim/utils/history.lua b/lua/project_nvim/utils/history.lua index 486c1ee..1ad898f 100644 --- a/lua/project_nvim/utils/history.lua +++ b/lua/project_nvim/utils/history.lua @@ -1,7 +1,7 @@ local path = require("project_nvim.utils.path") local uv = vim.loop local M = {} -local is_windows = vim.fn.has('win32') or vim.fn.has('wsl') +local is_windows = vim.fn.has("win32") or vim.fn.has("wsl") M.recent_projects = nil -- projects from previous neovim sessions M.session_projects = {} -- projects from current neovim session @@ -27,13 +27,13 @@ local function dir_exists(dir) end local function normalise_path(path_to_normalise) - local normalised_path = path_to_normalise:gsub("\\", "/"):gsub("//", "/") + local normalised_path = path_to_normalise:gsub("\\", "/"):gsub("//", "/") - if is_windows then - normalised_path = normalised_path:sub(1,1):lower()..normalised_path:sub(2) - end + if is_windows then + normalised_path = normalised_path:sub(1, 1):lower() .. normalised_path:sub(2) + end - return normalised_path + return normalised_path end local function delete_duplicates(tbl) @@ -60,9 +60,11 @@ local function delete_duplicates(tbl) end function M.delete_project(project) - for k, v in ipairs(M.recent_projects) do - if v == project.value then - M.recent_projects[k] = nil + if M.recent_projects ~= nil then + for k, v in ipairs(M.recent_projects) do + if v == project.value then + M.recent_projects[k] = nil + end end end end