From 1b5730d51195fee74f3544bd29d017c46da3dea3 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Wed, 11 Aug 2021 17:29:20 +0200 Subject: feat: make autopairs configurable --- lua/core/autopairs.lua | 95 ++++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 42 deletions(-) (limited to 'lua/core') diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index a5f21a1b..53572a5b 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -1,54 +1,65 @@ --- 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 on insert mode + map_cr = true, + ---@usage it will auto insert after select function or method item, + map_complete = map_complete_optional, + ---@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 Log = require "core.log" + 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 "") + 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 "") + else + return npairs.esc "" + end else - return npairs.esc "" + 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 on insert mode - map_complete = map_complete_optional, -- it will auto insert `(` after select function or method item + if package.loaded["compe"] then + local map_complete_optional = vim.bo.filetype ~= "tex" + 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 -- cgit v1.2.3 From fb388d7ff81bdedf6e43c077dbf45e4288d45a49 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Wed, 11 Aug 2021 17:39:06 +0200 Subject: fix map_complete option --- lua/core/autopairs.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lua/core') diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index 53572a5b..9309bac9 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -5,8 +5,8 @@ function M.config() active = true, ---@usage map on insert mode map_cr = true, - ---@usage it will auto insert after select function or method item, - map_complete = map_complete_optional, + ---@usage auto insert after select function or method item, + map_complete = vim.bo.filetype ~= "tex", ---@usage check treesitter check_ts = true, ts_config = { @@ -20,7 +20,6 @@ end M.setup = function() -- skip it, if you use another global object _G.MUtils = {} - local Log = require "core.log" local npairs = require "nvim-autopairs" local Rule = require "nvim-autopairs.rule" @@ -38,7 +37,6 @@ M.setup = function() end if package.loaded["compe"] then - local map_complete_optional = vim.bo.filetype ~= "tex" require("nvim-autopairs.completion.compe").setup { map_cr = lvim.builtin.autopairs.map_cr, map_complete = lvim.builtin.autopairs.map_complete, -- cgit v1.2.3 From a3344203818658441d176fe279e1978505940432 Mon Sep 17 00:00:00 2001 From: Andrew Fridley <34749972+afridley@users.noreply.github.com> Date: Thu, 12 Aug 2021 00:49:37 -0500 Subject: Please... reverse history and cycle next telescope bindings (#1276) --- lua/core/telescope.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lua/core') diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index f4d154b0..f8862260 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -60,8 +60,8 @@ M.config = function() -- [""] = actions.select_default + actions.center + my_cool_custom_action, }, n = { - [""] = actions.move_selection_next, - [""] = actions.move_selection_previous, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, [""] = actions.smart_send_to_qflist + actions.open_qflist, -- [""] = trouble.open_with_trouble, -- [""] = my_cool_custom_action, -- cgit v1.2.3 From 4fd72b1be2c1220a519d5b8d58219939a11df0c9 Mon Sep 17 00:00:00 2001 From: abzcoding Date: Thu, 12 Aug 2021 12:05:54 +0430 Subject: Revert "Merge pull request #1294 from kylo252/autopairs-refactor" This reverts commit d71c3280c88c72665a21875522f0be3b157075b4, reversing changes made to a3344203818658441d176fe279e1978505940432. --- lua/core/autopairs.lua | 93 +++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 51 deletions(-) (limited to 'lua/core') diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index 9309bac9..a5f21a1b 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -1,63 +1,54 @@ -local M = {} - -function M.config() - lvim.builtin.autopairs = { - active = true, - ---@usage map on insert mode - map_cr = true, - ---@usage auto insert after select function or method item, - map_complete = vim.bo.filetype ~= "tex", - ---@usage check treesitter - check_ts = true, - ts_config = { - lua = { "string" }, - javascript = { "template_string" }, - java = false, - }, - } +-- 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 end +local npairs = require "nvim-autopairs" +local Rule = require "nvim-autopairs.rule" -M.setup = function() - -- skip it, if you use another global object - _G.MUtils = {} - local npairs = require "nvim-autopairs" - local Rule = require "nvim-autopairs.rule" +-- skip it, if you use another global object +_G.MUtils = {} - 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 "") - else - return npairs.esc "" - end +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 "") else - return npairs.autopairs_cr() + return npairs.esc "" end + else + return npairs.autopairs_cr() end +end - 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, +if package.loaded["compe"] then + local map_complete_optional = vim.bo.filetype ~= "tex" + require("nvim-autopairs.completion.compe").setup { + map_cr = true, -- map on insert mode + map_complete = map_complete_optional, -- it will auto insert `(` after select function or method item } +end - require("nvim-treesitter.configs").setup { autopairs = { enable = true } } +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 + }, +} - local ts_conds = require "nvim-autopairs.ts-conds" +require("nvim-treesitter.configs").setup { autopairs = { enable = true } } - -- 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 +local ts_conds = require "nvim-autopairs.ts-conds" -return M +-- 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" }), +} -- cgit v1.2.3 From 6bbce4ee07ac8428846dfb6722e15a932d6d9e05 Mon Sep 17 00:00:00 2001 From: Pasi Bergman Date: Thu, 12 Aug 2021 15:58:45 +0300 Subject: fix: use correct highlight group with LvimInfo (#1302) --- lua/core/info.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lua/core') diff --git a/lua/core/info.lua b/lua/core/info.lua index 56fc3ca2..5e5c5edc 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -204,8 +204,8 @@ function M.toggle_popup(ft) local function set_syntax_hl() vim.cmd [[highlight LvimInfoIdentifier gui=bold]] vim.cmd [[highlight link LvimInfoHeader Type]] - vim.cmd [[let m=matchadd("DashboardHeader", "Language Server Protocol (LSP) info")]] - vim.cmd [[let m=matchadd("DashboardHeader", "Formatters and linters")]] + vim.cmd [[let m=matchadd("LvimInfoHeader", "Language Server Protocol (LSP) info")]] + vim.cmd [[let m=matchadd("LvimInfoHeader", "Formatters and linters")]] vim.cmd('let m=matchadd("LvimInfoIdentifier", " ' .. ft .. '$")') vim.cmd 'let m=matchadd("string", "true")' vim.cmd 'let m=matchadd("error", "false")' -- cgit v1.2.3 From 53869f00be7eda020088342e6e1a160ef5fc2a53 Mon Sep 17 00:00:00 2001 From: Ahmed Khalf Date: Sat, 14 Aug 2021 00:16:04 +0400 Subject: Fix nvimtree quit to update bufferline (#1312) --- lua/core/nvimtree.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'lua/core') diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 4d15b1b5..25c69575 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -66,6 +66,7 @@ M.setup = function() { key = { "l", "", "o" }, cb = tree_cb "edit" }, { key = "h", cb = tree_cb "close_node" }, { key = "v", cb = tree_cb "vsplit" }, + { key = "q", cb = ":lua require('core.nvimtree').toggle_tree()" }, } end end -- cgit v1.2.3 From 70d139ac2771fac9b072aaebe505f9ac77480b2a Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Fri, 13 Aug 2021 22:32:56 +0200 Subject: [Refactor/Bugfix] Improve null ls handler (#1277) --- lua/core/galaxyline.lua | 8 ++++++-- lua/core/info.lua | 41 +++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 24 deletions(-) (limited to 'lua/core') diff --git a/lua/core/galaxyline.lua b/lua/core/galaxyline.lua index ee0a317d..512dd78c 100644 --- a/lua/core/galaxyline.lua +++ b/lua/core/galaxyline.lua @@ -204,19 +204,23 @@ table.insert(gls.right, { local function get_attached_provider_name(msg) msg = msg or "LSP Inactive" + local buf_clients = vim.lsp.buf_get_clients() if next(buf_clients) == nil then return msg end - local buf_ft = vim.bo.filetype + local buf_client_names = {} - local null_ls_providers = require("lsp.null-ls").get_registered_providers_by_filetype(buf_ft) for _, client in pairs(buf_clients) do if client.name ~= "null-ls" then table.insert(buf_client_names, client.name) end end + + local null_ls = require "lsp.null-ls" + local null_ls_providers = null_ls.list_supported_provider_names(vim.bo.filetype) vim.list_extend(buf_client_names, null_ls_providers) + return table.concat(buf_client_names, ", ") end diff --git a/lua/core/info.lua b/lua/core/info.lua index 5e5c5edc..1610e763 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -1,6 +1,4 @@ local M = {} -local u = require "utils" -local null_ls_handler = require "lsp.null-ls" local indent = " " M.banner = { @@ -25,7 +23,8 @@ local function str_list(list) end local function get_formatter_suggestion_msg(ft) - local supported_formatters = u.get_supported_formatters_by_filetype(ft) + local null_formatters = require "lsp.null-ls.formatters" + local supported_formatters = null_formatters.list_available(ft) return { indent .. "───────────────────────────────────────────────────────────────────", @@ -36,7 +35,7 @@ local function get_formatter_suggestion_msg(ft) indent .. "* Configured formatter needs to be installed and executable.", indent .. "* Enable installed formatter(s) with following config in ~/.config/lvim/config.lua", "", - indent .. " lvim.lang." .. tostring(ft) .. [[.formatting = { { exe = ']] .. table.concat( + indent .. " lvim.lang." .. tostring(ft) .. [[.formatters = { { exe = ']] .. table.concat( supported_formatters, "│" ) .. [[' } }]], @@ -45,7 +44,8 @@ local function get_formatter_suggestion_msg(ft) end local function get_linter_suggestion_msg(ft) - local supported_linters = u.get_supported_linters_by_filetype(ft) + local null_linters = require "lsp.null-ls.linters" + local supported_linters = null_linters.list_available(ft) return { indent .. "───────────────────────────────────────────────────────────────────", @@ -129,16 +129,14 @@ local function tbl_set_highlight(terms, highlight_group) end function M.toggle_popup(ft) - local client = u.get_active_client_by_ft(ft) + local lsp_utils = require "lsp.utils" + local client = lsp_utils.get_active_client_by_ft(ft) local is_client_active = false local client_enabled_caps = {} local client_name = "" local client_id = 0 local document_formatting = false - local missing_linters = {} - local missing_formatters = {} local num_caps = 0 - local null_ls_providers = null_ls_handler.get_registered_providers_by_filetype(ft) if client ~= nil then is_client_active = not client.is_stopped() client_enabled_caps = require("lsp").get_ls_capabilities(client.id) @@ -147,10 +145,6 @@ function M.toggle_popup(ft) client_id = client.id document_formatting = client.resolved_capabilities.document_formatting end - if lvim.lang[ft] ~= nil then - missing_linters = lvim.lang[ft].linters._failed_requests or {} - missing_formatters = lvim.lang[ft].formatters._failed_requests or {} - end local buf_lines = {} vim.list_extend(buf_lines, M.banner) @@ -173,23 +167,27 @@ function M.toggle_popup(ft) } vim.list_extend(buf_lines, lsp_info) + local null_ls = require "lsp.null-ls" + local registered_providers = null_ls.list_supported_provider_names(ft) local null_ls_info = { indent .. "Formatters and linters", - indent .. "* Configured providers: " .. table.concat(null_ls_providers, "  , ") .. "  ", + indent .. "* Configured providers: " .. table.concat(registered_providers, "  , ") .. "  ", } vim.list_extend(buf_lines, null_ls_info) - local missing_formatters_status + local null_formatters = require "lsp.null-ls.formatters" + local missing_formatters = null_formatters.list_unsupported_names(ft) if vim.tbl_count(missing_formatters) > 0 then - missing_formatters_status = { + local missing_formatters_status = { indent .. "* Missing formatters: " .. table.concat(missing_formatters, "  , ") .. "  ", } vim.list_extend(buf_lines, missing_formatters_status) end - local missing_linters_status + local null_linters = require "lsp.null-ls.linters" + local missing_linters = null_linters.list_unsupported_names(ft) if vim.tbl_count(missing_linters) > 0 then - missing_linters_status = { + local missing_linters_status = { indent .. "* Missing linters: " .. table.concat(missing_linters, "  , ") .. "  ", } vim.list_extend(buf_lines, missing_linters_status) @@ -198,7 +196,6 @@ function M.toggle_popup(ft) vim.list_extend(buf_lines, { "" }) vim.list_extend(buf_lines, get_formatter_suggestion_msg(ft)) - vim.list_extend(buf_lines, get_linter_suggestion_msg(ft)) local function set_syntax_hl() @@ -209,11 +206,11 @@ function M.toggle_popup(ft) vim.cmd('let m=matchadd("LvimInfoIdentifier", " ' .. ft .. '$")') vim.cmd 'let m=matchadd("string", "true")' vim.cmd 'let m=matchadd("error", "false")' - tbl_set_highlight(null_ls_providers, "LvimInfoIdentifier") + tbl_set_highlight(registered_providers, "LvimInfoIdentifier") tbl_set_highlight(missing_formatters, "LvimInfoIdentifier") tbl_set_highlight(missing_linters, "LvimInfoIdentifier") - -- tbl_set_highlight(u.get_supported_formatters_by_filetype(ft), "LvimInfoIdentifier") - -- tbl_set_highlight(u.get_supported_linters_by_filetype(ft), "LvimInfoIdentifier") + -- tbl_set_highlight(require("lsp.null-ls.formatters").list_available(ft), "LvimInfoIdentifier") + -- tbl_set_highlight(require("lsp.null-ls.linters").list_available(ft), "LvimInfoIdentifier") vim.cmd('let m=matchadd("LvimInfoIdentifier", "' .. client_name .. '")') end -- cgit v1.2.3 From 9c9bcb1e0a1074e03290bae9c2c247b9c2a02b0f Mon Sep 17 00:00:00 2001 From: Pasi Bergman Date: Sat, 14 Aug 2021 14:43:48 +0300 Subject: fix: lviminfo highlight match fix (#1316) --- lua/core/info.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua/core') diff --git a/lua/core/info.lua b/lua/core/info.lua index 1610e763..d5bd94ce 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -124,7 +124,7 @@ local function tbl_set_highlight(terms, highlight_group) end for _, v in pairs(terms) do - vim.cmd('let m=matchadd("' .. highlight_group .. '", "' .. v .. '")') + vim.cmd('let m=matchadd("' .. highlight_group .. '", "' .. v .. "[ ,│']\")") end end -- cgit v1.2.3 From fe55935c056a6b5f3dafa606b253324b1edc7ab5 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 14 Aug 2021 14:16:38 +0200 Subject: feat: use telescope to quickly open lunarvim files (#1310) --- lua/core/telescope.lua | 38 ++++++++++++++++++++++++++++++++++++-- lua/core/which-key.lua | 12 ++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) (limited to 'lua/core') diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index f8862260..30533b65 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -1,6 +1,6 @@ local M = {} local Log = require "core.log" -M.config = function() +function M.config() local status_ok, actions = pcall(require, "telescope.actions") if not status_ok then return @@ -77,7 +77,41 @@ M.config = function() } end -M.setup = function() +function M.find_lunarvim_files(opts) + opts = opts or {} + local themes = require "telescope.themes" + local theme_opts = themes.get_ivy { + previewer = false, + sorting_strategy = "ascending", + layout_strategy = "bottom_pane", + layout_config = { + height = 5, + width = 0.5, + }, + prompt = ">> ", + prompt_title = "~ LunarVim files ~", + cwd = CONFIG_PATH, + find_command = { "git", "ls-files" }, + } + opts = vim.tbl_deep_extend("force", theme_opts, opts) + require("telescope.builtin").find_files(opts) +end + +function M.grep_lunarvim_files(opts) + opts = opts or {} + local themes = require "telescope.themes" + local theme_opts = themes.get_ivy { + sorting_strategy = "ascending", + layout_strategy = "bottom_pane", + prompt = ">> ", + prompt_title = "~ search LunarVim ~", + cwd = CONFIG_PATH, + } + opts = vim.tbl_deep_extend("force", theme_opts, opts) + require("telescope.builtin").live_grep(opts) +end + +function M.setup() local status_ok, telescope = pcall(require, "telescope") if not status_ok then Log:get_default().error "Failed to load telescope" diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 96f3a8f7..66e3ffbb 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -169,6 +169,18 @@ M.config = function() }, L = { name = "+LunarVim", + c = { + "edit ~/.config/lvim/config.lua", + "Edit config.lua", + }, + f = { + "lua require('core.telescope').find_lunarvim_files()", + "Find LunarVim files", + }, + g = { + "lua require('core.telescope').grep_lunarvim_files()", + "Grep LunarVim files", + }, k = { "lua require('keymappings').print()", "View LunarVim's default keymappings" }, i = { "lua require('core.info').toggle_popup(vim.bo.filetype)", -- cgit v1.2.3 From 0fbf66e379f10d816d875583f6805ab7e3ea9e78 Mon Sep 17 00:00:00 2001 From: Marcelo Cerri Date: Sat, 14 Aug 2021 16:56:37 -0300 Subject: Add a new option to show the mode name in galaxyline (#1303) --- lua/core/galaxyline.lua | 24 ++++++++++++++++++++++++ lua/core/status_colors.lua | 1 + 2 files changed, 25 insertions(+) (limited to 'lua/core') diff --git a/lua/core/galaxyline.lua b/lua/core/galaxyline.lua index 512dd78c..0f31ef53 100644 --- a/lua/core/galaxyline.lua +++ b/lua/core/galaxyline.lua @@ -18,6 +18,20 @@ local condition = require "galaxyline.condition" local gls = gl.section gl.short_line_list = { "NvimTree", "vista", "dbui", "packer" } +local function get_mode_name() + local names = { + n = "NORMAL", + i = "INSERT", + c = "COMMAND", + v = "VISUAL", + V = "VISUAL LINE", + t = "TERMINAL", + R = "REPLACE", + [""] = "VISUAL BLOCK", + } + return names[vim.fn.mode()] +end + table.insert(gls.left, { ViMode = { provider = function() @@ -44,6 +58,16 @@ table.insert(gls.left, { ["!"] = colors.blue, t = colors.blue, } + if lvim.builtin.galaxyline.show_mode then + local name = get_mode_name() + -- Fall back to the default behavior is a name is not defined + if name ~= nil then + vim.api.nvim_command("hi GalaxyViMode guibg=" .. mode_color[vim.fn.mode()]) + vim.api.nvim_command("hi GalaxyViMode guifg=" .. colors.alt_bg) + return " " .. name .. " " + end + end + vim.api.nvim_command("hi GalaxyViMode guibg=" .. colors.alt_bg) vim.api.nvim_command("hi GalaxyViMode guifg=" .. mode_color[vim.fn.mode()]) return "▊" end, diff --git a/lua/core/status_colors.lua b/lua/core/status_colors.lua index 37e9d7c9..d6317309 100644 --- a/lua/core/status_colors.lua +++ b/lua/core/status_colors.lua @@ -1,5 +1,6 @@ lvim.builtin.galaxyline = { active = true, + show_mode = false, colors = { alt_bg = "#2E2E2E", grey = "#858585", -- cgit v1.2.3 From 6eb75c5678ddb4d040f644e331e222078b99b3a1 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 15 Aug 2021 17:38:47 +0200 Subject: [Refactor] Clean-up redundant module-load checks (#1011) --- lua/core/compe.lua | 7 +------ lua/core/dap.lua | 7 +------ lua/core/gitsigns.lua | 8 +------- lua/core/telescope.lua | 2 +- lua/core/terminal.lua | 17 ++++------------- lua/core/which-key.lua | 16 +++------------- 6 files changed, 11 insertions(+), 46 deletions(-) (limited to 'lua/core') diff --git a/lua/core/compe.lua b/lua/core/compe.lua index c2f97e27..b5b37805 100644 --- a/lua/core/compe.lua +++ b/lua/core/compe.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" M.config = function() lvim.builtin.compe = { enabled = true, @@ -61,11 +60,7 @@ end M.setup = function() vim.g.vsnip_snippet_dir = lvim.vsnip_dir - local status_ok, compe = pcall(require, "compe") - if not status_ok then - Log:get_default().error "Failed to load compe" - return - end + local compe = require "compe" compe.setup(lvim.builtin.compe) diff --git a/lua/core/dap.lua b/lua/core/dap.lua index 4e21cc4c..259ff87e 100644 --- a/lua/core/dap.lua +++ b/lua/core/dap.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" M.config = function() lvim.builtin.dap = { active = false, @@ -13,11 +12,7 @@ M.config = function() end M.setup = function() - local status_ok, dap = pcall(require, "dap") - if not status_ok then - Log:get_default().error "Failed to load dap" - return - end + local dap = require "dap" vim.fn.sign_define("DapBreakpoint", lvim.builtin.dap.breakpoint) dap.defaults.fallback.terminal_win_cmd = "50vsplit new" diff --git a/lua/core/gitsigns.lua b/lua/core/gitsigns.lua index 9e023762..0c0efa91 100644 --- a/lua/core/gitsigns.lua +++ b/lua/core/gitsigns.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" M.config = function() lvim.builtin.gitsigns = { signs = { @@ -49,12 +48,7 @@ M.config = function() end M.setup = function() - local status_ok, gitsigns = pcall(require, "gitsigns") - if not status_ok then - Log:get_default().error "Failed to load gitsigns" - return - end - gitsigns.setup(lvim.builtin.gitsigns) + require("gitsigns").setup(lvim.builtin.gitsigns) end return M diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index 30533b65..d31edef9 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" function M.config() local status_ok, actions = pcall(require, "telescope.actions") if not status_ok then @@ -114,6 +113,7 @@ 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 diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index 818038fd..661e5b3b 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" local utils = require "utils" M.config = function() @@ -46,22 +45,13 @@ M.config = function() end M.setup = function() - local status_ok, terminal = pcall(require, "toggleterm") - if not status_ok then - Log:get_default().error "Failed to load toggleterm" - print(terminal) - return - end + local terminal = require "toggleterm" for _, exec in pairs(lvim.builtin.terminal.execs) do require("core.terminal").add_exec(exec[1], exec[2], exec[3]) end terminal.setup(lvim.builtin.terminal) end -local function is_installed(exe) - return vim.fn.executable(exe) == 1 -end - M.add_exec = function(exec, keymap, name) vim.api.nvim_set_keymap( "n", @@ -85,8 +75,9 @@ end M._exec_toggle = function(exec) local binary = M._split(exec)[1] - if is_installed(binary) ~= true then - print("Please install executable " .. binary .. ". Check documentation for more information") + if vim.fn.executable(binary) ~= 1 then + local Log = require "core.log" + Log:get_default().error("Unable to run executable " .. binary .. ". Please make sure it is installed properly.") return end local Terminal = require("toggleterm.terminal").Terminal diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 66e3ffbb..04f892d8 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -1,5 +1,4 @@ local M = {} -local Log = require "core.log" M.config = function() lvim.builtin.which_key = { active = false, @@ -230,14 +229,7 @@ M.config = function() end M.setup = function() - -- if not package.loaded['which-key'] then - -- return - -- end - local status_ok, which_key = pcall(require, "which-key") - if not status_ok then - Log:get_default "Failed to load whichkey" - return - end + local which_key = require "which-key" which_key.setup(lvim.builtin.which_key.setup) @@ -247,10 +239,8 @@ M.setup = function() local mappings = lvim.builtin.which_key.mappings local vmappings = lvim.builtin.which_key.vmappings - local wk = require "which-key" - - wk.register(mappings, opts) - wk.register(vmappings, vopts) + which_key.register(mappings, opts) + which_key.register(vmappings, vopts) end return M -- cgit v1.2.3 From 9b36872d886c632ca93479321cde1e0f00629e3c Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Mon, 16 Aug 2021 15:07:46 +0200 Subject: [Feature] Encapsulate interface logic (#1320) * Provide a utility function for aligning text * Replace lvim banner with one using only ASCII chars * Use strings.format instead of .. operator * Center text in the popup based on its dimentions * Minor improvements * Provide a popup factory function * Add function documentation * Improve text alignment * Print marker only if provider list is not empty * Format client capabilities as list * Pretty format lsp client capabilities * Add a metatable to popup.lua * Improve rendering when no lsp is available * Take cmdheight into acount when computing popup size and pos Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com> --- lua/core/info.lua | 239 +++++++++++++++++++++++------------------------------- 1 file changed, 102 insertions(+), 137 deletions(-) (limited to 'lua/core') diff --git a/lua/core/info.lua b/lua/core/info.lua index d5bd94ce..d9b348b5 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -1,128 +1,63 @@ -local M = {} -local indent = " " - -M.banner = { - " ", - indent - .. "⠀⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀ ⠀⠀⠀ ⠀⠀ ⣺⡿⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀", - indent - .. "⠀⣿⠇⠀⠀⠀⠀⠀⣤⡄⠀⠀⢠⣤⡄⠀.⣠⣤⣤⣤⡀⠀⠀⢀⣤⣤⣤⣤⡄⠀⠀⠀⣤⣄⣤⣤⣤⠀⠀ ⣿⣯ ⣿⡟⠀ ⣤⣤⠀⠀⠀⠀⣠⣤⣤⣤⣄⣤⣤", - indent - .. "⢠⣿⠀⠀⠀⠀⠀⠀⣿⠃⠀⠀⣸⣿⠁⠀⣿⣿⠉⠀⠈⣿⡇⠀⠀⠛⠋⠀⠀⢹⣿⠀⠀⠀⣿⠏⠀⠸⠿⠃⠀⣿⣿⠀⣰⡟⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡟⢸⣿⡇⢀⣿", - indent - .. "⣸⡇⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⣿⡟⠀⢠⣿⡇⠀⠀⢰⣿⡇⠀⣰⣾⠟⠛⠛⣻⡇⠀⠀⢸⡿⠀⠀⠀⠀⠀⠀⢻⣿⢰⣿⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⢸⣿⠇⢸⣿⠀⢸⡏", - indent - .. "⣿⣧⣤⣤⣤⡄⠀⠘⣿⣤⣤⡤⣿⠇⠀⢸⣿⠁⠀⠀⣼⣿⠀⠀⢿⣿⣤⣤⠔⣿⠃⠀⠀⣾⡇⠀⠀⠀⠀⠀⠀⢸⣿⣿⠋⠀⠀⠀⢠⣤⣤⣿⣥⣤⡄⠀⣼⣿⠀⣸⡏⠀⣿⠃", - indent - .. "⠉⠉⠉⠉⠉⠁⠀⠀⠈⠉⠉⠀⠉⠀⠀⠈⠉⠀⠀⠀⠉⠉⠀⠀⠀⠉⠉⠁⠈⠉⠀⠀⠀⠉⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠀⠀⠀⠀⠈⠉⠉⠉⠉⠉⠁⠀⠉⠁⠀⠉⠁⠀⠉⠀", - "", +local M = { + banner = { + "", + [[ __ _ ___ ]], + [[ / / __ ______ ____ _____| | / (_)___ ___ ]], + [[ / / / / / / __ \/ __ `/ ___/ | / / / __ `__ \]], + [[ / /___/ /_/ / / / / /_/ / / | |/ / / / / / / /]], + [[/_____/\__,_/_/ /_/\__,_/_/ |___/_/_/ /_/ /_/ ]], + }, } +local fmt = string.format + local function str_list(list) - return "[ " .. table.concat(list, ", ") .. " ]" + return fmt("[ %s ]", table.concat(list, ", ")) end local function get_formatter_suggestion_msg(ft) local null_formatters = require "lsp.null-ls.formatters" local supported_formatters = null_formatters.list_available(ft) - return { - indent - .. "───────────────────────────────────────────────────────────────────", - "", - indent .. " HINT ", - "", - indent .. "* List of supported formatters: " .. str_list(supported_formatters), - indent .. "* Configured formatter needs to be installed and executable.", - indent .. "* Enable installed formatter(s) with following config in ~/.config/lvim/config.lua", - "", - indent .. " lvim.lang." .. tostring(ft) .. [[.formatters = { { exe = ']] .. table.concat( - supported_formatters, - "│" - ) .. [[' } }]], + local section = { + " HINT ", "", + fmt("* List of supported formatters: %s", str_list(supported_formatters)), } + + if not vim.tbl_isempty(supported_formatters) then + vim.list_extend(section, { + "* Configured formatter needs to be installed and executable.", + fmt("* Enable installed formatter(s) with following config in %s", USER_CONFIG_PATH), + "", + fmt(" lvim.lang.%s.formatters = { { exe = '%s' } }", ft, table.concat(supported_formatters, "│")), + }) + end + + return section end local function get_linter_suggestion_msg(ft) local null_linters = require "lsp.null-ls.linters" local supported_linters = null_linters.list_available(ft) - return { - indent - .. "───────────────────────────────────────────────────────────────────", - "", - indent .. " HINT ", - "", - indent .. "* List of supported linters: " .. str_list(supported_linters), - indent .. "* Configured linter needs to be installed and executable.", - indent .. "* Enable installed linter(s) with following config in ~/.config/lvim/config.lua", - "", - indent - .. " lvim.lang." - .. tostring(ft) - .. [[.linters = { { exe = ']] - .. table.concat(supported_linters, "│") - .. [[' } }]], + local section = { + " HINT ", "", + fmt("* List of supported linters: %s", str_list(supported_linters)), } -end ----creates an average size popup ----@param buf_lines a list of lines to print ----@param callback could be used to set syntax highlighting rules for example ----@return bufnr buffer number of the created buffer ----@return win_id window ID of the created popup -function M.create_simple_popup(buf_lines, callback) - -- runtime/lua/vim/lsp/util.lua - local bufnr = vim.api.nvim_create_buf(false, true) - local height_percentage = 0.9 - local width_percentage = 0.8 - local row_start_percentage = (1 - height_percentage) / 2 - local col_start_percentage = (1 - width_percentage) / 2 - local opts = {} - opts.relative = "editor" - opts.height = math.min(math.ceil(vim.o.lines * height_percentage), #buf_lines) - opts.row = math.ceil(vim.o.lines * row_start_percentage) - opts.col = math.floor(vim.o.columns * col_start_percentage) - opts.width = math.floor(vim.o.columns * width_percentage) - opts.style = "minimal" - opts.border = "rounded" - --[[ - opts.border = { - lvim.builtin.telescope.defaults.borderchars[5], -- "┌", - lvim.builtin.telescope.defaults.borderchars[3], -- "-", - lvim.builtin.telescope.defaults.borderchars[6], -- "┐", - lvim.builtin.telescope.defaults.borderchars[2], -- "|", - lvim.builtin.telescope.defaults.borderchars[7], -- "┘", - lvim.builtin.telescope.defaults.borderchars[3], -- "-", - lvim.builtin.telescope.defaults.borderchars[8], -- "└", - lvim.builtin.telescope.defaults.borderchars[4], -- "|", - } - --]] - - local win_id = vim.api.nvim_open_win(bufnr, true, opts) - - vim.api.nvim_win_set_buf(win_id, bufnr) - -- this needs to be window option! - vim.api.nvim_win_set_option(win_id, "number", false) - vim.cmd "setlocal nocursorcolumn" - vim.cmd "setlocal wrap" - -- set buffer options - vim.api.nvim_buf_set_option(bufnr, "filetype", "lspinfo") - vim.lsp.util.close_preview_autocmd({ "BufHidden", "BufLeave" }, win_id) - buf_lines = vim.lsp.util._trim(buf_lines, {}) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, buf_lines) - vim.api.nvim_buf_set_option(bufnr, "modifiable", false) - if type(callback) == "function" then - callback() + if not vim.tbl_isempty(supported_linters) then + vim.list_extend(section, { + "* Configured linter needs to be installed and executable.", + fmt("* Enable installed linter(s) with following config in %s", USER_CONFIG_PATH), + "", + fmt(" lvim.lang.%s.linters = { { exe = '%s' } }", ft, table.concat(supported_linters, "│")), + }) end - return bufnr, win_id + + return section end local function tbl_set_highlight(terms, highlight_group) - if type(terms) ~= "table" then - return - end - for _, v in pairs(terms) do vim.cmd('let m=matchadd("' .. highlight_group .. '", "' .. v .. "[ ,│']\")") end @@ -136,67 +71,90 @@ function M.toggle_popup(ft) local client_name = "" local client_id = 0 local document_formatting = false - local num_caps = 0 if client ~= nil then is_client_active = not client.is_stopped() client_enabled_caps = require("lsp").get_ls_capabilities(client.id) - num_caps = vim.tbl_count(client_enabled_caps) client_name = client.name client_id = client.id document_formatting = client.resolved_capabilities.document_formatting end - local buf_lines = {} - vim.list_extend(buf_lines, M.banner) - local header = { - indent .. "Detected filetype: " .. tostring(ft), - indent .. "Treesitter active: " .. tostring(next(vim.treesitter.highlighter.active) ~= nil), - "", + fmt("Detected filetype: %s", ft), + fmt("Treesitter active: %s", tostring(next(vim.treesitter.highlighter.active) ~= nil)), } - vim.list_extend(buf_lines, header) + local text = require "interface.text" local lsp_info = { - indent .. "Language Server Protocol (LSP) info", - indent .. "* Associated server: " .. client_name, - indent .. "* Active: " .. tostring(is_client_active) .. " (id: " .. tostring(client_id) .. ")", - indent .. "* Supports formatting: " .. tostring(document_formatting), - indent .. "* Capabilities list: " .. table.concat(vim.list_slice(client_enabled_caps, 1, num_caps / 2), ", "), - indent .. indent .. indent .. table.concat(vim.list_slice(client_enabled_caps, ((num_caps / 2) + 1)), ", "), - "", + "Language Server Protocol (LSP) info", + fmt("* Associated server: %s", client_name), + fmt("* Active: %s (id: %d)", tostring(is_client_active), client_id), + fmt("* Supports formatting: %s", tostring(document_formatting)), } - vim.list_extend(buf_lines, lsp_info) - + if not vim.tbl_isempty(client_enabled_caps) then + local caps_text = "* Capabilities list: " + local caps_text_len = caps_text:len() + local enabled_caps = text.format_table(client_enabled_caps, 3, " | ") + enabled_caps = text.shift_left(enabled_caps, caps_text_len) + enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1)) + vim.list_extend(lsp_info, enabled_caps) + end local null_ls = require "lsp.null-ls" local registered_providers = null_ls.list_supported_provider_names(ft) + local registered_count = vim.tbl_count(registered_providers) local null_ls_info = { - indent .. "Formatters and linters", - indent .. "* Configured providers: " .. table.concat(registered_providers, "  , ") .. "  ", + "Formatters and linters", + fmt( + "* Configured providers: %s%s", + table.concat(registered_providers, "  , "), + registered_count > 0 and "  " or "" + ), } - vim.list_extend(buf_lines, null_ls_info) local null_formatters = require "lsp.null-ls.formatters" local missing_formatters = null_formatters.list_unsupported_names(ft) - if vim.tbl_count(missing_formatters) > 0 then - local missing_formatters_status = { - indent .. "* Missing formatters: " .. table.concat(missing_formatters, "  , ") .. "  ", + local missing_formatters_status = {} + if not vim.tbl_isempty(missing_formatters) then + missing_formatters_status = { + fmt("* Missing formatters: %s", table.concat(missing_formatters, "  , ") .. "  "), } - vim.list_extend(buf_lines, missing_formatters_status) end local null_linters = require "lsp.null-ls.linters" local missing_linters = null_linters.list_unsupported_names(ft) - if vim.tbl_count(missing_linters) > 0 then - local missing_linters_status = { - indent .. "* Missing linters: " .. table.concat(missing_linters, "  , ") .. "  ", + local missing_linters_status = {} + if not vim.tbl_isempty(missing_linters) then + missing_linters_status = { + fmt("* Missing linters: %s", table.concat(missing_linters, "  , ") .. "  "), } - vim.list_extend(buf_lines, missing_linters_status) end - vim.list_extend(buf_lines, { "" }) - - vim.list_extend(buf_lines, get_formatter_suggestion_msg(ft)) - vim.list_extend(buf_lines, get_linter_suggestion_msg(ft)) + local content_provider = function(popup) + local content = {} + + for _, section in ipairs { + M.banner, + { "" }, + { "" }, + header, + { "" }, + lsp_info, + { "" }, + null_ls_info, + missing_formatters_status, + missing_linters_status, + { "" }, + { "" }, + get_formatter_suggestion_msg(ft), + { "" }, + { "" }, + get_linter_suggestion_msg(ft), + } do + vim.list_extend(content, section) + end + + return text.align(popup, content, 0.5) + end local function set_syntax_hl() vim.cmd [[highlight LvimInfoIdentifier gui=bold]] @@ -214,6 +172,13 @@ function M.toggle_popup(ft) vim.cmd('let m=matchadd("LvimInfoIdentifier", "' .. client_name .. '")') end - return M.create_simple_popup(buf_lines, set_syntax_hl) + local Popup = require("interface.popup"):new { + win_opts = { number = false }, + buf_opts = { modifiable = false, filetype = "lspinfo" }, + } + Popup:display(content_provider) + set_syntax_hl() + + return Popup end return M -- cgit v1.2.3 From 8becb83eeba4c35c9d7fae90438f3d6ef60be790 Mon Sep 17 00:00:00 2001 From: rebuilt Date: Mon, 16 Aug 2021 18:46:36 +0200 Subject: Check if emmet is active. Enable emmet completion if emmet language server is active (#1335) * Check if emmet is active. Enable emmet completion if it is active * move emmet check after the check for a space character * Check if emmet is active for the current buffer only --- lua/core/compe.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lua/core') diff --git a/lua/core/compe.lua b/lua/core/compe.lua index b5b37805..9edb2af0 100644 --- a/lua/core/compe.lua +++ b/lua/core/compe.lua @@ -77,6 +77,17 @@ M.setup = function() end end + local is_emmet_active = function() + local clients = vim.lsp.buf_get_clients() + + for _, client in pairs(clients) do + if client.name == "emmet_ls" then + return true + end + end + return false + end + -- Use (s-)tab to: --- move to prev/next item in completion menuone --- jump to prev/next snippet's placeholder @@ -87,8 +98,9 @@ M.setup = function() return t "(vsnip-jump-next)" elseif check_back_space() then return t "" + elseif is_emmet_active() then + return vim.fn["compe#complete"]() else - -- return vim.fn["compe#complete"]() -- < use this if you want to always offer completion return t "" end end -- cgit v1.2.3 From 335e707b2aae38c0cd5d0d962b27038ab1117aa6 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Tue, 17 Aug 2021 17:20:18 +0200 Subject: [Feature] Make the rest of the builtins configurable (#1318) --- lua/core/autopairs.lua | 94 ++++++++++++++++++++++++++++---------------------- lua/core/comment.lua | 25 ++++++++++++++ lua/core/compe.lua | 2 +- lua/core/dashboard.lua | 17 +++------ lua/core/gitsigns.lua | 85 +++++++++++++++++++++++---------------------- lua/core/nvimtree.lua | 1 + lua/core/telescope.lua | 3 +- lua/core/which-key.lua | 3 +- 8 files changed, 132 insertions(+), 98 deletions(-) create mode 100644 lua/core/comment.lua (limited to 'lua/core') 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 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 "") + 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 "") + else + return npairs.esc "" + end else - return npairs.esc "" + 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 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[";"] = { "Dashboard", "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 ` -- cgit v1.2.3 From b9b9c69615b469146e3cc75adcf9bd61047404eb Mon Sep 17 00:00:00 2001 From: Ahmed Khalf Date: Wed, 18 Aug 2021 09:34:26 +0400 Subject: [Refactor]: Remove vim-rooter and smart-cwd; then use project.nvim (#1315) * Replace vim-rooter with project.nvim * Implement stylua format * Remove smart_cwd * Implicitly update nvim-tree dir when project active * Link datapath to cache * Fix stylua * Fix lint * Fix telescope bug * Fix telescope dependency * Fix telescope once and for all * Fix telescope once again --- lua/core/dashboard.lua | 11 ++++------- lua/core/nvimtree.lua | 6 ++++++ lua/core/project.lua | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ lua/core/rooter.lua | 15 --------------- lua/core/telescope.lua | 3 +++ 5 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 lua/core/project.lua delete mode 100644 lua/core/rooter.lua (limited to 'lua/core') diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index 649be14c..423cddd8 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -31,19 +31,16 @@ M.config = function() description = { " Find File " }, command = "Telescope find_files", }, - b = { + -- b is reserved for the core.project module + c = { description = { " Recently Used Files" }, command = "Telescope oldfiles", }, - -- c = { - -- description = { " Load Last Session " }, - -- command = "SessionLoad", - -- }, - c = { + d = { description = { " Find Word " }, command = "Telescope live_grep", }, - d = { + e = { description = { " Settings " }, command = ":e " .. USER_CONFIG_PATH, }, diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 7c99a91e..737f248e 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -60,6 +60,12 @@ M.setup = function() g["nvim_tree_" .. opt] = val end + -- Implicitly update nvim-tree when project module is active + if lvim.builtin.project.active then + vim.g.nvim_tree_update_cwd = 1 + vim.g.nvim_tree_respect_buf_cwd = 1 + end + local tree_cb = nvim_tree_config.nvim_tree_callback if not g.nvim_tree_bindings then diff --git a/lua/core/project.lua b/lua/core/project.lua new file mode 100644 index 00000000..650f2924 --- /dev/null +++ b/lua/core/project.lua @@ -0,0 +1,48 @@ +local M = {} +-- +function M.config() + lvim.builtin.project = { + --- This is on by default since it's currently the expected behavior. + ---@usage set to false to disable project.nvim. + active = true, + + -- Manual mode doesn't automatically change your root directory, so you have + -- the option to manually do so using `:ProjectRoot` command. + manual_mode = false, + + -- Methods of detecting the root directory. **"lsp"** uses the native neovim + -- lsp, while **"pattern"** uses vim-rooter like glob pattern matching. Here + -- order matters: if one is not detected, the other is used as fallback. You + -- can also delete or rearangne the detection methods. + detection_methods = { "lsp", "pattern" }, + + -- All the patterns used to detect root dir, when **"pattern"** is in + -- detection_methods + patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" }, + + -- When set to false, you will get a message when project.nvim changes your + -- directory. + silent_chdir = true, + } +end +-- +function M.setup() + local settings = lvim.builtin.project + + -- Table of lsp clients to ignore by name + -- eg: { "efm", ... } + settings["ignore_lsp"] = {} + + -- Path where project.nvim will store the project history for use in + -- telescope + settings["datapath"] = CACHE_PATH + + require("project_nvim").setup(settings) + + lvim.builtin.dashboard.custom_section["b"] = { + description = { " Recent Projects " }, + command = "Telescope projects", + } +end +-- +return M diff --git a/lua/core/rooter.lua b/lua/core/rooter.lua deleted file mode 100644 index 8ebdf7cc..00000000 --- a/lua/core/rooter.lua +++ /dev/null @@ -1,15 +0,0 @@ -local M = {} -function M.config() - lvim.builtin.rooter = { - --- This is on by default since it's currently the expected behavior. - ---@usage set to false to disable vim-rooter. - active = true, - silent_chdir = 1, - manual_only = 0, - } -end -function M.setup() - vim.g.rooter_silent_chdir = lvim.builtin.rooter.silent_chdir - vim.g.rooter_manual_only = lvim.builtin.rooter.manual_only -end -return M diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index e72727a4..5d9263d7 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -119,6 +119,9 @@ function M.setup() return end telescope.setup(lvim.builtin.telescope) + if lvim.builtin.project.active then + pcall(require("telescope").load_extension, "projects") + end end return M -- cgit v1.2.3 From 0bf6fd68c625396d83eb8fca8d7248c5543ae6f1 Mon Sep 17 00:00:00 2001 From: Binx <68950943+Binx-Codes@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:44:21 +0400 Subject: rename settings to configuration in dashboard (#1350) --- lua/core/dashboard.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua/core') diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index 423cddd8..f98721cc 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -41,7 +41,7 @@ M.config = function() command = "Telescope live_grep", }, e = { - description = { " Settings " }, + description = { " Configuration " }, command = ":e " .. USER_CONFIG_PATH, }, }, -- cgit v1.2.3 From 59598723077ac6728fc585c3c88e0ec84ba430c3 Mon Sep 17 00:00:00 2001 From: Ahmed Khalf Date: Fri, 20 Aug 2021 11:31:18 +0400 Subject: [Refactor]: consistent update of bufferline offset with nvim-tree (#1351) * Refactor nvim-tree * Fix stylua comments * Delete useless functions * Remove autocmd and fix tasty's bug * Fix luacheck * Fix icon issue * Fix formatting * Fix formatting again * Resolve Tasty's request * Replace double dashes with blank line --- lua/core/nvimtree.lua | 78 ++++++++++++++++++-------------------------------- lua/core/which-key.lua | 1 - 2 files changed, 28 insertions(+), 51 deletions(-) (limited to 'lua/core') diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 737f248e..ff52029d 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -1,6 +1,6 @@ local M = {} local Log = require "core.log" --- + M.config = function() lvim.builtin.nvimtree = { active = true, @@ -47,7 +47,7 @@ M.config = function() }, } end --- + M.setup = function() local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") if not status_ok then @@ -73,64 +73,42 @@ M.setup = function() { key = { "l", "", "o" }, cb = tree_cb "edit" }, { key = "h", cb = tree_cb "close_node" }, { key = "v", cb = tree_cb "vsplit" }, - { key = "q", cb = ":lua require('core.nvimtree').toggle_tree()" }, } end -end --- -M.focus_or_close = function() - local view_status_ok, view = pcall(require, "nvim-tree.view") - if not view_status_ok then - return - end - local a = vim.api - local curwin = a.nvim_get_current_win() - local curbuf = a.nvim_win_get_buf(curwin) - local bufnr = view.View.bufnr - local winnr = view.get_winnr() + lvim.builtin.which_key.mappings["e"] = { "NvimTreeToggle", "Explorer" } + + local tree_view = require "nvim-tree.view" - if view.win_open() then - if curwin == winnr and curbuf == bufnr then - view.close() - if package.loaded["bufferline.state"] then - require("bufferline.state").set_offset(0) - end - else - view.focus() - end - else - view.open() - if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then - -- require'bufferline.state'.set_offset(lvim.builtin.nvimtree.width + 1, 'File Explorer') - require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "") - end + -- Add nvim_tree open callback + local open = tree_view.open + tree_view.open = function() + M.on_open() + open() end + + vim.cmd "au WinClosed * lua require('core.nvimtree').on_close()" end --- -M.toggle_tree = function() - local view_status_ok, view = pcall(require, "nvim-tree.view") - if not view_status_ok then - return + +M.on_open = function() + if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then + require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "") end - if view.win_open() then - require("nvim-tree").close() - if package.loaded["bufferline.state"] then - require("bufferline.state").set_offset(0) - end - else - if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then - -- require'bufferline.state'.set_offset(lvim.builtin.nvimtree.width + 1, 'File Explorer') - require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "") - end - require("nvim-tree").toggle() +end + +M.on_close = function() + local buf = tonumber(vim.fn.expand "") + local ft = vim.api.nvim_buf_get_option(buf, "filetype") + if ft == "NvimTree" and package.loaded["bufferline.state"] then + require("bufferline.state").set_offset(0) end end --- + function M.change_tree_dir(dir) - if vim.g.loaded_tree then - require("nvim-tree.lib").change_dir(dir) + local lib_status_ok, lib = pcall(require, "nvim-tree.lib") + if lib_status_ok then + lib.change_dir(dir) end end --- + return M diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index ff53142c..5b249430 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -66,7 +66,6 @@ M.config = function() ["q"] = { "q!", "Quit" }, ["/"] = { "CommentToggle", "Comment" }, ["c"] = { "BufferClose!", "Close Buffer" }, - ["e"] = { "lua require'core.nvimtree'.toggle_tree()", "Explorer" }, ["f"] = { "Telescope find_files", "Find File" }, ["h"] = { "nohlsearch", "No Highlight" }, b = { -- cgit v1.2.3 From 85fe093efb8353552171575809c02a5e9124fa68 Mon Sep 17 00:00:00 2001 From: chaeing Date: Fri, 20 Aug 2021 02:16:29 -0700 Subject: [Feature] switch galaxyline to lualine (#1329) --- lua/core/galaxyline.lua | 348 ---------------------------------------- lua/core/lualine/colors.lua | 16 ++ lua/core/lualine/components.lua | 130 +++++++++++++++ lua/core/lualine/conditions.lua | 17 ++ lua/core/lualine/init.lua | 47 ++++++ lua/core/lualine/styles.lua | 170 ++++++++++++++++++++ lua/core/lualine/utils.lua | 24 +++ lua/core/status_colors.lua | 20 --- 8 files changed, 404 insertions(+), 368 deletions(-) delete mode 100644 lua/core/galaxyline.lua create mode 100644 lua/core/lualine/colors.lua create mode 100644 lua/core/lualine/components.lua create mode 100644 lua/core/lualine/conditions.lua create mode 100644 lua/core/lualine/init.lua create mode 100644 lua/core/lualine/styles.lua create mode 100644 lua/core/lualine/utils.lua delete mode 100644 lua/core/status_colors.lua (limited to 'lua/core') diff --git a/lua/core/galaxyline.lua b/lua/core/galaxyline.lua deleted file mode 100644 index 0f31ef53..00000000 --- a/lua/core/galaxyline.lua +++ /dev/null @@ -1,348 +0,0 @@ --- if not package.loaded['galaxyline'] then --- return --- end -local Log = require "core.log" -local status_ok, gl = pcall(require, "galaxyline") -if not status_ok then - Log:get_default().error "Failed to load galaxyline" - return -end - --- NOTE: if someone defines colors but doesn't have them then this will break -local palette_status_ok, colors = pcall(require, lvim.colorscheme .. ".palette") -if not palette_status_ok then - colors = lvim.builtin.galaxyline.colors -end - -local condition = require "galaxyline.condition" -local gls = gl.section -gl.short_line_list = { "NvimTree", "vista", "dbui", "packer" } - -local function get_mode_name() - local names = { - n = "NORMAL", - i = "INSERT", - c = "COMMAND", - v = "VISUAL", - V = "VISUAL LINE", - t = "TERMINAL", - R = "REPLACE", - [""] = "VISUAL BLOCK", - } - return names[vim.fn.mode()] -end - -table.insert(gls.left, { - ViMode = { - provider = function() - -- auto change color according the vim mode - local mode_color = { - n = colors.blue, - i = colors.green, - v = colors.purple, - [""] = colors.purple, - V = colors.purple, - c = colors.magenta, - no = colors.blue, - s = colors.orange, - S = colors.orange, - [""] = colors.orange, - ic = colors.yellow, - R = colors.red, - Rv = colors.red, - cv = colors.blue, - ce = colors.blue, - r = colors.cyan, - rm = colors.cyan, - ["r?"] = colors.cyan, - ["!"] = colors.blue, - t = colors.blue, - } - if lvim.builtin.galaxyline.show_mode then - local name = get_mode_name() - -- Fall back to the default behavior is a name is not defined - if name ~= nil then - vim.api.nvim_command("hi GalaxyViMode guibg=" .. mode_color[vim.fn.mode()]) - vim.api.nvim_command("hi GalaxyViMode guifg=" .. colors.alt_bg) - return " " .. name .. " " - end - end - vim.api.nvim_command("hi GalaxyViMode guibg=" .. colors.alt_bg) - vim.api.nvim_command("hi GalaxyViMode guifg=" .. mode_color[vim.fn.mode()]) - return "▊" - end, - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { "NONE", colors.alt_bg }, - }, -}) --- print(vim.fn.getbufvar(0, 'ts')) -vim.fn.getbufvar(0, "ts") - -table.insert(gls.left, { - GitIcon = { - provider = function() - return " " - end, - condition = condition.check_git_workspace, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.orange, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - GitBranch = { - provider = "GitBranch", - condition = condition.check_git_workspace, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - DiffAdd = { - provider = "DiffAdd", - condition = condition.hide_in_width, - icon = "  ", - highlight = { colors.green, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - DiffModified = { - provider = "DiffModified", - condition = condition.hide_in_width, - icon = " 柳", - highlight = { colors.blue, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - DiffRemove = { - provider = "DiffRemove", - condition = condition.hide_in_width, - icon = "  ", - highlight = { colors.red, colors.alt_bg }, - }, -}) - -table.insert(gls.left, { - Filler = { - provider = function() - return " " - end, - highlight = { colors.grey, colors.alt_bg }, - }, -}) --- get output from shell command -function os.capture(cmd, raw) - local f = assert(io.popen(cmd, "r")) - local s = assert(f:read "*a") - f:close() - if raw then - return s - end - s = string.gsub(s, "^%s+", "") - s = string.gsub(s, "%s+$", "") - s = string.gsub(s, "[\n\r]+", " ") - return s -end --- cleanup virtual env -local function env_cleanup(venv) - if string.find(venv, "/") then - local final_venv = venv - for w in venv:gmatch "([^/]+)" do - final_venv = w - end - venv = final_venv - end - return venv -end -local PythonEnv = function() - if vim.bo.filetype == "python" then - local venv = os.getenv "CONDA_DEFAULT_ENV" - if venv ~= nil then - return "  (" .. env_cleanup(venv) .. ")" - end - venv = os.getenv "VIRTUAL_ENV" - if venv ~= nil then - return "  (" .. env_cleanup(venv) .. ")" - end - return "" - end - return "" -end -table.insert(gls.left, { - VirtualEnv = { - provider = PythonEnv, - event = "BufEnter", - highlight = { colors.green, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - DiagnosticError = { - provider = "DiagnosticError", - icon = "  ", - highlight = { colors.red, colors.alt_bg }, - }, -}) -table.insert(gls.right, { - DiagnosticWarn = { - provider = "DiagnosticWarn", - icon = "  ", - highlight = { colors.orange, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - DiagnosticInfo = { - provider = "DiagnosticInfo", - icon = "  ", - highlight = { colors.yellow, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - DiagnosticHint = { - provider = "DiagnosticHint", - icon = "  ", - highlight = { colors.blue, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - TreesitterIcon = { - provider = function() - if next(vim.treesitter.highlighter.active) ~= nil then - return " " - end - return "" - end, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.green, colors.alt_bg }, - }, -}) - -local function get_attached_provider_name(msg) - msg = msg or "LSP Inactive" - - local buf_clients = vim.lsp.buf_get_clients() - if next(buf_clients) == nil then - return msg - end - - local buf_client_names = {} - for _, client in pairs(buf_clients) do - if client.name ~= "null-ls" then - table.insert(buf_client_names, client.name) - end - end - - local null_ls = require "lsp.null-ls" - local null_ls_providers = null_ls.list_supported_provider_names(vim.bo.filetype) - vim.list_extend(buf_client_names, null_ls_providers) - - return table.concat(buf_client_names, ", ") -end - -table.insert(gls.right, { - ShowLspClient = { - provider = get_attached_provider_name, - condition = function() - local tbl = { ["dashboard"] = true, [" "] = true } - if tbl[vim.bo.filetype] then - return false - end - return true - end, - icon = " ", - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - LineInfo = { - provider = "LineColumn", - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - PerCent = { - provider = "LinePercent", - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - Tabstop = { - provider = function() - local label = "Spaces: " - if not vim.api.nvim_buf_get_option(0, "expandtab") then - label = "Tab size: " - end - return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " - end, - condition = condition.hide_in_width, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - BufferType = { - provider = "FileTypeName", - condition = condition.hide_in_width, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - FileEncode = { - provider = "FileEncode", - condition = condition.hide_in_width, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.right, { - Space = { - provider = function() - return " " - end, - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, - }, -}) - -table.insert(gls.short_line_left, { - BufferType = { - provider = "FileTypeName", - separator = " ", - separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.alt_bg, colors.alt_bg }, - }, -}) - -table.insert(gls.short_line_left, { - SFileName = { - provider = "SFileName", - condition = condition.buffer_not_empty, - highlight = { colors.alt_bg, colors.alt_bg }, - }, -}) - ---table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.alt_bg}}}) diff --git a/lua/core/lualine/colors.lua b/lua/core/lualine/colors.lua new file mode 100644 index 00000000..4984cd1f --- /dev/null +++ b/lua/core/lualine/colors.lua @@ -0,0 +1,16 @@ +local colors = { + bg = "#202328", + fg = "#bbc2cf", + yellow = "#ECBE7B", + cyan = "#008080", + darkblue = "#081633", + green = "#98be65", + orange = "#FF8800", + violet = "#a9a1e1", + magenta = "#c678dd", + purple = "#c678dd", + blue = "#51afef", + red = "#ec5f67", +} + +return colors diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua new file mode 100644 index 00000000..b9211a79 --- /dev/null +++ b/lua/core/lualine/components.lua @@ -0,0 +1,130 @@ +local conditions = require "core.lualine.conditions" +local colors = require "core.lualine.colors" + +return { + vi_mode = { + function() + return " " + end, + left_padding = 0, + right_padding = 0, + condition = conditions.hide_in_width, + }, + branch = { + "branch", + icon = " ", + condition = function() + return conditions.hide_in_width() and conditions.check_git_workspace() + end, + }, + diff = { + "diff", + symbols = { added = "  ", modified = "柳", removed = " " }, + color_added = { fg = colors.green }, + color_modified = { fg = colors.yellow }, + color_removed = { fg = colors.red }, + condition = conditions.hide_in_width, + }, + python_env = { + function() + local utils = require "core.lualine.utils" + if vim.bo.filetype == "python" then + local venv = os.getenv "CONDA_DEFAULT_ENV" + if venv then + return string.format("  (%s)", utils.env_cleanup(venv)) + end + venv = os.getenv "VIRTUAL_ENV" + if venv then + return string.format("  (%s)", utils.env_cleanup(venv)) + end + return "" + end + return "" + end, + color = { fg = colors.green }, + condition = conditions.hide_in_width, + }, + diagnostics = { + "diagnostics", + sources = { "nvim_lsp" }, + symbols = { error = " ", warn = " ", info = " ", hint = " " }, + condition = conditions.hide_in_width, + }, + treesitter = { + function() + if next(vim.treesitter.highlighter.active) then + return "  " + end + return "" + end, + color = { fg = colors.green }, + condition = conditions.hide_in_width, + }, + lsp = { + function(msg) + msg = msg or "LSP Inactive" + local buf_clients = vim.lsp.buf_get_clients() + if next(buf_clients) == nil then + return msg + end + local buf_ft = vim.bo.filetype + local buf_client_names = {} + + -- add client + local utils = require "lsp.utils" + local active_client = utils.get_active_client_by_ft(buf_ft) + for _, client in pairs(buf_clients) do + if client.name ~= "null-ls" then + table.insert(buf_client_names, client.name) + end + end + vim.list_extend(buf_client_names, active_client or {}) + + -- add formatter + local formatters = require "lsp.null-ls.formatters" + local supported_formatters = formatters.list_supported_names(buf_ft) + vim.list_extend(buf_client_names, supported_formatters) + + -- add linter + local linters = require "lsp.null-ls.linters" + local supported_linters = linters.list_supported_names(buf_ft) + vim.list_extend(buf_client_names, supported_linters) + + return table.concat(buf_client_names, ", ") + end, + condition = conditions.hide_in_width, + icon = " ", + color = { gui = "bold" }, + }, + location = { "location", condition = conditions.hide_in_width }, + progress = { "progress", condition = conditions.hide_in_width }, + spaces = { + function() + local label = "Spaces: " + if not vim.api.nvim_buf_get_option(0, "expandtab") then + label = "Tab size: " + end + return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " + end, + condition = conditions.hide_in_width, + }, + encoding = { + "o:encoding", + upper = true, + condition = conditions.hide_in_width, + }, + filetype = { "filetype", condition = conditions.hide_in_width }, + scrollbar = { + function() + local current_line = vim.fn.line "." + local total_lines = vim.fn.line "$" + local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" } + local line_ratio = current_line / total_lines + local index = math.ceil(line_ratio * #chars) + return chars[index] + end, + color = { fg = colors.yellow, bg = colors.bg }, + left_padding = 0, + right_padding = 0, + }, +} diff --git a/lua/core/lualine/conditions.lua b/lua/core/lualine/conditions.lua new file mode 100644 index 00000000..2d2d81ef --- /dev/null +++ b/lua/core/lualine/conditions.lua @@ -0,0 +1,17 @@ +local window_width_limit = 80 + +local conditions = { + buffer_not_empty = function() + return vim.fn.empty(vim.fn.expand "%:t") ~= 1 + end, + hide_in_width = function() + return vim.fn.winwidth(0) > window_width_limit + end, + check_git_workspace = function() + local filepath = vim.fn.expand "%:p:h" + local gitdir = vim.fn.finddir(".git", filepath .. ";") + return gitdir and #gitdir > 0 and #gitdir < #filepath + end, +} + +return conditions diff --git a/lua/core/lualine/init.lua b/lua/core/lualine/init.lua new file mode 100644 index 00000000..5b3ce2a1 --- /dev/null +++ b/lua/core/lualine/init.lua @@ -0,0 +1,47 @@ +local M = {} +M.config = function() + lvim.builtin.lualine = { + active = true, + style = "lvim", + options = { + icons_enabled = nil, + component_separators = nil, + section_separators = nil, + theme = nil, + disabled_filetypes = nil, + }, + sections = { + lualine_a = nil, + lualine_b = nil, + lualine_c = nil, + lualine_x = nil, + lualine_y = nil, + lualine_z = nil, + }, + inactive_sections = { + lualine_a = nil, + lualine_b = nil, + lualine_c = nil, + lualine_x = nil, + lualine_y = nil, + lualine_z = nil, + }, + tabline = nil, + extensions = nil, + on_config_done = nil, + } +end + +M.setup = function() + require("core.lualine.styles").update() + require("core.lualine.utils").validate_theme() + + local lualine = require "lualine" + lualine.setup(lvim.builtin.lualine) + + if lvim.builtin.lualine.on_config_done then + lvim.builtin.lualine.on_config_done(lualine, lvim.builtin.lualine) + end +end + +return M diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua new file mode 100644 index 00000000..e35f66fe --- /dev/null +++ b/lua/core/lualine/styles.lua @@ -0,0 +1,170 @@ +local M = {} +local components = require "core.lualine.components" + +local styles = { + lvim = nil, + default = nil, + none = nil, +} + +styles.none = { + style = "none", + options = { + icons_enabled = true, + component_separators = "", + section_separators = "", + disabled_filetypes = {}, + }, + sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = {}, +} + +styles.default = { + style = "default", + options = { + icons_enabled = true, + component_separators = { "", "" }, + section_separators = { "", "" }, + disabled_filetypes = {}, + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch" }, + lualine_c = { "filename" }, + lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = {}, +} + +styles.lvim = { + style = "lvim", + options = { + icons_enabled = true, + component_separators = "", + section_separators = "", + disabled_filetypes = { "dashboard", "" }, + }, + sections = { + lualine_a = { + components.vi_mode, + }, + lualine_b = { + components.branch, + }, + lualine_c = { + components.diff, + components.python_env, + }, + lualine_x = { + components.diagnostics, + components.treesitter, + components.lsp, + -- components.location, + -- components.progress, + -- components.spaces, + -- components.encoding, + components.filetype, + }, + lualine_y = { + -- components.filetype, + }, + lualine_z = { + components.scrollbar, + }, + }, + inactive_sections = { + lualine_a = { + "filename", + }, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = { "nvim-tree" }, +} + +function M.get_style(style) + local style_keys = vim.tbl_keys(styles) + if not vim.tbl_contains(style_keys, style) then + local Log = require "core.log" + local logger = Log:get_default() + logger.error( + "Invalid lualine style", + string.format('"%s"', style), + "options are: ", + string.format('"%s"', table.concat(style_keys, '", "')) + ) + logger.info '"lvim" style is applied.' + style = "lvim" + end + + return vim.deepcopy(styles[style]) +end + +function M.update() + local config = lvim.builtin.lualine + local style = M.get_style(config.style) + + lvim.builtin.lualine = { + active = true, + style = style.style, + options = { + icons_enabled = config.options.icons_enabled or style.options.icons_enabled, + component_separators = config.options.component_separators or style.options.component_separators, + section_separators = config.options.section_separators or style.options.section_separators, + theme = config.options.theme or lvim.colorscheme or "auto", + disabled_filetypes = config.options.disabled_filetypes or style.options.disabled_filetypes, + }, + sections = { + lualine_a = config.sections.lualine_a or style.sections.lualine_a, + lualine_b = config.sections.lualine_b or style.sections.lualine_b, + lualine_c = config.sections.lualine_c or style.sections.lualine_c, + lualine_x = config.sections.lualine_x or style.sections.lualine_x, + lualine_y = config.sections.lualine_y or style.sections.lualine_y, + lualine_z = config.sections.lualine_z or style.sections.lualine_z, + }, + inactive_sections = { + lualine_a = config.inactive_sections.lualine_a or style.inactive_sections.lualine_a, + lualine_b = config.inactive_sections.lualine_b or style.inactive_sections.lualine_b, + lualine_c = config.inactive_sections.lualine_c or style.inactive_sections.lualine_c, + lualine_x = config.inactive_sections.lualine_x or style.inactive_sections.lualine_x, + lualine_y = config.inactive_sections.lualine_y or style.inactive_sections.lualine_y, + lualine_z = config.inactive_sections.lualine_z or style.inactive_sections.lualine_z, + }, + tabline = config.tabline or style.tabline, + extensions = config.extensions or style.extensions, + on_config_done = config.on_config_done, + } +end + +return M diff --git a/lua/core/lualine/utils.lua b/lua/core/lualine/utils.lua new file mode 100644 index 00000000..f2f29592 --- /dev/null +++ b/lua/core/lualine/utils.lua @@ -0,0 +1,24 @@ +local M = {} + +function M.validate_theme() + local theme = lvim.builtin.lualine.options.theme + + local lualine_loader = require "lualine.utils.loader" + local ok = pcall(lualine_loader.load_theme, theme) + if not ok then + lvim.builtin.lualine.options.theme = "auto" + end +end + +function M.env_cleanup(venv) + if string.find(venv, "/") then + local final_venv = venv + for w in venv:gmatch "([^/]+)" do + final_venv = w + end + venv = final_venv + end + return venv +end + +return M diff --git a/lua/core/status_colors.lua b/lua/core/status_colors.lua deleted file mode 100644 index d6317309..00000000 --- a/lua/core/status_colors.lua +++ /dev/null @@ -1,20 +0,0 @@ -lvim.builtin.galaxyline = { - active = true, - show_mode = false, - colors = { - alt_bg = "#2E2E2E", - grey = "#858585", - blue = "#569CD6", - green = "#608B4E", - yellow = "#DCDCAA", - orange = "#FF8800", - purple = "#C586C0", - magenta = "#D16D9E", - cyan = "#4EC9B0", - red = "#D16969", - error_red = "#F44747", - warning_orange = "#FF8800", - info_yellow = "#FFCC66", - hint_blue = "#9CDCFE", - }, -} -- cgit v1.2.3 From 7845b671ecb8634684f2d38158938bfe65fc5b31 Mon Sep 17 00:00:00 2001 From: Ahmed Khalf Date: Fri, 20 Aug 2021 23:22:35 +0400 Subject: Add show_hidden option to project module (#1359) --- lua/core/project.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lua/core') diff --git a/lua/core/project.lua b/lua/core/project.lua index 650f2924..6d7aa56e 100644 --- a/lua/core/project.lua +++ b/lua/core/project.lua @@ -20,6 +20,9 @@ function M.config() -- detection_methods patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" }, + -- Show hidden files in telescope + show_hidden = false, + -- When set to false, you will get a message when project.nvim changes your -- directory. silent_chdir = true, -- cgit v1.2.3 From c5c9ae0fb68567c2a207c8c486b03bbafc650f98 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 22 Aug 2021 08:35:50 +0200 Subject: [fix]: don't overwrite user's dashboard config (#1366) --- lua/core/dashboard.lua | 5 ++++- lua/core/project.lua | 49 +++++++++++++++++++++---------------------------- 2 files changed, 25 insertions(+), 29 deletions(-) (limited to 'lua/core') diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index f98721cc..63ae7294 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -31,7 +31,10 @@ M.config = function() description = { " Find File " }, command = "Telescope find_files", }, - -- b is reserved for the core.project module + b = { + description = { " Recent Projects " }, + command = "Telescope projects", + }, c = { description = { " Recently Used Files" }, command = "Telescope oldfiles", diff --git a/lua/core/project.lua b/lua/core/project.lua index 6d7aa56e..7be65a11 100644 --- a/lua/core/project.lua +++ b/lua/core/project.lua @@ -2,50 +2,43 @@ local M = {} -- function M.config() lvim.builtin.project = { - --- This is on by default since it's currently the expected behavior. ---@usage set to false to disable project.nvim. + --- This is on by default since it's currently the expected behavior. active = true, - -- Manual mode doesn't automatically change your root directory, so you have - -- the option to manually do so using `:ProjectRoot` command. + ---@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. manual_mode = false, - -- Methods of detecting the root directory. **"lsp"** uses the native neovim - -- lsp, while **"pattern"** uses vim-rooter like glob pattern matching. Here - -- order matters: if one is not detected, the other is used as fallback. You - -- can also delete or rearangne the detection methods. + ---@usage Methods of detecting the root directory + --- Allowed values: **"lsp"** uses the native neovim lsp + --- **"pattern"** uses vim-rooter like glob pattern matching. Here + --- order matters: if one is not detected, the other is used as fallback. You + --- can also delete or rearangne the detection methods. detection_methods = { "lsp", "pattern" }, - -- All the patterns used to detect root dir, when **"pattern"** is in - -- detection_methods + ---@usage patterns used to detect root dir, when **"pattern"** is in detection_methods patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" }, - -- Show hidden files in telescope + ---@ Show hidden files in telescope when searching for files in a project show_hidden = false, - -- When set to false, you will get a message when project.nvim changes your - -- directory. + ---@usage When set to false, you will get a message when project.nvim changes your directory. + -- When set to false, you will get a message when project.nvim changes your directory. silent_chdir = true, + + ---@usage list of lsp client names to ignore when using **lsp** detection. eg: { "efm", ... } + ignore_lsp = {}, + + ---@type string + ---@usage path to store the project history for use in telescope + datapath = CACHE_PATH, } end -- function M.setup() - local settings = lvim.builtin.project - - -- Table of lsp clients to ignore by name - -- eg: { "efm", ... } - settings["ignore_lsp"] = {} - - -- Path where project.nvim will store the project history for use in - -- telescope - settings["datapath"] = CACHE_PATH - - require("project_nvim").setup(settings) - - lvim.builtin.dashboard.custom_section["b"] = { - description = { " Recent Projects " }, - command = "Telescope projects", - } + require("project_nvim").setup(lvim.builtin.project) end -- return M -- cgit v1.2.3 From d85584d09f9028fa4202cea473f7f0ae3c531aef Mon Sep 17 00:00:00 2001 From: devtoi <508254+devtoi@users.noreply.github.com> Date: Sun, 22 Aug 2021 20:03:19 +0200 Subject: [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 Co-authored-by: rebuilt Co-authored-by: Luc Sinet Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com> --- lua/core/autopairs.lua | 17 +++++++++++------ lua/core/bufferline.lua | 5 +++++ lua/core/comment.lua | 8 +++++++- lua/core/compe.lua | 6 ++++++ lua/core/dap.lua | 6 ++++++ lua/core/dashboard.lua | 6 ++++++ lua/core/gitsigns.lua | 9 ++++++++- lua/core/lspinstall.lua | 19 +++++++++++++++++++ lua/core/nvimtree.lua | 13 +++++++++---- lua/core/project.lua | 15 +++++++++++---- lua/core/telescope.lua | 28 +++++++++++++++++----------- lua/core/terminal.lua | 5 +++++ lua/core/treesitter.lua | 6 ++++++ lua/core/which-key.lua | 6 ++++++ 14 files changed, 122 insertions(+), 27 deletions(-) create mode 100644 lua/core/lspinstall.lua (limited to 'lua/core') 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 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 "") + return vim.fn["compe#confirm"](autopairs.esc "") else - return npairs.esc "" + return autopairs.esc "" 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 = { [""] = ":BufferNext", @@ -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", "", "v:lua.tab_complete()", { expr = true }) vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", { expr = true }) vim.api.nvim_set_keymap("s", "", "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 = { "lua require'dap'.continue()", "Start" }, q = { "lua require'dap'.close()", "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 q :q" }, }, } + + 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 "") 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 = [[]], @@ -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 -- cgit v1.2.3 From 378c1c3eb5f32da7057371fedda405250ccb67c8 Mon Sep 17 00:00:00 2001 From: chaeing Date: Mon, 23 Aug 2021 23:49:18 -0700 Subject: [Feature] enhance lualine config (#1372) --- lua/core/lualine/components.lua | 36 +++++++++++++++++++++-------- lua/core/lualine/init.lua | 2 +- lua/core/lualine/styles.lua | 50 ++++++++--------------------------------- lua/core/lualine/utils.lua | 3 +++ 4 files changed, 40 insertions(+), 51 deletions(-) (limited to 'lua/core') diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua index b9211a79..042f6b6d 100644 --- a/lua/core/lualine/components.lua +++ b/lua/core/lualine/components.lua @@ -2,13 +2,16 @@ local conditions = require "core.lualine.conditions" local colors = require "core.lualine.colors" return { - vi_mode = { + mode = { function() return " " end, left_padding = 0, right_padding = 0, - condition = conditions.hide_in_width, + condition = function() + return true + end, + color = {}, }, branch = { "branch", @@ -16,6 +19,14 @@ return { condition = function() return conditions.hide_in_width() and conditions.check_git_workspace() end, + color = { gui = "bold" }, + }, + filename = { + "filename", + condition = function() + return true + end, + color = {}, }, diff = { "diff", @@ -24,6 +35,7 @@ return { color_modified = { fg = colors.yellow }, color_removed = { fg = colors.red }, condition = conditions.hide_in_width, + color = {}, }, python_env = { function() @@ -41,14 +53,15 @@ return { end return "" end, - color = { fg = colors.green }, condition = conditions.hide_in_width, + color = { fg = colors.green }, }, diagnostics = { "diagnostics", sources = { "nvim_lsp" }, symbols = { error = " ", warn = " ", info = " ", hint = " " }, condition = conditions.hide_in_width, + color = {}, }, treesitter = { function() @@ -57,8 +70,8 @@ return { end return "" end, - color = { fg = colors.green }, condition = conditions.hide_in_width, + color = { fg = colors.green }, }, lsp = { function(msg) @@ -92,12 +105,12 @@ return { return table.concat(buf_client_names, ", ") end, - condition = conditions.hide_in_width, icon = " ", + condition = conditions.hide_in_width, color = { gui = "bold" }, }, - location = { "location", condition = conditions.hide_in_width }, - progress = { "progress", condition = conditions.hide_in_width }, + location = { "location", condition = conditions.hide_in_width, color = {} }, + progress = { "progress", condition = conditions.hide_in_width, color = {} }, spaces = { function() local label = "Spaces: " @@ -107,13 +120,15 @@ return { return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " end, condition = conditions.hide_in_width, + color = {}, }, encoding = { "o:encoding", upper = true, condition = conditions.hide_in_width, + color = {}, }, - filetype = { "filetype", condition = conditions.hide_in_width }, + filetype = { "filetype", condition = conditions.hide_in_width, color = {} }, scrollbar = { function() local current_line = vim.fn.line "." @@ -123,8 +138,11 @@ return { local index = math.ceil(line_ratio * #chars) return chars[index] end, - color = { fg = colors.yellow, bg = colors.bg }, left_padding = 0, right_padding = 0, + condition = function() + return true + end, + color = { fg = colors.yellow, bg = colors.bg }, }, } diff --git a/lua/core/lualine/init.lua b/lua/core/lualine/init.lua index 5b3ce2a1..aa6fe098 100644 --- a/lua/core/lualine/init.lua +++ b/lua/core/lualine/init.lua @@ -40,7 +40,7 @@ M.setup = function() lualine.setup(lvim.builtin.lualine) if lvim.builtin.lualine.on_config_done then - lvim.builtin.lualine.on_config_done(lualine, lvim.builtin.lualine) + lvim.builtin.lualine.on_config_done(lualine) end end diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua index e35f66fe..876d7fa3 100644 --- a/lua/core/lualine/styles.lua +++ b/lua/core/lualine/styles.lua @@ -69,14 +69,15 @@ styles.lvim = { icons_enabled = true, component_separators = "", section_separators = "", - disabled_filetypes = { "dashboard", "" }, + disabled_filetypes = { "dashboard" }, }, sections = { lualine_a = { - components.vi_mode, + components.mode, }, lualine_b = { components.branch, + components.filename, }, lualine_c = { components.diff, @@ -86,15 +87,9 @@ styles.lvim = { components.diagnostics, components.treesitter, components.lsp, - -- components.location, - -- components.progress, - -- components.spaces, - -- components.encoding, components.filetype, }, - lualine_y = { - -- components.filetype, - }, + lualine_y = {}, lualine_z = { components.scrollbar, }, @@ -132,39 +127,12 @@ function M.get_style(style) end function M.update() - local config = lvim.builtin.lualine - local style = M.get_style(config.style) + local style = M.get_style(lvim.builtin.lualine.style) + if lvim.builtin.lualine.options.theme == nil then + lvim.builtin.lualine.options.theme = lvim.colorscheme + end - lvim.builtin.lualine = { - active = true, - style = style.style, - options = { - icons_enabled = config.options.icons_enabled or style.options.icons_enabled, - component_separators = config.options.component_separators or style.options.component_separators, - section_separators = config.options.section_separators or style.options.section_separators, - theme = config.options.theme or lvim.colorscheme or "auto", - disabled_filetypes = config.options.disabled_filetypes or style.options.disabled_filetypes, - }, - sections = { - lualine_a = config.sections.lualine_a or style.sections.lualine_a, - lualine_b = config.sections.lualine_b or style.sections.lualine_b, - lualine_c = config.sections.lualine_c or style.sections.lualine_c, - lualine_x = config.sections.lualine_x or style.sections.lualine_x, - lualine_y = config.sections.lualine_y or style.sections.lualine_y, - lualine_z = config.sections.lualine_z or style.sections.lualine_z, - }, - inactive_sections = { - lualine_a = config.inactive_sections.lualine_a or style.inactive_sections.lualine_a, - lualine_b = config.inactive_sections.lualine_b or style.inactive_sections.lualine_b, - lualine_c = config.inactive_sections.lualine_c or style.inactive_sections.lualine_c, - lualine_x = config.inactive_sections.lualine_x or style.inactive_sections.lualine_x, - lualine_y = config.inactive_sections.lualine_y or style.inactive_sections.lualine_y, - lualine_z = config.inactive_sections.lualine_z or style.inactive_sections.lualine_z, - }, - tabline = config.tabline or style.tabline, - extensions = config.extensions or style.extensions, - on_config_done = config.on_config_done, - } + lvim.builtin.lualine = vim.tbl_deep_extend("keep", lvim.builtin.lualine, style) end return M diff --git a/lua/core/lualine/utils.lua b/lua/core/lualine/utils.lua index f2f29592..cf80a99e 100644 --- a/lua/core/lualine/utils.lua +++ b/lua/core/lualine/utils.lua @@ -2,6 +2,9 @@ local M = {} function M.validate_theme() local theme = lvim.builtin.lualine.options.theme + if type(theme) == "table" then + return + end local lualine_loader = require "lualine.utils.loader" local ok = pcall(lualine_loader.load_theme, theme) -- cgit v1.2.3 From 00b895d9e9577f084cf577a07f9d6d6e1f7a4cac Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Wed, 25 Aug 2021 07:47:48 +0200 Subject: [Feature] Encapsulate config logic (#1338) * Define core/builtins, streamline status_color interface * Encapsulate configuration in its own module * Add fallback to lv-config.lua * Rectify settings loading order to allow overriding vim options * Move default-config into config/ module * replace uv.fs_stat with utils.is_file --- lua/core/autocmds.lua | 3 ++- lua/core/builtins/init.lua | 29 +++++++++++++++++++++++++++++ lua/core/dashboard.lua | 4 ++-- lua/core/info.lua | 6 ++++-- 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 lua/core/builtins/init.lua (limited to 'lua/core') diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua index 91278544..91ec70b5 100644 --- a/lua/core/autocmds.lua +++ b/lua/core/autocmds.lua @@ -1,4 +1,5 @@ local autocommands = {} +local config = require "config" lvim.autocommands = { _general_settings = { @@ -32,7 +33,7 @@ lvim.autocommands = { "*", "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", }, - { "BufWritePost", USER_CONFIG_PATH, "lua require('utils').reload_lv_config()" }, + { "BufWritePost", config.path, "lua require('utils').reload_lv_config()" }, { "FileType", "qf", diff --git a/lua/core/builtins/init.lua b/lua/core/builtins/init.lua new file mode 100644 index 00000000..32f96af5 --- /dev/null +++ b/lua/core/builtins/init.lua @@ -0,0 +1,29 @@ +local M = {} + +local builtins = { + "keymappings", + "core.which-key", + "core.gitsigns", + "core.compe", + "core.dashboard", + "core.dap", + "core.terminal", + "core.telescope", + "core.treesitter", + "core.nvimtree", + "core.project", + "core.bufferline", + "core.autopairs", + "core.comment", + "core.lspinstall", + "core.lualine", +} + +function M.config(config) + for _, builtin_path in ipairs(builtins) do + local builtin = require(builtin_path) + builtin.config(config) + end +end + +return M diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index c76d55c9..ac6ee013 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -1,6 +1,6 @@ local M = {} -M.config = function() +M.config = function(config) lvim.builtin.dashboard = { active = false, on_config_done = nil, @@ -47,7 +47,7 @@ M.config = function() }, e = { description = { " Configuration " }, - command = ":e " .. USER_CONFIG_PATH, + command = ":e " .. config.path, }, }, diff --git a/lua/core/info.lua b/lua/core/info.lua index d9b348b5..67e45d1c 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -16,6 +16,7 @@ local function str_list(list) end local function get_formatter_suggestion_msg(ft) + local config = require "config" local null_formatters = require "lsp.null-ls.formatters" local supported_formatters = null_formatters.list_available(ft) local section = { @@ -27,7 +28,7 @@ local function get_formatter_suggestion_msg(ft) if not vim.tbl_isempty(supported_formatters) then vim.list_extend(section, { "* Configured formatter needs to be installed and executable.", - fmt("* Enable installed formatter(s) with following config in %s", USER_CONFIG_PATH), + fmt("* Enable installed formatter(s) with following config in %s", config.path), "", fmt(" lvim.lang.%s.formatters = { { exe = '%s' } }", ft, table.concat(supported_formatters, "│")), }) @@ -37,6 +38,7 @@ local function get_formatter_suggestion_msg(ft) end local function get_linter_suggestion_msg(ft) + local config = require "config" local null_linters = require "lsp.null-ls.linters" local supported_linters = null_linters.list_available(ft) local section = { @@ -48,7 +50,7 @@ local function get_linter_suggestion_msg(ft) if not vim.tbl_isempty(supported_linters) then vim.list_extend(section, { "* Configured linter needs to be installed and executable.", - fmt("* Enable installed linter(s) with following config in %s", USER_CONFIG_PATH), + fmt("* Enable installed linter(s) with following config in %s", config.path), "", fmt(" lvim.lang.%s.linters = { { exe = '%s' } }", ft, table.concat(supported_linters, "│")), }) -- cgit v1.2.3 From 291c8bb5bd894b4da7c9e684915348a094a13aae Mon Sep 17 00:00:00 2001 From: chaeing Date: Thu, 26 Aug 2021 00:20:04 -0700 Subject: [Refactor] Lualine component conditions (#1394) --- lua/core/lualine/components.lua | 42 ++++++++++++++++++++++------------------- lua/core/lualine/conditions.lua | 10 +++++----- 2 files changed, 28 insertions(+), 24 deletions(-) (limited to 'lua/core') diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua index 042f6b6d..894d9e9b 100644 --- a/lua/core/lualine/components.lua +++ b/lua/core/lualine/components.lua @@ -1,6 +1,17 @@ local conditions = require "core.lualine.conditions" local colors = require "core.lualine.colors" +local function diff_source() + local gitsigns = vim.b.gitsigns_status_dict + if gitsigns then + return { + added = gitsigns.added, + modified = gitsigns.changed, + removed = gitsigns.removed, + } + end +end + return { mode = { function() @@ -8,34 +19,29 @@ return { end, left_padding = 0, right_padding = 0, - condition = function() - return true - end, color = {}, + condition = nil, }, branch = { - "branch", + "b:gitsigns_head", icon = " ", - condition = function() - return conditions.hide_in_width() and conditions.check_git_workspace() - end, color = { gui = "bold" }, + condition = conditions.hide_in_width, }, filename = { "filename", - condition = function() - return true - end, color = {}, + condition = nil, }, diff = { "diff", + source = diff_source, symbols = { added = "  ", modified = "柳", removed = " " }, color_added = { fg = colors.green }, color_modified = { fg = colors.yellow }, color_removed = { fg = colors.red }, - condition = conditions.hide_in_width, color = {}, + condition = nil, }, python_env = { function() @@ -53,15 +59,15 @@ return { end return "" end, - condition = conditions.hide_in_width, color = { fg = colors.green }, + condition = conditions.hide_in_width, }, diagnostics = { "diagnostics", sources = { "nvim_lsp" }, symbols = { error = " ", warn = " ", info = " ", hint = " " }, - condition = conditions.hide_in_width, color = {}, + condition = conditions.hide_in_width, }, treesitter = { function() @@ -70,8 +76,8 @@ return { end return "" end, - condition = conditions.hide_in_width, color = { fg = colors.green }, + condition = conditions.hide_in_width, }, lsp = { function(msg) @@ -106,8 +112,8 @@ return { return table.concat(buf_client_names, ", ") end, icon = " ", - condition = conditions.hide_in_width, color = { gui = "bold" }, + condition = conditions.hide_in_width, }, location = { "location", condition = conditions.hide_in_width, color = {} }, progress = { "progress", condition = conditions.hide_in_width, color = {} }, @@ -125,8 +131,8 @@ return { encoding = { "o:encoding", upper = true, - condition = conditions.hide_in_width, color = {}, + condition = conditions.hide_in_width, }, filetype = { "filetype", condition = conditions.hide_in_width, color = {} }, scrollbar = { @@ -140,9 +146,7 @@ return { end, left_padding = 0, right_padding = 0, - condition = function() - return true - end, color = { fg = colors.yellow, bg = colors.bg }, + condition = nil, }, } diff --git a/lua/core/lualine/conditions.lua b/lua/core/lualine/conditions.lua index 2d2d81ef..3ee4fbb8 100644 --- a/lua/core/lualine/conditions.lua +++ b/lua/core/lualine/conditions.lua @@ -7,11 +7,11 @@ local conditions = { hide_in_width = function() return vim.fn.winwidth(0) > window_width_limit end, - check_git_workspace = function() - local filepath = vim.fn.expand "%:p:h" - local gitdir = vim.fn.finddir(".git", filepath .. ";") - return gitdir and #gitdir > 0 and #gitdir < #filepath - end, + -- check_git_workspace = function() + -- local filepath = vim.fn.expand "%:p:h" + -- local gitdir = vim.fn.finddir(".git", filepath .. ";") + -- return gitdir and #gitdir > 0 and #gitdir < #filepath + -- end, } return conditions -- cgit v1.2.3 From 5b94e3cee2c4405e98c9c0e8769670723a1f4bae Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 26 Aug 2021 12:49:29 +0200 Subject: fix logging when plenary is not available (#1390) --- lua/core/log.lua | 43 +++++++++++++++++++++++++++++++++++++------ lua/core/lualine/styles.lua | 5 ++--- lua/core/nvimtree.lua | 2 +- lua/core/terminal.lua | 4 ++-- 4 files changed, 42 insertions(+), 12 deletions(-) (limited to 'lua/core') diff --git a/lua/core/log.lua b/lua/core/log.lua index 5dd5622e..54620625 100644 --- a/lua/core/log.lua +++ b/lua/core/log.lua @@ -4,26 +4,57 @@ local Log = {} ---@param opts these are passed verbatim to Plenary.log ---@return log handle function Log:new(opts) - local status_ok, _ = pcall(require, "plenary.log") + local status_ok, handle = pcall(require, "plenary.log") if not status_ok then - return nil + vim.notify("Plenary.log is not available. Logging to console only", vim.log.levels.DEBUG) end - local obj = require("plenary.log").new(opts) + self.__handle = handle + local path = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), opts.plugin) - obj.get_path = function() + self.get_path = function() return path end - return obj + setmetatable({}, Log) + return self +end + +function Log:add_entry(msg, level) + local status_ok, _ = pcall(require, "plenary.log") + if not status_ok then + return vim.notify(msg, vim.log.levels[level]) + end + -- plenary uses lower-case log levels + return self.__handle[level:lower()](msg) end --- Creates or retrieves a log handle for the default logfile --- based on Plenary.log ---@return log handle -function Log:get_default() +function Log:new_default() return Log:new { plugin = "lunarvim", level = lvim.log.level } end +function Log:trace(msg) + self:add_entry(msg, "TRACE") +end + +function Log:debug(msg) + self:add_entry(msg, "DEBUG") +end + +function Log:info(msg) + self:add_entry(msg, "INFO") +end + +function Log:warn(msg) + self:add_entry(msg, "TRACE") +end + +function Log:error(msg) + self:add_entry(msg, "TRACE") +end + return Log diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua index 876d7fa3..53b0691e 100644 --- a/lua/core/lualine/styles.lua +++ b/lua/core/lualine/styles.lua @@ -112,14 +112,13 @@ function M.get_style(style) local style_keys = vim.tbl_keys(styles) if not vim.tbl_contains(style_keys, style) then local Log = require "core.log" - local logger = Log:get_default() - logger.error( + Log:error( "Invalid lualine style", string.format('"%s"', style), "options are: ", string.format('"%s"', table.concat(style_keys, '", "')) ) - logger.info '"lvim" style is applied.' + Log:info '"lvim" style is applied.' style = "lvim" end diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index bea1add4..b5a6cc8d 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -52,7 +52,7 @@ end 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" + Log:error "Failed to load nvim-tree.config" return end local g = vim.g diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index 4fced26e..f9be8734 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -82,7 +82,7 @@ M._exec_toggle = function(exec) local binary = M._split(exec)[1] if vim.fn.executable(binary) ~= 1 then local Log = require "core.log" - Log:get_default().error("Unable to run executable " .. binary .. ". Please make sure it is installed properly.") + Log:error("Unable to run executable " .. binary .. ". Please make sure it is installed properly.") return end local Terminal = require("toggleterm.terminal").Terminal @@ -122,7 +122,7 @@ M.toggle_log_view = function(name) local Terminal = require("toggleterm.terminal").Terminal local log_view = Terminal:new(term_opts) - -- require("core.log"):get_default().debug("term", vim.inspect(term_opts)) + -- require("core.log"):debug("term", vim.inspect(term_opts)) log_view:toggle() end -- cgit v1.2.3 From 27679f988fe187f9831ba7895c9c3a7ce2dd14f4 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 26 Aug 2021 20:32:16 +0200 Subject: [Refactor]: only allow a single logger (#1405) --- lua/core/log.lua | 65 ++++++++++++++++++++++----------------------- lua/core/lualine/styles.lua | 2 +- 2 files changed, 33 insertions(+), 34 deletions(-) (limited to 'lua/core') diff --git a/lua/core/log.lua b/lua/core/log.lua index 54620625..1eb786ba 100644 --- a/lua/core/log.lua +++ b/lua/core/log.lua @@ -1,60 +1,59 @@ local Log = {} ---- Creates a log handle based on Plenary.log ----@param opts these are passed verbatim to Plenary.log ----@return log handle -function Log:new(opts) - local status_ok, handle = pcall(require, "plenary.log") - if not status_ok then - vim.notify("Plenary.log is not available. Logging to console only", vim.log.levels.DEBUG) - end - - self.__handle = handle - - local path = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), opts.plugin) - - self.get_path = function() - return path - end - - setmetatable({}, Log) - return self -end - +--- Adds a log entry using Plenary.log +---@param msg any +---@param level string [same as vim.log.log_levels] function Log:add_entry(msg, level) - local status_ok, _ = pcall(require, "plenary.log") - if not status_ok then - return vim.notify(msg, vim.log.levels[level]) + assert(type(level) == "string") + if self.__handle then + -- plenary uses lower-case log levels + self.__handle[level:lower()](msg) + end + local status_ok, plenary = pcall(require, "plenary") + if status_ok then + local default_opts = { plugin = "lunarvim", level = lvim.log.level } + local handle = plenary.log.new(default_opts) + handle[level:lower()](msg) + self.__handle = handle end - -- plenary uses lower-case log levels - return self.__handle[level:lower()](msg) + -- don't do anything if plenary is not available end ---- Creates or retrieves a log handle for the default logfile ---- based on Plenary.log ----@return log handle -function Log:new_default() - return Log:new { plugin = "lunarvim", level = lvim.log.level } +---Retrieves the path of the logfile +---@return string path of the logfile +function Log:get_path() + return string.format("%s/%s.log", vim.fn.stdpath "cache", "lunarvim") end +---Add a log entry at TRACE level +---@param msg any function Log:trace(msg) self:add_entry(msg, "TRACE") end +---Add a log entry at DEBUG level +---@param msg any function Log:debug(msg) self:add_entry(msg, "DEBUG") end +---Add a log entry at INFO level +---@param msg any function Log:info(msg) self:add_entry(msg, "INFO") end +---Add a log entry at WARN level +---@param msg any function Log:warn(msg) - self:add_entry(msg, "TRACE") + self:add_entry(msg, "WARN") end +---Add a log entry at ERROR level +---@param msg any function Log:error(msg) - self:add_entry(msg, "TRACE") + self:add_entry(msg, "ERROR") end +setmetatable({}, Log) return Log diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua index 53b0691e..84e8123d 100644 --- a/lua/core/lualine/styles.lua +++ b/lua/core/lualine/styles.lua @@ -118,7 +118,7 @@ function M.get_style(style) "options are: ", string.format('"%s"', table.concat(style_keys, '", "')) ) - Log:info '"lvim" style is applied.' + Log:debug '"lvim" style is applied.' style = "lvim" end -- cgit v1.2.3 From 7aa079d74a11f53f90e3b30371f530e85eb63b93 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Thu, 26 Aug 2021 22:40:24 -0400 Subject: disable nvimtree and outline for lualine --- lua/core/lualine/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua/core') diff --git a/lua/core/lualine/init.lua b/lua/core/lualine/init.lua index aa6fe098..9bf4f831 100644 --- a/lua/core/lualine/init.lua +++ b/lua/core/lualine/init.lua @@ -8,7 +8,7 @@ M.config = function() component_separators = nil, section_separators = nil, theme = nil, - disabled_filetypes = nil, + disabled_filetypes = {'NvimTree', 'Outline'} }, sections = { lualine_a = nil, -- cgit v1.2.3 From a0fd11ea0875e663b396dcdbce446072bcc1005e Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Thu, 26 Aug 2021 22:54:15 -0400 Subject: use styles.lua rather instead of editing options directly --- lua/core/lualine/init.lua | 2 +- lua/core/lualine/styles.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lua/core') diff --git a/lua/core/lualine/init.lua b/lua/core/lualine/init.lua index 9bf4f831..30b6a6a6 100644 --- a/lua/core/lualine/init.lua +++ b/lua/core/lualine/init.lua @@ -8,7 +8,7 @@ M.config = function() component_separators = nil, section_separators = nil, theme = nil, - disabled_filetypes = {'NvimTree', 'Outline'} + disabled_filetypes = nil }, sections = { lualine_a = nil, diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua index 84e8123d..3595e5e3 100644 --- a/lua/core/lualine/styles.lua +++ b/lua/core/lualine/styles.lua @@ -69,7 +69,7 @@ styles.lvim = { icons_enabled = true, component_separators = "", section_separators = "", - disabled_filetypes = { "dashboard" }, + disabled_filetypes = { "dashboard", "NvimTree", "Outline" }, }, sections = { lualine_a = { -- cgit v1.2.3 From 33af0668baf2df2a27782e2db8c6dd72cdf914b4 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Fri, 27 Aug 2021 00:10:45 -0400 Subject: format --- lua/core/lualine/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua/core') diff --git a/lua/core/lualine/init.lua b/lua/core/lualine/init.lua index 30b6a6a6..aa6fe098 100644 --- a/lua/core/lualine/init.lua +++ b/lua/core/lualine/init.lua @@ -8,7 +8,7 @@ M.config = function() component_separators = nil, section_separators = nil, theme = nil, - disabled_filetypes = nil + disabled_filetypes = nil, }, sections = { lualine_a = nil, -- cgit v1.2.3 From df7c3cb8f0512042bd24c10e744718991ae6a9a2 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Fri, 27 Aug 2021 00:11:01 -0400 Subject: q to quit quickfix when focused --- lua/core/autocmds.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lua/core') diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua index 91ec70b5..041926e5 100644 --- a/lua/core/autocmds.lua +++ b/lua/core/autocmds.lua @@ -8,6 +8,11 @@ lvim.autocommands = { "*", "lua require('utils.ft').do_filetype(vim.fn.expand(\"\"))", }, + { + "FileType", + "qf", + "nnoremap q :q", + }, { "TextYankPost", "*", -- cgit v1.2.3 From 23952f14437be39056b1e89436e8aea76dfbb61d Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 27 Aug 2021 18:47:31 +0200 Subject: Fix missing "HOME" variable errors (#1415) Co-authored-by: MarcSchaetz --- lua/core/dashboard.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lua/core') diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index ac6ee013..a613921f 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -1,4 +1,5 @@ local M = {} +local home_dir = vim.loop.os_homedir() M.config = function(config) lvim.builtin.dashboard = { @@ -6,7 +7,7 @@ M.config = function(config) on_config_done = nil, search_handler = "telescope", disable_at_vim_enter = 0, - session_directory = os.getenv "HOME" .. "/.cache/lvim/sessions", + session_directory = home_dir .. "/.cache/lvim/sessions", custom_header = { "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣶⣾⠿⠿⠟⠛⠛⠛⠛⠿⠿⣿⣷⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", -- cgit v1.2.3 From 17e65a99fea6a61ae55f181432be3ce30d082283 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Sat, 28 Aug 2021 09:45:42 -0400 Subject: use netrw when opening directory --- lua/core/nvimtree.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lua/core') diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index b5a6cc8d..6aa5401d 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -15,7 +15,7 @@ function M.config() tree_width = 30, }, ignore = { ".git", "node_modules", ".cache" }, - auto_open = 1, + auto_open = 0, auto_close = 1, quit_on_open = 0, follow = 1, @@ -65,6 +65,9 @@ function M.setup() if lvim.builtin.project.active then vim.g.nvim_tree_update_cwd = 1 vim.g.nvim_tree_respect_buf_cwd = 1 + vim.g.nvim_tree_disable_netrw = 0 + vim.g.nvim_tree_hijack_netrw = 0 + vim.g.netrw_banner = 0 end local tree_cb = nvim_tree_config.nvim_tree_callback -- cgit v1.2.3