From 5e10f11735f6007a4f6654ee2eb93e8115a45627 Mon Sep 17 00:00:00 2001 From: qianz Date: Fri, 24 Apr 2026 10:12:23 +0800 Subject: [PATCH] Fix lazy.nvim startup loading --- vim/my.nvim/init.lua | 7 ++++ vim/my.nvim/lazy-lock.json | 1 - vim/my.nvim/lua/setup.lua | 70 -------------------------------------- 3 files changed, 7 insertions(+), 71 deletions(-) diff --git a/vim/my.nvim/init.lua b/vim/my.nvim/init.lua index 7c29e6c..45e92e5 100644 --- a/vim/my.nvim/init.lua +++ b/vim/my.nvim/init.lua @@ -1,3 +1,10 @@ +local config_root = vim.fn.fnamemodify( + vim.fn.resolve(debug.getinfo(1, "S").source:sub(2)), + ":p:h" +) + +vim.opt.runtimepath:prepend(config_root) + require('setup').setup() vim.keymap.set("n", "sv", function() require('setup').setup() end, {noremap = true,silent = true}) diff --git a/vim/my.nvim/lazy-lock.json b/vim/my.nvim/lazy-lock.json index 2de2f7a..51bd352 100644 --- a/vim/my.nvim/lazy-lock.json +++ b/vim/my.nvim/lazy-lock.json @@ -42,7 +42,6 @@ "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, "quick-scope": { "branch": "master", "commit": "6cee1d9e0b9ac0fbffeb538d4a5ba9f5628fabbc" }, "rainbow": { "branch": "master", "commit": "76ca1a20aa42edb5c65c19029968aad4625790dc" }, - "sidekick.nvim": { "branch": "main", "commit": "c2bdf8cfcd87a6be5f8b84322c1b5052e78e302e" }, "space-vim-dark": { "branch": "master", "commit": "0ab698bd2a3959e3bed7691ac55ba4d8abefd143" }, "stylish.nvim": { "branch": "main", "commit": "63c21552bce62175f2d067a92bf7c856e062c314" }, "switch.vim": { "branch": "main", "commit": "4017a58f7ed8a2d76a288e36130affe8eb55e83a" }, diff --git a/vim/my.nvim/lua/setup.lua b/vim/my.nvim/lua/setup.lua index 6bd54e8..212fc9e 100644 --- a/vim/my.nvim/lua/setup.lua +++ b/vim/my.nvim/lua/setup.lua @@ -33,75 +33,6 @@ local function ensure_plugin_manager(dir) vim.opt.runtimepath:prepend(lazypath) end -local function checksum_cache_path(root) - if not root then - return nil - end - return root .. "/.lazy-lock.sha256" -end - -local function read_lock_checksum(lockfile) - if not lockfile or vim.fn.filereadable(lockfile) ~= 1 then - return nil - end - local ok, lines = pcall(vim.fn.readfile, lockfile) - if not ok or not lines then - return nil - end - return vim.fn.sha256(table.concat(lines, "\n")) -end - -local function read_cached_checksum(root) - local path = checksum_cache_path(root) - if not path or vim.fn.filereadable(path) ~= 1 then - return nil - end - local ok, lines = pcall(vim.fn.readfile, path) - if not ok or not lines or #lines == 0 then - return nil - end - return lines[1] -end - -local function write_cached_checksum(root, checksum) - local path = checksum_cache_path(root) - if not path or not checksum then - return - end - vim.fn.mkdir(root, "p") - pcall(vim.fn.writefile, {checksum}, path) -end - -local function try_restore(lazy_mod, root, lockfile) - local ok_stats, stats = pcall(function() - return lazy_mod.stats() - end) - local missing = 0 - if ok_stats and stats and stats.missing then - missing = stats.missing - end - local desired_checksum = read_lock_checksum(lockfile) - local cached_checksum = read_cached_checksum(root) - local needs_restore = missing > 0 or (desired_checksum and desired_checksum ~= cached_checksum) - local restore_fn = type(lazy_mod.restore) == "function" and lazy_mod.restore - or type(lazy_mod.sync) == "function" and lazy_mod.sync - or nil - if not needs_restore or not restore_fn then - return - end - local opts = {wait = true, show = false} - local restore_ok, err = pcall(restore_fn, opts) - if restore_ok then - if desired_checksum then - write_cached_checksum(root, desired_checksum) - end - elseif err then - vim.schedule(function() - vim.notify(string.format("lazy.nvim restore failed: %s", err), vim.log.levels.ERROR) - end) - end -end - local function ensure_plugins(dir) local lazy = require("lazy") local lazy_opts = {root = dir} @@ -203,7 +134,6 @@ local function ensure_plugins(dir) end, }, }, lazy_opts) - try_restore(lazy, lazy_opts.root, lazy_opts.lockfile) end local function config_coc()