浏览代码

[Feature] Make the rest of the builtins configurable (#1318)

kylo252 3 年之前
父节点
当前提交
335e707b2a
共有 11 个文件被更改,包括 149 次插入100 次删除
  1. 52 42
      lua/core/autopairs.lua
  2. 25 0
      lua/core/comment.lua
  3. 1 1
      lua/core/compe.lua
  4. 5 12
      lua/core/dashboard.lua
  5. 44 41
      lua/core/gitsigns.lua
  6. 1 0
      lua/core/nvimtree.lua
  7. 2 1
      lua/core/telescope.lua
  8. 2 1
      lua/core/which-key.lua
  9. 2 0
      lua/default-config.lua
  10. 5 1
      lua/lsp/init.lua
  11. 10 1
      lua/plugins.lua

+ 52 - 42
lua/core/autopairs.lua

@@ -1,54 +1,64 @@
--- if not package.loaded['nvim-autopairs'] then
---   return
--- end
-local Log = require "core.log"
-local status_ok, _ = pcall(require, "nvim-autopairs")
-if not status_ok then
-  Log:get_default().error "Failed to load autopairs"
-  return
+local M = {}
+
+function M.config()
+  lvim.builtin.autopairs = {
+    active = true,
+    ---@usage  map <CR> on insert mode
+    map_cr = true,
+    ---@usage auto insert after select function or method item
+    -- NOTE: This should be wrapped into a function so that it is re-evaluated when opening new files
+    map_complete = vim.bo.filetype ~= "tex",
+    ---@usage check treesitter
+    check_ts = true,
+    ts_config = {
+      lua = { "string" },
+      javascript = { "template_string" },
+      java = false,
+    },
+  }
 end
-local npairs = require "nvim-autopairs"
-local Rule = require "nvim-autopairs.rule"
 
--- skip it, if you use another global object
-_G.MUtils = {}
+M.setup = function()
+  -- skip it, if you use another global object
+  _G.MUtils = {}
+  local npairs = require "nvim-autopairs"
+  local Rule = require "nvim-autopairs.rule"
 
-vim.g.completion_confirm_key = ""
-MUtils.completion_confirm = function()
-  if vim.fn.pumvisible() ~= 0 then
-    if vim.fn.complete_info()["selected"] ~= -1 then
-      return vim.fn["compe#confirm"](npairs.esc "<cr>")
+  vim.g.completion_confirm_key = ""
+  MUtils.completion_confirm = function()
+    if vim.fn.pumvisible() ~= 0 then
+      if vim.fn.complete_info()["selected"] ~= -1 then
+        return vim.fn["compe#confirm"](npairs.esc "<cr>")
+      else
+        return npairs.esc "<cr>"
+      end
     else
-      return npairs.esc "<cr>"
+      return npairs.autopairs_cr()
     end
-  else
-    return npairs.autopairs_cr()
   end
-end
 
-if package.loaded["compe"] then
-  local map_complete_optional = vim.bo.filetype ~= "tex"
-  require("nvim-autopairs.completion.compe").setup {
-    map_cr = true, --  map <CR> on insert mode
-    map_complete = map_complete_optional, -- it will auto insert `(` after select function or method item
+  if package.loaded["compe"] then
+    require("nvim-autopairs.completion.compe").setup {
+      map_cr = lvim.builtin.autopairs.map_cr,
+      map_complete = lvim.builtin.autopairs.map_complete,
+    }
+  end
+
+  npairs.setup {
+    check_ts = lvim.builtin.autopairs.check_ts,
+    ts_config = lvim.builtin.autopairs.ts_config,
   }
-end
 
-npairs.setup {
-  check_ts = true,
-  ts_config = {
-    lua = { "string" }, -- it will not add pair on that treesitter node
-    javascript = { "template_string" },
-    java = false, -- don't check treesitter on java
-  },
-}
+  require("nvim-treesitter.configs").setup { autopairs = { enable = true } }
 
-require("nvim-treesitter.configs").setup { autopairs = { enable = true } }
+  local ts_conds = require "nvim-autopairs.ts-conds"
 
-local ts_conds = require "nvim-autopairs.ts-conds"
+  -- TODO: can these rules be safely added from "config.lua" ?
+  -- press % => %% is only inside comment or string
+  npairs.add_rules {
+    Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }),
+    Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }),
+  }
+end
 
--- press % => %% is only inside comment or string
-npairs.add_rules {
-  Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }),
-  Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }),
-}
+return M

+ 25 - 0
lua/core/comment.lua

