Line data Source code
1 : -- lua/yoda/commands/lazy.lua
2 : -- Lazy.nvim plugin manager debug and management commands
3 :
4 1 : local M = {}
5 :
6 : --- Setup Lazy.nvim related commands
7 1 : function M.setup()
8 : -- Debug Lazy.nvim plugin manager
9 22 : vim.api.nvim_create_user_command("YodaDebugLazy", function()
10 1 : local logger = require("yoda-logging.logger")
11 1 : logger.set_strategy("console")
12 1 : logger.set_level("debug")
13 :
14 1 : logger.info("=== Lazy.nvim Debug Information ===")
15 2 : logger.debug("Lazy.nvim path", { path = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" })
16 2 : logger.debug("Plugin state path", { path = vim.fn.stdpath("state") .. "/lazy" })
17 :
18 : -- Check if Lazy.nvim is loaded
19 1 : local ok, lazy = pcall(require, "lazy")
20 1 : if ok then
21 1 : logger.info("Lazy.nvim loaded successfully")
22 :
23 : -- Check plugin status
24 1 : local plugins = lazy.get_plugins()
25 1 : logger.info("Total plugins", { count = #plugins })
26 :
27 : -- Check for problematic plugins
28 1 : for _, plugin in ipairs(plugins) do
29 : if plugin._.loaded and plugin._.load_error then
30 : logger.error("Plugin with error", { plugin = plugin.name, error = plugin._.load_error })
31 : end
32 1 : end
33 : else
34 : logger.error("Lazy.nvim failed to load", { error = lazy })
35 : end
36 12 : end, { desc = "Debug Lazy.nvim plugin manager" })
37 :
38 : -- Clean Lazy.nvim cache and state
39 22 : vim.api.nvim_create_user_command("YodaCleanLazy", function()
40 1 : local logger = require("yoda-logging.logger")
41 1 : logger.set_strategy("console")
42 1 : logger.set_level("info")
43 :
44 : -- Clean up Lazy.nvim cache and state
45 2 : local lazy_state = vim.fn.stdpath("state") .. "/lazy"
46 :
47 1 : logger.info("Cleaning Lazy.nvim cache...")
48 :
49 : -- Clean readme directory
50 1 : local readme_dir = lazy_state .. "/readme"
51 2 : if vim.fn.isdirectory(readme_dir) == 1 then
52 : vim.fn.delete(readme_dir, "rf")
53 : logger.info("Cleaned readme directory", { path = readme_dir })
54 : end
55 :
56 : -- Clean lock file
57 1 : local lock_file = lazy_state .. "/lock.json"
58 2 : if vim.fn.filereadable(lock_file) == 1 then
59 : vim.fn.delete(lock_file)
60 : logger.info("Cleaned lock file", { path = lock_file })
61 : end
62 :
63 : -- Clean cache directory
64 1 : local cache_dir = lazy_state .. "/cache"
65 2 : if vim.fn.isdirectory(cache_dir) == 1 then
66 : vim.fn.delete(cache_dir, "rf")
67 : logger.info("Cleaned cache directory", { path = cache_dir })
68 : end
69 :
70 1 : logger.info("Lazy.nvim cache cleaned. Restart Neovim to reload plugins.")
71 12 : end, { desc = "Clean Lazy.nvim cache and state" })
72 12 : end
73 :
74 1 : return M
|