diff options
| author | kylo252 <[email protected]> | 2021-08-17 17:20:18 +0200 | 
|---|---|---|
| committer | GitHub <[email protected]> | 2021-08-17 19:50:18 +0430 | 
| commit | 335e707b2aae38c0cd5d0d962b27038ab1117aa6 (patch) | |
| tree | 4be5b6ca5ea2e018893b067e5656f199e7a99e8f | |
| parent | 1cc2452eb7b76aad36a6d9d210abff88edf6721a (diff) | |
[Feature] Make the rest of the builtins configurable (#1318)
| -rw-r--r-- | lua/core/autopairs.lua | 94 | ||||
| -rw-r--r-- | lua/core/comment.lua | 25 | ||||
| -rw-r--r-- | lua/core/compe.lua | 2 | ||||
| -rw-r--r-- | lua/core/dashboard.lua | 17 | ||||
| -rw-r--r-- | lua/core/gitsigns.lua | 85 | ||||
| -rw-r--r-- | lua/core/nvimtree.lua | 1 | ||||
| -rw-r--r-- | lua/core/telescope.lua | 3 | ||||
| -rw-r--r-- | lua/core/which-key.lua | 3 | ||||
| -rw-r--r-- | lua/default-config.lua | 2 | ||||
| -rw-r--r-- | lua/lsp/init.lua | 6 | ||||
| -rw-r--r-- | lua/plugins.lua | 11 | 
11 files changed, 149 insertions, 100 deletions
| diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index a5f21a1b..470f8335 100644 --- a/lua/core/autopairs.lua +++ b/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 diff --git a/lua/core/comment.lua b/lua/core/comment.lua new file mode 100644 index 00000000..79d711b6 --- /dev/null +++ b/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 diff --git a/lua/core/compe.lua b/lua/core/compe.lua index 9edb2af0..29344d97 100644 --- a/lua/core/compe.lua +++ b/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, diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index d5e5bfe9..649be14c 100644 --- a/lua/core/dashboard.lua +++ b/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 diff --git a/lua/core/gitsigns.lua b/lua/core/gitsigns.lua index 0c0efa91..80a31500 100644 --- a/lua/core/gitsigns.lua +++ b/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 diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 25c69575..7c99a91e 100644 --- a/lua/core/nvimtree.lua +++ b/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 = { diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index d31edef9..e72727a4 100644 --- a/lua/core/telescope.lua +++ b/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 = " ", diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 04f892d8..ff53142c 100644 --- a/lua/core/which-key.lua +++ b/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 ` diff --git a/lua/default-config.lua b/lua/default-config.lua index 44da8954..ed9b17d6 100644 --- a/lua/default-config.lua +++ b/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() diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 891147e5..920aceb3 100644 --- a/lua/lsp/init.lua +++ b/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" }, diff --git a/lua/plugins.lua b/lua/plugins.lua index 5353de5b..c9e7f3c2 100644 --- a/lua/plugins.lua +++ b/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 | 
