Skip to content

Commit

Permalink
Confirm that recent_projects is not null before using
Browse files Browse the repository at this point in the history
  • Loading branch information
OrdoFlammae committed Sep 23, 2024
1 parent 8c6bad7 commit 33da9e1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lua/project_nvim/utils/history.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 33da9e1

Please sign in to comment.