summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordevtoi <[email protected]>2021-08-22 20:03:19 +0200
committerGitHub <[email protected]>2021-08-22 20:03:19 +0200
commitd85584d09f9028fa4202cea473f7f0ae3c531aef (patch)
tree956d7d9909ca8e37ec604d96965ae7f878262388
parentc5c9ae0fb68567c2a207c8c486b03bbafc650f98 (diff)
[Refactor/Bugfix] move on_config_done callbacks to relevant setup() (#1175)
* Make autopairs config consistent with others * Fix two typos for autopairs * Remove extranous autopairs code. Return on setup * Remove extranous else for autopairs completion confirmation * Move on_config_done callbacks to setup functions. * Add on_config_done completion for builtins lacking a config function * enables galaxyline callbacks to work properly * Add modules for more builtins * Finish streamline of config function in plugin setup * Fix double use of which_key/wk * Fix erroneous remove of functionality in autopairs completion * consistency fixes * Work around telescope not found at config time * Match plugin definition of project and lualine with others * fix: restore config callback syntax Co-authored-by: Johan Melin <[email protected]> Co-authored-by: rebuilt <[email protected]> Co-authored-by: Luc Sinet <[email protected]> Co-authored-by: kylo252 <[email protected]>
-rw-r--r--lua/core/autopairs.lua17
-rw-r--r--lua/core/bufferline.lua5
-rw-r--r--lua/core/comment.lua8
-rw-r--r--lua/core/compe.lua6
-rw-r--r--lua/core/dap.lua6
-rw-r--r--lua/core/dashboard.lua6
-rw-r--r--lua/core/gitsigns.lua9
-rw-r--r--lua/core/lspinstall.lua19
-rw-r--r--lua/core/nvimtree.lua13
-rw-r--r--lua/core/project.lua15
-rw-r--r--lua/core/telescope.lua28
-rw-r--r--lua/core/terminal.lua5
-rw-r--r--lua/core/treesitter.lua6
-rw-r--r--lua/core/which-key.lua6
-rw-r--r--lua/default-config.lua21
-rw-r--r--lua/plugins.lua44
16 files changed, 126 insertions, 88 deletions
diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua
index 470f8335..24aa1875 100644
--- a/lua/core/autopairs.lua
+++ b/lua/core/autopairs.lua
@@ -3,6 +3,7 @@ local M = {}
function M.config()
lvim.builtin.autopairs = {
active = true,
+ on_config_done = nil,
---@usage map <CR> on insert mode
map_cr = true,
---@usage auto insert after select function or method item
@@ -21,19 +22,19 @@ end
M.setup = function()
-- skip it, if you use another global object
_G.MUtils = {}
- local npairs = require "nvim-autopairs"
+ local autopairs = 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>")
+ return vim.fn["compe#confirm"](autopairs.esc "<cr>")
else
- return npairs.esc "<cr>"
+ return autopairs.esc "<cr>"
end
else
- return npairs.autopairs_cr()
+ return autopairs.autopairs_cr()
end
end
@@ -44,7 +45,7 @@ M.setup = function()
}
end
- npairs.setup {
+ autopairs.setup {
check_ts = lvim.builtin.autopairs.check_ts,
ts_config = lvim.builtin.autopairs.ts_config,
}
@@ -55,10 +56,14 @@ M.setup = function()
-- TODO: can these rules be safely added from "config.lua" ?
-- press % => %% is only inside comment or string
- npairs.add_rules {
+ autopairs.add_rules {
Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node { "string", "comment" }),
Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node { "function" }),
}
+
+ if lvim.builtin.autopairs.on_config_done then
+ lvim.builtin.autopairs.on_config_done(autopairs)
+ end
end
return M
diff --git a/lua/core/bufferline.lua b/lua/core/bufferline.lua
index 8989ce21..e3f6b5de 100644
--- a/lua/core/bufferline.lua
+++ b/lua/core/bufferline.lua
@@ -3,6 +3,7 @@ local M = {}
M.config = function()
lvim.builtin.bufferline = {
active = true,
+ on_config_done = nil,
keymap = {
normal_mode = {
["<S-l>"] = ":BufferNext<CR>",
@@ -15,6 +16,10 @@ end
M.setup = function()
local keymap = require "keymappings"
keymap.append_to_defaults(lvim.builtin.bufferline.keymap)
+
+ if lvim.builtin.bufferline.on_config_done then
+ lvim.builtin.bufferline.on_config_done()
+ end
end
return M
diff --git a/lua/core/comment.lua b/lua/core/comment.lua
index 79d711b6..b98410ab 100644
--- a/lua/core/comment.lua
+++ b/lua/core/comment.lua
@@ -3,6 +3,7 @@ local M = {}
function M.config()
lvim.builtin.comment = {
active = true,
+ on_config_done = nil,
-- Linters prefer comment and line to have a space in between markers
marker_padding = true,
-- should comment out empty or whitespace only lines
@@ -19,7 +20,12 @@ function M.config()
end
function M.setup()
- require("nvim_comment").setup(lvim.builtin.comment)
+ local nvim_comment = require "nvim_comment"
+
+ nvim_comment.setup(lvim.builtin.comment)
+ if lvim.builtin.comment.on_config_done then
+ lvim.builtin.comment.on_config_done(nvim_comment)
+ end
end
return M
diff --git a/lua/core/compe.lua b/lua/core/compe.lua
index 29344d97..9eb3dcfa 100644
--- a/lua/core/compe.lua
+++ b/lua/core/compe.lua
@@ -1,7 +1,9 @@
local M = {}
+
M.config = function()
lvim.builtin.compe = {
active = true,
+ on_config_done = nil,
autocomplete = true,
debug = false,
min_length = 1,
@@ -122,6 +124,10 @@ M.setup = function()
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", { expr = true })
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true })
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true })
+
+ if lvim.builtin.compe.on_config_done then
+ lvim.builtin.compe.on_config_done(compe)
+ end
end
return M
diff --git a/lua/core/dap.lua b/lua/core/dap.lua
index 259ff87e..5de3b7c4 100644
--- a/lua/core/dap.lua
+++ b/lua/core/dap.lua
@@ -1,7 +1,9 @@
local M = {}
+
M.config = function()
lvim.builtin.dap = {
active = false,
+ on_config_done = nil,
breakpoint = {
text = "",
texthl = "LspDiagnosticsSignError",
@@ -33,6 +35,10 @@ M.setup = function()
s = { "<cmd>lua require'dap'.continue()<cr>", "Start" },
q = { "<cmd>lua require'dap'.close()<cr>", "Quit" },
}
+
+ if lvim.builtin.dap.on_config_done then
+ lvim.builtin.dap.on_config_done(dap)
+ end
end
-- TODO put this up there ^^^ call in ftplugin
diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua
index 63ae7294..c76d55c9 100644
--- a/lua/core/dashboard.lua
+++ b/lua/core/dashboard.lua
@@ -1,7 +1,9 @@
local M = {}
+
M.config = function()
lvim.builtin.dashboard = {
active = false,
+ on_config_done = nil,
search_handler = "telescope",
disable_at_vim_enter = 0,
session_directory = os.getenv "HOME" .. "/.cache/lvim/sessions",
@@ -91,6 +93,10 @@ M.setup = function()
{ "FileType", "dashboard", "nnoremap <silent> <buffer> q :q<CR>" },
},
}
+
+ if lvim.builtin.dashboard.on_config_done then
+ lvim.builtin.dashboard.on_config_done()
+ end
end
return M
diff --git a/lua/core/gitsigns.lua b/lua/core/gitsigns.lua
index 80a31500..bb9d088b 100644
--- a/lua/core/gitsigns.lua
+++ b/lua/core/gitsigns.lua
@@ -1,7 +1,9 @@
local M = {}
+
M.config = function()
lvim.builtin.gitsigns = {
active = true,
+ on_config_done = nil,
opts = {
signs = {
add = {
@@ -51,7 +53,12 @@ M.config = function()
end
M.setup = function()
- require("gitsigns").setup(lvim.builtin.gitsigns.opts)
+ local gitsigns = require "gitsigns"
+
+ gitsigns.setup(lvim.builtin.gitsigns.opts)
+ if lvim.builtin.gitsigns.on_config_done then
+ lvim.builtin.gitsigns.on_config_done(gitsigns)
+ end
end
return M
diff --git a/lua/core/lspinstall.lua b/lua/core/lspinstall.lua
new file mode 100644
index 00000000..0bb59e0e
--- /dev/null
+++ b/lua/core/lspinstall.lua
@@ -0,0 +1,19 @@
+local M = {}
+
+M.config = function()
+ lvim.builtin.lspinstall = {
+ active = true,
+ on_config_done = nil,
+ }
+end
+
+M.setup = function()
+ local lspinstall = require "lspinstall"
+ lspinstall.setup()
+
+ if lvim.builtin.lspinstall.on_config_done then
+ lvim.builtin.lspinstall.on_config_done(lspinstall)
+ end
+end
+
+return M
diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua
index ff52029d..bea1add4 100644
--- a/lua/core/nvimtree.lua
+++ b/lua/core/nvimtree.lua
@@ -1,9 +1,10 @@
local M = {}
local Log = require "core.log"
-M.config = function()
+function M.config()
lvim.builtin.nvimtree = {
active = true,
+ on_config_done = nil,
side = "left",
width = 30,
show_icons = {
@@ -48,7 +49,7 @@ M.config = function()
}
end
-M.setup = function()
+function M.setup()
local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config")
if not status_ok then
Log:get_default().error "Failed to load nvim-tree.config"
@@ -88,15 +89,19 @@ M.setup = function()
end
vim.cmd "au WinClosed * lua require('core.nvimtree').on_close()"
+
+ if lvim.builtin.nvimtree.on_config_done then
+ lvim.builtin.nvimtree.on_config_done(nvim_tree_config)
+ end
end
-M.on_open = function()
+function M.on_open()
if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then
require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "")
end
end
-M.on_close = function()
+function M.on_close()
local buf = tonumber(vim.fn.expand "<abuf>")
local ft = vim.api.nvim_buf_get_option(buf, "filetype")
if ft == "NvimTree" and package.loaded["bufferline.state"] then
diff --git a/lua/core/project.lua b/lua/core/project.lua
index 7be65a11..7fb04933 100644
--- a/lua/core/project.lua
+++ b/lua/core/project.lua
@@ -1,11 +1,13 @@
local M = {}
---
+
function M.config()
lvim.builtin.project = {
---@usage set to false to disable project.nvim.
--- This is on by default since it's currently the expected behavior.
active = true,
+ on_config_done = nil,
+
---@usage set to true to disable setting the current-woriking directory
--- Manual mode doesn't automatically change your root directory, so you have
--- the option to manually do so using `:ProjectRoot` command.
@@ -36,9 +38,14 @@ function M.config()
datapath = CACHE_PATH,
}
end
---
+
function M.setup()
- require("project_nvim").setup(lvim.builtin.project)
+ local project = require "project_nvim"
+
+ project.setup(lvim.builtin.project)
+ if lvim.builtin.project.on_config_done then
+ lvim.builtin.project.on_config_done(project)
+ end
end
---
+
return M
diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua
index 5d9263d7..4ae56df0 100644
--- a/lua/core/telescope.lua
+++ b/lua/core/telescope.lua
@@ -1,13 +1,19 @@
local M = {}
+
function M.config()
+ -- Define this minimal config so that it's available if telescope is not yet available.
+ lvim.builtin.telescope = {
+ ---@usage disable telescope completely [not recommeded]
+ active = true,
+ on_config_done = nil,
+ }
+
local status_ok, actions = pcall(require, "telescope.actions")
if not status_ok then
return
end
- lvim.builtin.telescope = {
- ---@usage disable telescope completely [not recommeded]
- active = true,
+ lvim.builtin.telescope = vim.tbl_extend("force", lvim.builtin.telescope, {
defaults = {
prompt_prefix = " ",
selection_caret = " ",
@@ -74,7 +80,7 @@ function M.config()
override_file_sorter = true,
},
},
- }
+ })
end
function M.find_lunarvim_files(opts)
@@ -112,15 +118,15 @@ function M.grep_lunarvim_files(opts)
end
function M.setup()
- local status_ok, telescope = pcall(require, "telescope")
- if not status_ok then
- local Log = require "core.log"
- Log:get_default().error "Failed to load telescope"
- return
- end
+ local telescope = require "telescope"
+
telescope.setup(lvim.builtin.telescope)
if lvim.builtin.project.active then
- pcall(require("telescope").load_extension, "projects")
+ telescope.load_extension "projects"
+ end
+
+ if lvim.builtin.telescope.on_config_done then
+ lvim.builtin.telescope.on_config_done(telescope)
end
end
diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua
index 661e5b3b..4fced26e 100644
--- a/lua/core/terminal.lua
+++ b/lua/core/terminal.lua
@@ -3,6 +3,7 @@ local utils = require "utils"
M.config = function()
lvim.builtin["terminal"] = {
+ on_config_done = nil,
-- size can be a number or function which is passed the current terminal
size = 20,
-- open_mapping = [[<c-\>]],
@@ -50,6 +51,10 @@ M.setup = function()
require("core.terminal").add_exec(exec[1], exec[2], exec[3])
end
terminal.setup(lvim.builtin.terminal)
+
+ if lvim.builtin.terminal.on_config_done then
+ lvim.builtin.terminal.on_config_done(terminal)
+ end
end
M.add_exec = function(exec, keymap, name)
diff --git a/lua/core/treesitter.lua b/lua/core/treesitter.lua
index 0a8a2ff2..d63024e6 100644
--- a/lua/core/treesitter.lua
+++ b/lua/core/treesitter.lua
@@ -1,7 +1,9 @@
local M = {}
local Log = require "core.log"
+
M.config = function()
lvim.builtin.treesitter = {
+ on_config_done = nil,
ensure_installed = {}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages
ignore_install = {},
matchup = {
@@ -70,6 +72,10 @@ M.setup = function()
end
treesitter_configs.setup(lvim.builtin.treesitter)
+
+ if lvim.builtin.treesitter.on_config_done then
+ lvim.builtin.treesitter.on_config_done(treesitter_configs)
+ end
end
return M
diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua
index 5b249430..71c0b695 100644
--- a/lua/core/which-key.lua
+++ b/lua/core/which-key.lua
@@ -1,8 +1,10 @@
local M = {}
+
M.config = function()
lvim.builtin.which_key = {
---@usage disable which-key completely [not recommeded]
active = true,
+ on_config_done = nil,
setup = {
plugins = {
marks = true, -- shows a list of your marks on ' and `
@@ -241,6 +243,10 @@ M.setup = function()
which_key.register(mappings, opts)
which_key.register(vmappings, vopts)
+
+ if lvim.builtin.which_key.on_config_done then
+ lvim.builtin.which_key.on_config_done(which_key)
+ end
end
return M
diff --git a/lua/default-config.lua b/lua/default-config.lua
index e88fee8d..9d84efaa 100644
--- a/lua/default-config.lua
+++ b/lua/default-config.lua
@@ -15,24 +15,7 @@ lvim = {
database = { save_location = "~/.config/lunarvim_db", auto_execute = 1 },
keys = {},
- -- TODO why do we need this?
- builtin = {
- lspinstall = {},
- telescope = {},
- compe = {},
- autopairs = {},
- treesitter = {},
- nvimtree = {},
- gitsigns = {},
- which_key = {},
- comment = {},
- project = {},
- lualine = {},
- bufferline = {},
- dap = {},
- dashboard = {},
- terminal = {},
- },
+ builtin = {},
log = {
---@usage can be { "trace", "debug", "info", "warn", "error", "fatal" },
@@ -1178,6 +1161,7 @@ lvim.lang = {
},
}
+-- NOTE: which-key should be first because it defines lvim.builtin.which_key.mappings
require("keymappings").config()
require("core.which-key").config()
require("core.gitsigns").config()
@@ -1192,4 +1176,5 @@ require("core.project").config()
require("core.bufferline").config()
require("core.autopairs").config()
require("core.comment").config()
+require("core.lspinstall").config()
require("core.lualine").config()
diff --git a/lua/plugins.lua b/lua/plugins.lua
index 9aaea922..5aaac3ce 100644
--- a/lua/plugins.lua
+++ b/lua/plugins.lua
@@ -8,11 +8,8 @@ return {
"kabouzeid/nvim-lspinstall",
event = "VimEnter",
config = function()
- local lspinstall = require "lspinstall"
+ local lspinstall = require "core.lspinstall"
lspinstall.setup()
- if lvim.builtin.lspinstall.on_config_done then
- lvim.builtin.lspinstall.on_config_done(lspinstall)
- end
end,
},
@@ -23,9 +20,6 @@ return {
"nvim-telescope/telescope.nvim",
config = function()
require("core.telescope").setup()
- if lvim.builtin.telescope.on_config_done then
- lvim.builtin.telescope.on_config_done(require "telescope")
- end
end,
disable = not lvim.builtin.telescope.active,
},
@@ -36,9 +30,6 @@ return {
event = "InsertEnter",
config = function()
require("core.compe").setup()
- if lvim.builtin.compe.on_config_done then
- lvim.builtin.compe.on_config_done(require "compe")
- end
end,
disable = not lvim.builtin.compe.active,
-- wants = "vim-vsnip",
@@ -73,9 +64,6 @@ return {
after = "nvim-compe",
config = function()
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,
},
@@ -87,9 +75,6 @@ return {
-- run = ":TSUpdate",
config = function()
require("core.treesitter").setup()
- if lvim.builtin.treesitter.on_config_done then
- lvim.builtin.treesitter.on_config_done(require "nvim-treesitter.configs")
- end
end,
},
@@ -101,9 +86,6 @@ return {
-- commit = "fd7f60e242205ea9efc9649101c81a07d5f458bb",
config = function()
require("core.nvimtree").setup()
- if lvim.builtin.nvimtree.on_config_done then
- lvim.builtin.nvimtree.on_config_done(require "nvim-tree.config")
- end
end,
disable = not lvim.builtin.nvimtree.active,
},
@@ -113,9 +95,6 @@ return {
config = function()
require("core.gitsigns").setup()
- if lvim.builtin.gitsigns.on_config_done then
- lvim.builtin.gitsigns.on_config_done(require "gitsigns")
- end
end,
event = "BufRead",
disable = not lvim.builtin.gitsigns.active,
@@ -126,9 +105,6 @@ return {
"folke/which-key.nvim",
config = function()
require("core.which-key").setup()
- if lvim.builtin.which_key.on_config_done then
- lvim.builtin.which_key.on_config_done(require "which-key")
- end
end,
event = "BufWinEnter",
disable = not lvim.builtin.which_key.active,
@@ -140,9 +116,6 @@ return {
event = "BufRead",
config = function()
require("nvim_comment").setup()
- if lvim.builtin.comment.on_config_done then
- lvim.builtin.comment.on_config_done(require "nvim_comment")
- end
end,
disable = not lvim.builtin.comment.active,
},
@@ -152,9 +125,6 @@ return {
"ahmedkhalf/project.nvim",
config = function()
require("core.project").setup()
- if lvim.builtin.project.on_config_done then
- lvim.builtin.project.on_config_done()
- end
end,
disable = not lvim.builtin.project.active,
},
@@ -177,9 +147,6 @@ return {
"romgrk/barbar.nvim",
config = function()
require("core.bufferline").setup()
- if lvim.builtin.bufferline.on_config_done then
- lvim.builtin.bufferline.on_config_done()
- end
end,
event = "BufWinEnter",
disable = not lvim.builtin.bufferline.active,
@@ -191,9 +158,6 @@ return {
-- event = "BufWinEnter",
config = function()
require("core.dap").setup()
- if lvim.builtin.dap.on_config_done then
- lvim.builtin.dap.on_config_done(require "dap")
- end
end,
disable = not lvim.builtin.dap.active,
},
@@ -212,9 +176,6 @@ return {
event = "BufWinEnter",
config = function()
require("core.dashboard").setup()
- if lvim.builtin.dashboard.on_config_done then
- lvim.builtin.dashboard.on_config_done(require "dashboard")
- end
end,
disable = not lvim.builtin.dashboard.active,
},
@@ -225,9 +186,6 @@ return {
event = "BufWinEnter",
config = function()
require("core.terminal").setup()
- if lvim.builtin.terminal.on_config_done then
- lvim.builtin.terminal.on_config_done(require "toggleterm")
- end
end,
disable = not lvim.builtin.terminal.active,
},