浏览代码

feat: update now syncs the core plugins (#1865)

kylo252 3 年之前
父节点
当前提交
377cab434c
共有 5 个文件被更改,包括 36 次插入19 次删除
  1. 2 3
      lua/lvim/bootstrap.lua
  2. 6 10
      lua/lvim/core/autopairs.lua
  3. 0 2
      lua/lvim/core/cmp.lua
  4. 14 0
      lua/lvim/plugin-loader.lua
  5. 14 4
      lua/lvim/utils/hooks.lua

+ 2 - 3
lua/lvim/bootstrap.lua

@@ -1,8 +1,5 @@
 local M = {}
 
-package.loaded["lvim.utils.hooks"] = nil
-local _, hooks = pcall(require, "lvim.utils.hooks")
-
 local uv = vim.loop
 local path_sep = uv.os_uname().version:match "Windows" and "\\" or "/"
 
@@ -101,6 +98,8 @@ end
 ---Update LunarVim
 ---pulls the latest changes from github and, resets the startup cache
 function M:update()
+  package.loaded["lvim.utils.hooks"] = nil
+  local _, hooks = pcall(require, "lvim.utils.hooks")
   hooks.run_pre_update()
   M:update_repo()
   hooks.run_post_update()

+ 6 - 10
lua/lvim/core/autopairs.lua

@@ -4,8 +4,6 @@ function M.config()
   lvim.builtin.autopairs = {
     active = true,
     on_config_done = nil,
-    ---@usage auto insert after select function or method item
-    map_complete = true,
     ---@usage  -- modifies the function or method delimiter by filetypes
     map_char = {
       all = "(",
@@ -52,14 +50,12 @@ M.setup = function()
     end),
   }
 
-  if package.loaded["cmp"] then
-    require("nvim-autopairs.completion.cmp").setup {
-      map_cr = false,
-      map_complete = lvim.builtin.autopairs.map_complete,
-      map_char = lvim.builtin.autopairs.map_char,
-    }
-    -- we map CR explicitly in cmp.lua but we still need to setup the autopairs CR keymap
-    vim.api.nvim_set_keymap("i", "<CR>", "v:lua.MPairs.autopairs_cr()", { expr = true, noremap = true })
+  local cmp_status_ok, cmp = pcall(require, "cmp")
+  if cmp_status_ok then
+    -- If you want insert `(` after select function or method item
+    local cmp_autopairs = require "nvim-autopairs.completion.cmp"
+    local map_char = lvim.builtin.autopairs.map_char
+    cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = map_char })
   end
 
   require("nvim-treesitter.configs").setup { autopairs = { enable = true } }

+ 0 - 2
lua/lvim/core/cmp.lua

@@ -161,8 +161,6 @@ M.config = function()
       select = false,
     },
     completion = {
-      ---@usage vim's `completeopt` setting. Warning: Be careful when changing this value.
-      completeopt = "menu,menuone,noinsert",
       ---@usage The minimum length of a word to complete on.
       keyword_length = 1,
     },

+ 14 - 0
lua/lvim/plugin-loader.lua

@@ -60,4 +60,18 @@ function plugin_loader:load(configurations)
   end)
 end
 
+function plugin_loader:get_core_plugins()
+  local list = {}
+  local plugins = require "lvim.plugins"
+  for _, item in pairs(plugins) do
+    table.insert(list, item[1]:match "/(%S*)")
+  end
+  return list
+end
+
+function plugin_loader:sync_core_plugins()
+  local core_plugins = plugin_loader.get_core_plugins()
+  vim.cmd("PackerSync " .. unpack(core_plugins))
+end
+
 return plugin_loader

+ 14 - 4
lua/lvim/utils/hooks.lua

@@ -1,11 +1,13 @@
 local M = {}
 
+local plugin_loader = require "lvim.plugin-loader"
 local Log = require "lvim.core.log"
 local in_headless = #vim.api.nvim_list_uis() == 0
 
 function M.run_pre_update()
   Log:debug "Starting pre-update hook"
   _G.__luacache.clear_cache()
+  vim.cmd "LspStop"
 end
 
 ---Reset any startup cache files used by Packer and Impatient
@@ -13,21 +15,29 @@ end
 ---Tip: Useful for clearing any outdated settings
 function M.reset_cache()
   _G.__luacache.clear_cache()
-  require("lvim.plugin-loader"):cache_reset()
+
+  plugin_loader:cache_reset()
   package.loaded["lvim.lsp.templates"] = nil
+
+  Log:debug "Re-generatring ftplugin template files"
   require("lvim.lsp.templates").generate_templates()
 end
 
 function M.run_post_update()
   Log:debug "Starting post-update hook"
-  M.reset_cache()
+
+  Log:debug "Re-generatring ftplugin template files"
+  package.loaded["lvim.lsp.templates"] = nil
+  require("lvim.lsp.templates").generate_templates()
+
+  Log:debug "Updating core plugins"
+  plugin_loader:sync_core_plugins()
 
   if not in_headless then
     vim.schedule(function()
-      require("packer").install()
       -- TODO: add a changelog
       vim.notify("Update complete", vim.log.levels.INFO)
-      vim.cmd "LspStart"
+      vim.cmd "LspRestart"
     end)
   end
 end