Ver Fonte

refactor: add explicit setup for impatient (#1529)

Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com>
Chase Colman há 3 anos atrás
pai
commit
ad86b19204
3 ficheiros alterados com 19 adições e 9 exclusões
  1. 4 1
      init.lua
  2. 15 8
      lua/impatient.lua
  3. 0 0
      lua/impatient/cachepack.lua

+ 4 - 1
init.lua

@@ -18,7 +18,10 @@ vim.cmd [[let &packpath = &runtimepath]]
 -- }}}
 
 _G.PLENARY_DEBUG = false -- Plenary destroys cache with this undocumented flag set to true by default
-require("impatient").enable_profile()
+require("impatient").setup {
+  path = vim.fn.stdpath "cache" .. "/lvim_cache",
+  enable_profiling = true,
+}
 
 local config = require "config"
 config:init()

+ 15 - 8
lua/impatient.lua

@@ -2,13 +2,12 @@
 
 local vim = vim
 local uv = vim.loop
-local impatient_start = uv.hrtime()
+local impatient_load_start = uv.hrtime()
 local api = vim.api
 local ffi = require "ffi"
 
 local get_option, set_option = api.nvim_get_option, api.nvim_set_option
 local get_runtime_file = api.nvim_get_runtime_file
-local home_dir = uv.os_homedir()
 
 local impatient_dur
 
@@ -16,7 +15,7 @@ local M = {
   cache = {},
   profile = nil,
   dirty = false,
-  path = home_dir .. "/.local/share/lunarvim/cache",
+  path = nil,
   log = {},
 }
 
@@ -274,7 +273,17 @@ function M.clear_cache()
   os.remove(M.path)
 end
 
-local function setup()
+impatient_dur = uv.hrtime() - impatient_load_start
+
+function M.setup(opts)
+  opts = opts or {}
+  M.path = opts.path or vim.fn.stdpath "cache" .. "/luacache"
+
+  if opts.enable_profiling then
+    M.enable_profile()
+  end
+
+  local impatient_setup_start = uv.hrtime()
   local stat = uv.fs_stat(M.path)
   if stat then
     log("Loading cache file %s", M.path)
@@ -344,10 +353,8 @@ local function setup()
     command! LuaCacheClear lua _G.__luacache.clear_cache()
     command! LuaCacheLog   lua _G.__luacache.print_log()
   ]]
-end
-
-setup()
 
-impatient_dur = uv.hrtime() - impatient_start
+  impatient_dur = impatient_dur + (uv.hrtime() - impatient_setup_start)
+end
 
 return M

+ 0 - 0
lua/impatient/cachepack.lua