@@ -0,0 +1,25 @@
+local M = {}
+
+function M.config()
+  lvim.builtin.comment = {
+    active = true,
+    -- Linters prefer comment and line to have a space in between markers
+    marker_padding = true,
+    -- should comment out empty or whitespace only lines
+    comment_empty = false,
+    -- Should key mappings be created
+    create_mappings = true,
+    -- Normal mode mapping left hand side
+    line_mapping = "gcc",
+    -- Visual/Operator mapping left hand side
+    operator_mapping = "gc",
+    -- Hook function to call before commenting takes place
+    hook = nil,
+  }
+end
+
+function M.setup()
+  require("nvim_comment").setup(lvim.builtin.comment)
+end
+
+return M

+ 1 - 1
lua/core/compe.lua

@@ -1,7 +1,7 @@
 local M = {}
 M.config = function()
   lvim.builtin.compe = {
-    enabled = true,
+    active = true,
     autocomplete = true,
     debug = false,
     min_length = 1,

+ 5 - 12
lua/core/dashboard.lua

@@ -3,6 +3,8 @@ M.config = function()
   lvim.builtin.dashboard = {
     active = false,
     search_handler = "telescope",
+    disable_at_vim_enter = 0,
+    session_directory = os.getenv "HOME" .. "/.cache/lvim/sessions",
     custom_header = {
       "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀",
       "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣶⣾⠿⠿⠟⠛⠛⠛⠛⠿⠿⣿⣷⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀",
@@ -52,7 +54,7 @@ M.config = function()
 end
 
 M.setup = function()
-  vim.g.dashboard_disable_at_vimenter = 0
+  vim.g.dashboard_disable_at_vimenter = lvim.builtin.dashboard.disable_at_vim_enter
 
   vim.g.dashboard_custom_header = lvim.builtin.dashboard.custom_header
 
@@ -62,12 +64,8 @@ M.setup = function()
 
   lvim.builtin.which_key.mappings[";"] = { "<cmd>Dashboard<CR>", "Dashboard" }
 
-  -- f = {
-  --   description = { "  Neovim Config Files" },
-  --   command = "Telescope find_files cwd=" .. CONFIG_PATH,
-  -- },
-  -- e = {description = {'  Marks              '}, command = 'Telescope marks'}
-  vim.cmd 'let g:dashboard_session_directory = "~/.config/lvim/.sessions"'
+  vim.g.dashboard_session_directory = lvim.builtin.dashboard.session_directory
+
   vim.cmd "let packages = len(globpath('~/.local/share/lunarvim/site/pack/packer/start', '*', 0, 1))"
 
   vim.api.nvim_exec(
@@ -77,11 +75,6 @@ M.setup = function()
     false
   )
 
-  -- file_browser = {description = {' File Browser'}, command = 'Telescope find_files'},
-
-  -- vim.g.dashboard_session_directory = CACHE_PATH..'/session'
-  -- vim.g.dashboard_custom_footer = lvim.dashboard.footer
-
   require("core.autocmds").define_augroups {
     _dashboard = {
       -- seems to be nobuflisted that makes my stuff disappear will do more testing

+ 44 - 41
lua/core/gitsigns.lua

@@ -1,54 +1,57 @@
 local M = {}
 M.config = function()
   lvim.builtin.gitsigns = {
-    signs = {
-      add = {
-        hl = "GitSignsAdd",
-        text = "▎",
-        numhl = "GitSignsAddNr",
-        linehl = "GitSignsAddLn",
+    active = true,
+    opts = {
+      signs = {
+        add = {
+          hl = "GitSignsAdd",
+          text = "▎",
+          numhl = "GitSignsAddNr",
+          linehl = "GitSignsAddLn",
+        },
+        change = {
+          hl = "GitSignsChange",
+          text = "▎",
+          numhl = "GitSignsChangeNr",
+          linehl = "GitSignsChangeLn",
+        },
+        delete = {
+          hl = "GitSignsDelete",
+          text = "契",
+          numhl = "GitSignsDeleteNr",
+          linehl = "GitSignsDeleteLn",
+        },
+        topdelete = {
+          hl = "GitSignsDelete",
+          text = "契",
+          numhl = "GitSignsDeleteNr",
+          linehl = "GitSignsDeleteLn",
+        },
+        changedelete = {
+          hl = "GitSignsChange",
+          text = "▎",
+          numhl = "GitSignsChangeNr",
+          linehl = "GitSignsChangeLn",
+        },
       },
-      change = {
-        hl = "GitSignsChange",
-        text = "▎",
-        numhl = "GitSignsChangeNr",
-        linehl = "GitSignsChangeLn",
+      numhl = false,
+      linehl = false,
+      keymaps = {
+        -- Default keymap options
+        noremap = true,
+        buffer = true,
       },
-      delete = {
-        hl = "GitSignsDelete",
-        text = "契",
-        numhl = "GitSignsDeleteNr",
-        linehl = "GitSignsDeleteLn",
-      },
-      topdelete = {
-        hl = "GitSignsDelete",
-        text = "契",
-        numhl = "GitSignsDeleteNr",
-        linehl = "GitSignsDeleteLn",
-      },
-      changedelete = {
-        hl = "GitSignsChange",
-        text = "▎",
-        numhl = "GitSignsChangeNr",
-        linehl = "GitSignsChangeLn",
-      },
-    },
-    numhl = false,
-    linehl = false,
-    keymaps = {
-      -- Default keymap options
-      noremap = true,
-      buffer = true,
+      watch_index = { interval = 1000 },
+      sign_priority = 6,
+      update_debounce = 200,
+      status_formatter = nil, -- Use default
     },
-    watch_index = { interval = 1000 },
-    sign_priority = 6,
-    update_debounce = 200,
-    status_formatter = nil, -- Use default
   }
 end
 
 M.setup = function()
-  require("gitsigns").setup(lvim.builtin.gitsigns)
+  require("gitsigns").setup(lvim.builtin.gitsigns.opts)
 end
 
 return M

+ 1 - 0
lua/core/nvimtree.lua

@@ -3,6 +3,7 @@ local Log = require "core.log"
 --
 M.config = function()
   lvim.builtin.nvimtree = {
+    active = true,
     side = "left",
     width = 30,
     show_icons = {

+ 2 - 1
lua/core/telescope.lua

@@ -6,7 +6,8 @@ function M.config()
   end
 
   lvim.builtin.telescope = {
-    active = false,
+    ---@usage disable telescope completely [not recommeded]
+    active = true,
     defaults = {
       prompt_prefix = " ",
       selection_caret = " ",

+ 2 - 1
lua/core/which-key.lua

@@ -1,7 +1,8 @@
 local M = {}
 M.config = function()
   lvim.builtin.which_key = {
-    active = false,
+    ---@usage disable which-key completely [not recommeded]
+    active = true,
     setup = {
       plugins = {
         marks = true, -- shows a list of your marks on ' and `

+ 2 - 0
lua/default-config.lua

@@ -1303,3 +1303,5 @@ require("core.treesitter").config()
 require("core.nvimtree").config()
 require("core.rooter").config()
 require("core.bufferline").config()
+require("core.autopairs").config()
+require("core.comment").config()

+ 5 - 1
lua/lsp/init.lua

@@ -34,7 +34,11 @@ local function lsp_highlight_document(client)
 end
 
 local function add_lsp_buffer_keybindings(bufnr)
-  local wk = require "which-key"
+  local status_ok, wk = pcall(require, "which-key")
+  if not status_ok then
+    return
+  end
+
   local keys = {
     ["K"] = { "<cmd>lua vim.lsp.buf.hover()<CR>", "Show hover" },
     ["gd"] = { "<cmd>lua vim.lsp.buf.definition()<CR>", "Goto Definition" },

+ 10 - 1
lua/plugins.lua

@@ -27,6 +27,7 @@ return {
         lvim.builtin.telescope.on_config_done(require "telescope")
       end
     end,
+    disable = not lvim.builtin.telescope.active,
   },
 
   -- Completion & Snippets
@@ -39,6 +40,7 @@ return {
         lvim.builtin.compe.on_config_done(require "compe")
       end
     end,
+    disable = not lvim.builtin.compe.active,
     -- wants = "vim-vsnip",
     -- requires = {
     -- {
@@ -56,10 +58,12 @@ return {
     "hrsh7th/vim-vsnip",
     -- wants = "friendly-snippets",
     event = "InsertEnter",
+    disable = not lvim.builtin.compe.active,
   },
   {
     "rafamadriz/friendly-snippets",
     event = "InsertCharPre",
+    disable = not lvim.builtin.compe.active,
   },
 
   -- Autopairs
@@ -68,11 +72,12 @@ return {
     -- event = "InsertEnter",
     after = "nvim-compe",
     config = function()
-      require "core.autopairs"
+      require("core.autopairs").setup()
       if lvim.builtin.autopairs.on_config_done then
         lvim.builtin.autopairs.on_config_done(require "nvim-autopairs")
       end
     end,
+    disable = not lvim.builtin.autopairs.active or not lvim.builtin.compe.active,
   },
 
   -- Treesitter
@@ -100,6 +105,7 @@ return {
         lvim.builtin.nvimtree.on_config_done(require "nvim-tree.config")
       end
     end,
+    disable = not lvim.builtin.nvimtree.active,
   },
 
   {
@@ -112,6 +118,7 @@ return {
       end
     end,
     event = "BufRead",
+    disable = not lvim.builtin.gitsigns.active,
   },
 
   -- Whichkey
@@ -124,6 +131,7 @@ return {
       end
     end,
     event = "BufWinEnter",
+    disable = not lvim.builtin.which_key.active,
   },
 
   -- Comments
@@ -136,6 +144,7 @@ return {
         lvim.builtin.comment.on_config_done(require "nvim_comment")
       end
     end,
+    disable = not lvim.builtin.comment.active,
   },
 
   -- vim-rooter