From 3330d1cc06f79625c01f6eb4b3d01ec9a42985d6 Mon Sep 17 00:00:00 2001 From: siduck Date: Wed, 17 Nov 2021 11:00:57 +0530 Subject: [PATCH] clean up! --- lua/colors/highlights.lua | 10 +++--- lua/colors/init.lua | 4 +-- lua/core/mappings.lua | 3 -- lua/core/utils.lua | 20 +++++------ lua/plugins/configs/bufferline.lua | 9 +++-- lua/plugins/configs/cmp.lua | 9 ++--- lua/plugins/configs/gitsigns.lua | 34 ------------------ lua/plugins/configs/lspkind_icons.lua | 6 ++-- lua/plugins/configs/nvimtree.lua | 8 ++--- lua/plugins/configs/others.lua | 51 ++++++++++++++++----------- lua/plugins/configs/statusline.lua | 11 +++--- lua/plugins/configs/telescope.lua | 1 + lua/plugins/configs/treesitter.lua | 1 + lua/plugins/init.lua | 2 +- 14 files changed, 68 insertions(+), 101 deletions(-) delete mode 100644 lua/plugins/configs/gitsigns.lua diff --git a/lua/colors/highlights.lua b/lua/colors/highlights.lua index 895a929..d460a64 100644 --- a/lua/colors/highlights.lua +++ b/lua/colors/highlights.lua @@ -82,9 +82,11 @@ fg("DashboardHeader", grey_fg) fg("DashboardShortcut", grey_fg) -- Git signs -fg_bg("DiffAdd", nord_blue, "none") -fg_bg("DiffChange", grey_fg, "none") -fg_bg("DiffModified", nord_blue, "none") +fg_bg("DiffAdd", blue, "NONE") +fg_bg("DiffChange", grey_fg, "NONE") +fg_bg("DiffChangeDelete", red, "NONE") +fg_bg("DiffModified", red, "NONE") +fg_bg("DiffDelete", red, "NONE") -- Indent blankline plugin fg("IndentBlanklineChar", line) @@ -137,7 +139,7 @@ if ui.transparency then bg("NvimTreeStatusLineNC", "NONE") bg("NvimTreeVertSplit", "NONE") fg("NvimTreeVertSplit", grey) - end +end if #override ~= 0 then require(override) diff --git a/lua/colors/init.lua b/lua/colors/init.lua index 3b23c86..1de4a62 100644 --- a/lua/colors/init.lua +++ b/lua/colors/init.lua @@ -19,9 +19,7 @@ M.init = function(theme) package.loaded["colors.highlights" or false] = nil -- then load the highlights require "colors.highlights" - else - return false - end + end end -- returns a table of colors for givem or current theme diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 3e0162b..e192ea5 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -108,9 +108,6 @@ M.misc = function() -- add NvChadUpdate command and mapping cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()" map("n", maps.misc.update_nvchad, ":NvChadUpdate ") - - -- add ChadReload command and maping - -- cmd "silent! command! NvChadReload lua require('nvchad').reload_config()" end non_config_mappings() diff --git a/lua/core/utils.lua b/lua/core/utils.lua index ee1002e..41c70e1 100644 --- a/lua/core/utils.lua +++ b/lua/core/utils.lua @@ -132,25 +132,25 @@ M.hide_statusline = function() if vim.tbl_contains(hidden, buftype) then api.nvim_set_option("laststatus", 0) return - else - api.nvim_set_option("laststatus", 2) end + + api.nvim_set_option("laststatus", 2) end -M.load_config = function(reload) +M.load_config = function() local conf = require "core.default_config" local chadrcExists, _ = pcall(require, "custom.chadrc") --- if chadrc exists , then merge its table into the default config's + -- if chadrc exists , then merge its table into the default config's -if chadrcExists then - local change = require "custom.chadrc" - conf = vim.tbl_deep_extend("force", conf, change) - return conf -end + if chadrcExists then + local change = require "custom.chadrc" + conf = vim.tbl_deep_extend("force", conf, change) + return conf + end --- or load default config + -- or load default config return conf end diff --git a/lua/plugins/configs/bufferline.lua b/lua/plugins/configs/bufferline.lua index cda1a7a..a396ed4 100644 --- a/lua/plugins/configs/bufferline.lua +++ b/lua/plugins/configs/bufferline.lua @@ -10,7 +10,6 @@ bufferline.setup { offsets = { { filetype = "NvimTree", text = "", padding = 1 } }, buffer_close_icon = "", modified_icon = "", - -- close_icon = "%@NvChad_bufferline_quitvim@%X", close_icon = "", show_close_icon = true, left_trunc_marker = "", @@ -24,7 +23,7 @@ bufferline.setup { show_buffer_close_icons = true, separator_style = "thin", always_show_bufferline = true, - diagnostics = false, -- "or nvim_lsp" + diagnostics = false, custom_filter = function(buf_number) -- Func to filter out our managed/persistent split terms local present_type, type = pcall(function() @@ -36,12 +35,11 @@ bufferline.setup { return false elseif type == "hori" then return false - else - return true end - else return true end + + return true end, }, @@ -121,6 +119,7 @@ bufferline.setup { guifg = colors.black2, guibg = colors.black2, }, + -- tabs tab = { guifg = colors.light_grey, diff --git a/lua/plugins/configs/cmp.lua b/lua/plugins/configs/cmp.lua index eab3bd2..80e2df4 100644 --- a/lua/plugins/configs/cmp.lua +++ b/lua/plugins/configs/cmp.lua @@ -6,7 +6,6 @@ end vim.opt.completeopt = "menuone,noselect" --- nvim-cmp setup cmp.setup { snippet = { expand = function(args) @@ -15,12 +14,8 @@ cmp.setup { }, formatting = { format = function(entry, vim_item) - -- load lspkind icons - vim_item.kind = string.format( - "%s %s", - require("plugins.configs.lspkind_icons").icons[vim_item.kind], - vim_item.kind - ) + local icons = require "plugins.configs.lspkind_icons" + vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) vim_item.menu = ({ nvim_lsp = "[LSP]", diff --git a/lua/plugins/configs/gitsigns.lua b/lua/plugins/configs/gitsigns.lua deleted file mode 100644 index f2b58f6..0000000 --- a/lua/plugins/configs/gitsigns.lua +++ /dev/null @@ -1,34 +0,0 @@ -local present, gitsigns = pcall(require, "gitsigns") -if not present then - return -end - -gitsigns.setup { - keymaps = { - -- Default keymap options - buffer = true, - noremap = true, - ["n ]c"] = { expr = true, "&diff ? ']c' : 'lua require\"gitsigns\".next_hunk()'" }, - ["n [c"] = { expr = true, "&diff ? '[c' : 'lua require\"gitsigns\".prev_hunk()'" }, - ["n hs"] = 'lua require"gitsigns".stage_hunk()', - ["n hu"] = 'lua require"gitsigns".undo_stage_hunk()', - ["n hr"] = 'lua require"gitsigns".reset_hunk()', - ["n hp"] = 'lua require"gitsigns".preview_hunk()', - ["n hb"] = 'lua require"gitsigns".blame_line()', - }, - numhl = false, - - sign_priority = 5, - signs = { - add = { hl = "DiffAdd", text = "│", numhl = "GitSignsAddNr" }, - change = { hl = "DiffChange", text = "│", numhl = "GitSignsChangeNr" }, - changedelete = { hl = "DiffChange", text = "~", numhl = "GitSignsChangeNr" }, - delete = { hl = "DiffDelete", text = "_", numhl = "GitSignsDeleteNr" }, - topdelete = { hl = "DiffDelete", text = "‾", numhl = "GitSignsDeleteNr" }, - }, - - status_formatter = nil, -- Use default - watch_gitdir = { - interval = 100, - }, -} diff --git a/lua/plugins/configs/lspkind_icons.lua b/lua/plugins/configs/lspkind_icons.lua index dd775b7..ea584ae 100644 --- a/lua/plugins/configs/lspkind_icons.lua +++ b/lua/plugins/configs/lspkind_icons.lua @@ -1,6 +1,4 @@ -local M = {} - -M.icons = { +local icons = { Text = "", Method = "", Function = "", @@ -28,4 +26,4 @@ M.icons = { TypeParameter = "", } -return M +return icons diff --git a/lua/plugins/configs/nvimtree.lua b/lua/plugins/configs/nvimtree.lua index 95b0319..e741d69 100644 --- a/lua/plugins/configs/nvimtree.lua +++ b/lua/plugins/configs/nvimtree.lua @@ -17,10 +17,9 @@ g.nvim_tree_indent_markers = 1 g.nvim_tree_ignore = { ".git", "node_modules", ".cache" } g.nvim_tree_quit_on_open = 0 -- closes tree when file's opened g.nvim_tree_root_folder_modifier = table.concat { ":t:gs?$?/..", string.rep(" ", 1000), "?:gs?^??" } --- + g.nvim_tree_show_icons = { folders = 1, - -- folder_arrows= 1 files = 1, git = git_status, } @@ -38,11 +37,8 @@ g.nvim_tree_icons = { untracked = "★", }, folder = { - -- disable indent_markers option to get arrows working or if you want both arrows and indent then just add the arrow icons in front ofthe default and opened folders below! - -- arrow_open = "", - -- arrow_closed = "", default = "", - empty = "", --  + empty = "", empty_open = "", open = "", symlink = "", diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index 9a55fab..e44ed8e 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -1,19 +1,17 @@ local M = {} local chadrc_config = require("core.utils").load_config() + M.autopairs = function() local present1, autopairs = pcall(require, "nvim-autopairs") local present2, cmp_autopairs = pcall(require, "nvim-autopairs.completion.cmp") - if not (present1 or present2) then - return + if present1 and present2 then + autopairs.setup() + + local cmp = require "cmp" + cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) end - - autopairs.setup() - - -- not needed if you disable cmp, the above var related to cmp tooo! override default config for autopairs - local cmp = require "cmp" - cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) end M.better_escape = function() @@ -71,17 +69,15 @@ end M.luasnip = function() local present, luasnip = pcall(require, "luasnip") - if not present then - return + if present then + luasnip.config.set_config { + history = true, + updateevents = "TextChanged,TextChangedI", + } + + require("luasnip/loaders/from_vscode").load { paths = chadrc_config.plugins.options.luasnip.snippet_path } + require("luasnip/loaders/from_vscode").load() end - - luasnip.config.set_config { - history = true, - updateevents = "TextChanged,TextChangedI", - } - - require("luasnip/loaders/from_vscode").load { paths = chadrc_config.plugins.options.luasnip.snippet_path } - require("luasnip/loaders/from_vscode").load() end M.signature = function() @@ -114,8 +110,8 @@ M.lsp_handlers = function() lspSymbol("Error", "") lspSymbol("Information", "") - lspSymbol("Hint", "") - lspSymbol("Warning", "") + lspSymbol("Hint", "") + lspSymbol("Warning", "") vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = { @@ -146,4 +142,19 @@ M.lsp_handlers = function() end end +M.gitsigns = function() + local present, gitsigns = pcall(require, "gitsigns") + if present then + gitsigns.setup { + signs = { + add = { hl = "DiffAdd", text = "│", numhl = "GitSignsAddNr" }, + change = { hl = "DiffChange", text = "│", numhl = "GitSignsChangeNr" }, + delete = { hl = "DiffDelete", text = "", numhl = "GitSignsDeleteNr" }, + topdelete = { hl = "DiffDelete", text = "‾", numhl = "GitSignsDeleteNr" }, + changedelete = { hl = "DiffChangeDelete", text = "~", numhl = "GitSignsChangeNr" }, + }, + } + end +end + return M diff --git a/lua/plugins/configs/statusline.lua b/lua/plugins/configs/statusline.lua index 0a8f4aa..b7bf633 100644 --- a/lua/plugins/configs/statusline.lua +++ b/lua/plugins/configs/statusline.lua @@ -43,10 +43,12 @@ local icon_styles = { } local config = require("core.utils").load_config().plugins.options.statusline + -- statusline style local user_statusline_style = config.style local statusline_style = icon_styles[user_statusline_style] --- if show short statusline on small screens + +-- show short statusline on small screens local shortline = config.shortline == false and true -- Initialize the components table @@ -55,7 +57,6 @@ local components = { inactive = {}, } --- Initialize left, mid and right table.insert(components.active, {}) table.insert(components.active, {}) table.insert(components.active, {}) @@ -186,6 +187,7 @@ components.active[1][10] = { components.active[2][1] = { provider = function() local Lsp = vim.lsp.util.get_progress_messages()[1] + if Lsp then local msg = Lsp.message or "" local percentage = Lsp.percentage or 0 @@ -207,10 +209,11 @@ components.active[2][1] = { if percentage >= 70 then return string.format(" %%<%s %s %s (%s%%%%) ", success_icon[frame + 1], title, msg, percentage) - else - return string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage) end + + return string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage) end + return "" end, enabled = shortline or function(winid) diff --git a/lua/plugins/configs/telescope.lua b/lua/plugins/configs/telescope.lua index 6db93db..c29b28d 100644 --- a/lua/plugins/configs/telescope.lua +++ b/lua/plugins/configs/telescope.lua @@ -1,4 +1,5 @@ local present, telescope = pcall(require, "telescope") + if not present then return end diff --git a/lua/plugins/configs/treesitter.lua b/lua/plugins/configs/treesitter.lua index 42ab87e..a9a7f49 100644 --- a/lua/plugins/configs/treesitter.lua +++ b/lua/plugins/configs/treesitter.lua @@ -1,4 +1,5 @@ local present, ts_config = pcall(require, "nvim-treesitter.configs") + if not present then return end diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 39a3c14..5a7fa7b 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -78,7 +78,7 @@ return packer.startup(function() "lewis6991/gitsigns.nvim", disable = not plugin_settings.status.gitsigns, opt = true, - config = override_req("gitsigns", "plugins.configs.gitsigns"), + config = override_req("gitsigns", "(plugins.configs.others).gitsigns()"), setup = function() require("core.utils").packer_lazy_load "gitsigns.nvim" end,