From f7e480cd62e58e913bfb0a93f36f4dca026352e5 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Tue, 23 Jul 2024 19:53:55 +0300 Subject: refactor(neovim): renamed custom/configs -> custom/config --- .config/nvim/lua/custom/config/cmp.lua | 122 +++++++++++++++++++++ .../nvim/lua/custom/config/language-servers.lua | 29 +++++ .config/nvim/lua/custom/config/lsp-keymaps.lua | 58 ++++++++++ .config/nvim/lua/custom/config/lsp.lua | 63 +++++++++++ .config/nvim/lua/custom/config/lualine.lua | 92 ++++++++++++++++ .config/nvim/lua/custom/config/mason.lua | 33 ++++++ .config/nvim/lua/custom/config/telescope.lua | 40 +++++++ .config/nvim/lua/custom/configs/completion.lua | 122 --------------------- .../nvim/lua/custom/configs/language-servers.lua | 29 ----- .config/nvim/lua/custom/configs/lsp-keymaps.lua | 58 ---------- .config/nvim/lua/custom/configs/lsp.lua | 63 ----------- .config/nvim/lua/custom/configs/lualine.lua | 92 ---------------- .config/nvim/lua/custom/configs/mason.lua | 33 ------ .config/nvim/lua/custom/configs/telescope.lua | 40 ------- .config/nvim/lua/custom/plugins/lspconfig.lua | 4 +- .config/nvim/lua/custom/plugins/lualine.lua | 2 +- .config/nvim/lua/custom/plugins/nvim-cmp.lua | 2 +- .config/nvim/lua/custom/plugins/telescope.lua | 2 +- 18 files changed, 442 insertions(+), 442 deletions(-) create mode 100644 .config/nvim/lua/custom/config/cmp.lua create mode 100644 .config/nvim/lua/custom/config/language-servers.lua create mode 100644 .config/nvim/lua/custom/config/lsp-keymaps.lua create mode 100644 .config/nvim/lua/custom/config/lsp.lua create mode 100644 .config/nvim/lua/custom/config/lualine.lua create mode 100644 .config/nvim/lua/custom/config/mason.lua create mode 100644 .config/nvim/lua/custom/config/telescope.lua delete mode 100644 .config/nvim/lua/custom/configs/completion.lua delete mode 100644 .config/nvim/lua/custom/configs/language-servers.lua delete mode 100644 .config/nvim/lua/custom/configs/lsp-keymaps.lua delete mode 100644 .config/nvim/lua/custom/configs/lsp.lua delete mode 100644 .config/nvim/lua/custom/configs/lualine.lua delete mode 100644 .config/nvim/lua/custom/configs/mason.lua delete mode 100644 .config/nvim/lua/custom/configs/telescope.lua (limited to '.config/nvim/lua/custom') diff --git a/.config/nvim/lua/custom/config/cmp.lua b/.config/nvim/lua/custom/config/cmp.lua new file mode 100644 index 0000000..127f7b3 --- /dev/null +++ b/.config/nvim/lua/custom/config/cmp.lua @@ -0,0 +1,122 @@ +-- Load snippets +for _, ft_path in ipairs(vim.api.nvim_get_runtime_file('lua/custom/snippets/*.lua', true)) do + loadfile(ft_path)() +end + +local luasnip = require('luasnip') +local lspkind = require('lspkind') +local cmp = require('cmp') + +-- Enable paretheses for function completions +cmp.event:on('confirm_done', require('nvim-autopairs.completion.cmp').on_confirm_done()) + +-- Helper functions +local function snippet_jump(jump_amount) + return cmp.mapping(function(fallback) + if luasnip.locally_jumpable(jump_amount) then + luasnip.jump(jump_amount) + else + fallback() + end + end, { 'i', 's' }) +end + +local function is_enabled() + local context = require('cmp.config.context') + + local is_in_comment = context.in_treesitter_capture('comment') or context.in_syntax_group('Comment') + if is_in_comment then + return false + end + + return true +end + +cmp.setup({ + enabled = is_enabled, + completion = { completeopt = 'menu,menuone,noinsert' }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, -- for lsp + { name = 'luasnip' }, -- for snippets + { name = 'lazydev', group_index = 0 }, -- for lazydev.nvim + { name = 'path' }, -- for filesystem + }, {}), + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + window = { + documentation = cmp.config.window.bordered(), + completion = { + border = 'rounded', + winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,Search:None', + col_offset = -3, + side_padding = 0, + }, + }, + mapping = cmp.mapping.preset.insert({ + [''] = snippet_jump(1), + [''] = snippet_jump(-1), + [''] = cmp.mapping.complete(), -- invoke completion + [''] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Insert }), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), + [''] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), + }), + ---@diagnostic disable-next-line: missing-fields + formatting = { + fields = { 'kind', 'abbr', 'menu' }, + format = function(entry, vim_item) + local kind = lspkind.cmp_format({ mode = 'symbol_text', maxwidth = 50 })(entry, vim_item) + local strings = vim.split(kind.kind, '%s', { trimempty = true }) + kind.kind = ' ' .. (strings[1] or '') .. ' ' -- left (icon) + kind.menu = ' ' .. (strings[2] or '') .. '' -- right (text) + return kind + end, + }, +}) + +-- -- Customization for Pmenu +-- vim.api.nvim_set_hl(0, 'PmenuSel', { bg = '#282C34', fg = 'NONE' }) +-- vim.api.nvim_set_hl(0, 'Pmenu', { fg = '#C5CDD9', bg = '#22252A' }) +-- +vim.api.nvim_set_hl(0, 'CmpItemAbbrDeprecated', { fg = '#ff8294', bg = 'NONE', strikethrough = true }) +-- vim.api.nvim_set_hl(0, 'CmpItemAbbrMatch', { fg = '#82AAFF', bg = 'NONE', bold = true }) +-- vim.api.nvim_set_hl(0, 'CmpItemAbbrMatchFuzzy', { fg = '#82AAFF', bg = 'NONE', bold = true }) +-- vim.api.nvim_set_hl(0, 'CmpItemMenu', { fg = '#C792EA', bg = 'NONE', italic = true }) +-- +-- vim.api.nvim_set_hl(0, 'CmpItemKindField', { fg = '#EED8DA', bg = '#B5585F' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindProperty', { fg = '#EED8DA', bg = '#B5585F' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindEvent', { fg = '#EED8DA', bg = '#B5585F' }) +-- +-- vim.api.nvim_set_hl(0, 'CmpItemKindText', { fg = '#C3E88D', bg = '#9FBD73' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindEnum', { fg = '#C3E88D', bg = '#9FBD73' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindKeyword', { fg = '#C3E88D', bg = '#9FBD73' }) +-- +-- vim.api.nvim_set_hl(0, 'CmpItemKindConstant', { fg = '#FFE082', bg = '#D4BB6C' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindConstructor', { fg = '#FFE082', bg = '#D4BB6C' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindReference', { fg = '#FFE082', bg = '#D4BB6C' }) +-- +-- vim.api.nvim_set_hl(0, 'CmpItemKindFunction', { fg = '#EADFF0', bg = '#A377BF' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindStruct', { fg = '#EADFF0', bg = '#A377BF' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindClass', { fg = '#EADFF0', bg = '#A377BF' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindModule', { fg = '#EADFF0', bg = '#A377BF' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindOperator', { fg = '#EADFF0', bg = '#A377BF' }) +-- +-- vim.api.nvim_set_hl(0, 'CmpItemKindVariable', { fg = '#C5CDD9', bg = '#7E8294' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindFile', { fg = '#C5CDD9', bg = '#7E8294' }) +-- +-- vim.api.nvim_set_hl(0, 'CmpItemKindUnit', { fg = '#F5EBD9', bg = '#D4A959' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindSnippet', { fg = '#F5EBD9', bg = '#D4A959' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindFolder', { fg = '#F5EBD9', bg = '#D4A959' }) +-- +-- vim.api.nvim_set_hl(0, 'CmpItemKindMethod', { fg = '#DDE5F5', bg = '#6C8ED4' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindValue', { fg = '#DDE5F5', bg = '#6C8ED4' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindEnumMember', { fg = '#DDE5F5', bg = '#6C8ED4' }) +-- +-- vim.api.nvim_set_hl(0, 'CmpItemKindInterface', { fg = '#D8EEEB', bg = '#58B5A8' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindColor', { fg = '#D8EEEB', bg = '#58B5A8' }) +-- vim.api.nvim_set_hl(0, 'CmpItemKindTypeParameter', { fg = '#D8EEEB', bg = '#58B5A8' }) diff --git a/.config/nvim/lua/custom/config/language-servers.lua b/.config/nvim/lua/custom/config/language-servers.lua new file mode 100644 index 0000000..1165994 --- /dev/null +++ b/.config/nvim/lua/custom/config/language-servers.lua @@ -0,0 +1,29 @@ +-- NOTE: A list of language servers (and potentially their config) +-- Accepts either true to enable, false to disable or a table with settings +return { + -- lua_ls = { + -- settings = { + -- diagnostics = { + -- globals = { 'vim' }, + -- }, + -- workspace = { + -- library = { + -- [vim.fn.expand('$VIMRUNTIME/lua')] = true, + -- [vim.fn.stdpath('config') .. '/lua'] = true, + -- }, + -- }, + -- }, + -- }, -- lua + lua_ls = true, -- lua + clangd = true, -- C/C++ + gradle_ls = true, -- java package manager + jdtls = true, -- java eclipse lsp + kotlin_language_server = true, -- kotlin + pyright = true, -- python + rust_analyzer = true, -- rust + bashls = true, -- bash + taplo = true, -- toml + lemminx = true, -- xml + yamlls = true, -- yaml + jsonls = true, -- json +} diff --git a/.config/nvim/lua/custom/config/lsp-keymaps.lua b/.config/nvim/lua/custom/config/lsp-keymaps.lua new file mode 100644 index 0000000..f43a03e --- /dev/null +++ b/.config/nvim/lua/custom/config/lsp-keymaps.lua @@ -0,0 +1,58 @@ +local severity = vim.diagnostic.severity +local function next_diagnostic(diagnostic_severity) + return function() + require('lspsaga.diagnostic'):goto_next({ severity = diagnostic_severity }) + end +end +local function prev_diagnostic(diagnostic_severity) + return function() + require('lspsaga.diagnostic'):goto_prev({ severity = diagnostic_severity }) + end +end +local function cursor_diagnostics() + vim.diagnostic.open_float({ + scope = 'cursor', + border = 'single', + }) +end + +local keymaps = { + { 'n', 'gd', 'Telescope lsp_definitions', { desc = '[G]oto [D]efinition' } }, + { 'n', 'gu', 'Telescope lsp_references', { desc = '[G]oto [U]sages' } }, + { 'n', 'gi', 'Telescope lsp_implementations', { desc = '[G]oto [I]mplementations' } }, + { 'n', 'gt', 'Telescope lsp_type_definitions', { desc = '[G]oto [T]ype Definitions' } }, + { 'n', 'ds', 'Telescope lsp_document_symbols', { desc = '[D]ocument [S]symbols' } }, + { 'n', 'ps', 'Telescope lsp_workspace_symbols', { desc = '[P]roject [S]ymbols' } }, + { { 'n', 'i' }, '', vim.lsp.buf.signature_help, { desc = 'Show [P]arameters' } }, + { 'n', 'K', 'Lspsaga hover_doc', { desc = 'Documentation' } }, + { 'n', 'R', 'Lspsaga rename', { desc = '[R]ename' } }, + { { 'n', 'i' }, '', 'Lspsaga code_action', { desc = 'Code Actions' } }, + { 'n', 'ca', 'Lspsaga code_action', { desc = '[C]ode [A]ctions' } }, + { 'n', 'ge', next_diagnostic(severity.ERROR), { desc = '[G]oto [E]rror' } }, + { 'n', 'gE', prev_diagnostic(severity.ERROR), { desc = '[G]oto [E]rror (prev)' } }, + { 'n', 'gw', next_diagnostic(severity.ERROR), { desc = '[G]oto [W]arning' } }, + { 'n', 'gW', prev_diagnostic(severity.ERROR), { desc = '[G]oto [W]arning (prev)' } }, + { 'n', 'D', cursor_diagnostics, { desc = '[D]iagnostics under cursor' } }, +} + +local M = {} + +--- Registers LSP keymaps for the given buffer +---@param bufnr number: the id of the buffer +M.setup = function(bufnr) + for _, keymap in ipairs(keymaps) do + local mode = keymap[1] + local lhs = keymap[2] + local rhs = keymap[3] + local opts = keymap[4] + + if not opts then + opts = {} + end + + opts.buffer = bufnr + vim.keymap.set(mode, lhs, rhs, opts) + end +end + +return M diff --git a/.config/nvim/lua/custom/config/lsp.lua b/.config/nvim/lua/custom/config/lsp.lua new file mode 100644 index 0000000..e099dd8 --- /dev/null +++ b/.config/nvim/lua/custom/config/lsp.lua @@ -0,0 +1,63 @@ +local capabilities = require('cmp_nvim_lsp').default_capabilities() +local servers = require('lua.custom.config.language-servers') + +local lspconfig = require('lspconfig') +for name, config in pairs(servers) do + if config == true then + ---@diagnostic disable-next-line: cast-local-type + config = {} + end + ---@diagnostic disable-next-line: cast-local-type + config = vim.tbl_deep_extend('force', {}, { + capabilities = capabilities, + }, config) + + lspconfig[name].setup(config) +end + +vim.api.nvim_create_autocmd('LspAttach', { + callback = function(args) + local bufnr = args.buf + local client = assert(vim.lsp.get_client_by_id(args.data.client_id), 'must have valid client') + + local settings = servers[client.name] + if type(settings) ~= 'table' then + ---@diagnostic disable-next-line: cast-local-type + settings = {} + end + + -- Override server capabilities + if settings.server_capabilities then + for k, v in pairs(settings.server_capabilities) do + if v == vim.NIL then + v = nil + end + client.server_capabilities[k] = v + end + end + + -- Register LSP keymaps local to buffer + require('lua.custom.config.lsp-keymaps').setup(bufnr) + end, +}) + +-- TODO: Decide if you want to use conform or not +-- +-- -- Autoformatting Setup +-- require('conform').setup({ +-- formatters_by_ft = { +-- lua = { 'stylua' }, +-- }, +-- }) +-- +-- vim.api.nvim_create_autocmd('BufWritePre', { +-- callback = function(args) +-- require('conform').format({ +-- bufnr = args.buf, +-- lsp_fallback = true, +-- quiet = true, +-- }) +-- end, +-- }) + +vim.diagnostic.config({ virtual_text = false }) diff --git a/.config/nvim/lua/custom/config/lualine.lua b/.config/nvim/lua/custom/config/lualine.lua new file mode 100644 index 0000000..ce581c4 --- /dev/null +++ b/.config/nvim/lua/custom/config/lualine.lua @@ -0,0 +1,92 @@ +local lualine = require('lualine') +local lsp_progress = require('lsp-progress') + +local progress_filled = '█' +local progress_empty = '░' +local function progress_bar(percentage, width) + -- Ensure i is an integer between 0 and width (inclusive) + local i = math.max(0, math.min(math.floor(width * percentage), width)) + return string.rep(progress_filled, i) .. string.rep(progress_empty, width - i) +end + +local progress_bar_width = 10 +lsp_progress.setup({ + format = function(client_messages) -- global + local sign = ' LSP' + if #client_messages > 0 then + return sign .. ' ' .. table.concat(client_messages, ' ') + end + if #require('lsp-progress.api').lsp_clients() > 0 then + return sign + end + return '' + end, + client_format = function(_, _, series_messages) -- per lsp + return #series_messages > 0 and table.concat(series_messages, ', ') or nil + end, + series_format = function(title, message, percentage, done) -- per progress + local builder = {} + local has_title = false + local has_message = false + if type(title) == 'string' and string.len(title) > 0 then + table.insert(builder, title .. ':') + has_title = true + end + if percentage then + table.insert(builder, string.format('%.0f%%', percentage)) + table.insert(builder, 1, progress_bar(percentage / 100, progress_bar_width)) + end + if type(message) == 'string' and string.len(message) > 0 then + table.insert(builder, string.format('(%s)', message)) + has_message = true + end + if done and (has_title or has_message) then + table.insert(builder, ' ') + end + return table.concat(builder, ' ') + end, +}) + +lualine.setup({ + options = { + globalstatus = true, + theme = 'auto', + }, + sections = { + lualine_a = { { 'mode', icon = '' } }, + lualine_b = { + require('auto-session.lib').current_session_name, + { 'branch', icon = '' }, + { + 'diagnostics', + symbols = { + error = '󰅙 ', + warn = '󰀦 ', + info = '󰋼 ', + hint = '󰌵 ', + }, + }, + }, + lualine_c = { + function() + return lsp_progress.progress() + end, + }, + lualine_x = { + 'searchcount', + 'encoding', + 'fileformat', + 'filetype', + }, + lualine_y = { 'progress' }, + lualine_z = { 'location' }, + }, + extensions = { 'oil', 'trouble' }, +}) + +-- Refresh lualine when lsp progress is updated +vim.api.nvim_create_autocmd('User', { + group = vim.api.nvim_create_augroup('lualine_augroup', { clear = true }), + pattern = 'LspProgressStatusUpdated', + callback = require('lualine').refresh, +}) diff --git a/.config/nvim/lua/custom/config/mason.lua b/.config/nvim/lua/custom/config/mason.lua new file mode 100644 index 0000000..886adc2 --- /dev/null +++ b/.config/nvim/lua/custom/config/mason.lua @@ -0,0 +1,33 @@ +-- NOTE: Not language servers but still make sure mason installs them +local ensure_installed = { + stylua = true, -- lua formatting +} +local servers = require('custom.config.language-servers') + +require('mason').setup({ + ui = { + icons = { + package_installed = '✓', + package_pending = '➜', + package_uninstalled = '✗', + }, + }, +}) + +local servers_to_install = vim.tbl_filter(function(key) + local server = servers[key] + if type(server) == 'table' then + return true + else + return server + end +end, vim.tbl_keys(servers)) + +vim.list_extend(ensure_installed, servers_to_install) +require('mason-lspconfig').setup({ ensure_installed = servers_to_install }) + +require('mason-tool-installer').setup({ + ensure_installed = { + 'stylua', -- lua formatter + }, +}) diff --git a/.config/nvim/lua/custom/config/telescope.lua b/.config/nvim/lua/custom/config/telescope.lua new file mode 100644 index 0000000..b554a33 --- /dev/null +++ b/.config/nvim/lua/custom/config/telescope.lua @@ -0,0 +1,40 @@ +local telescope = require('telescope') +telescope.setup({ + pickers = { + find_files = { follow = true }, + grep_string = { additional_args = '--follow' }, + live_grep = { additional_args = '--follow' }, + }, + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, + override_file_sorter = true, + case_mode = 'smart_case', -- default "smart_case" or "ignore_case" or "respect_case" + }, + ['ui-select'] = { + require('telescope.themes').get_dropdown({}), + }, + }, +}) + +pcall(telescope.load_extension('ui-select')) +pcall(telescope.load_extension('fzf')) + +local builtin = require('telescope.builtin') +local function find_all() + builtin.find_files({ + cwd = '~', + hidden = true, + no_ignore = true, + no_ignore_parent = true, + }) +end + +vim.keymap.set('n', 'fs', builtin.find_files, { desc = '[F]ile [S]ystem' }) +vim.keymap.set('n', 'fa', find_all, { desc = '[F]ind [A]ll files' }) +vim.keymap.set('n', 'fh', builtin.help_tags, { desc = '[F]ind [H]elp' }) +vim.keymap.set('n', 'fm', builtin.man_pages, { desc = '[F]ind [M]an Pages' }) +vim.keymap.set('n', 'lv', builtin.live_grep, { desc = '[L]ive [G]rep' }) +vim.keymap.set('n', 'f.', builtin.oldfiles, { desc = '[F]ind Recent Files' }) +vim.keymap.set('n', 'th', builtin.colorscheme, { desc = 'List [Th]eme' }) diff --git a/.config/nvim/lua/custom/configs/completion.lua b/.config/nvim/lua/custom/configs/completion.lua deleted file mode 100644 index 127f7b3..0000000 --- a/.config/nvim/lua/custom/configs/completion.lua +++ /dev/null @@ -1,122 +0,0 @@ --- Load snippets -for _, ft_path in ipairs(vim.api.nvim_get_runtime_file('lua/custom/snippets/*.lua', true)) do - loadfile(ft_path)() -end - -local luasnip = require('luasnip') -local lspkind = require('lspkind') -local cmp = require('cmp') - --- Enable paretheses for function completions -cmp.event:on('confirm_done', require('nvim-autopairs.completion.cmp').on_confirm_done()) - --- Helper functions -local function snippet_jump(jump_amount) - return cmp.mapping(function(fallback) - if luasnip.locally_jumpable(jump_amount) then - luasnip.jump(jump_amount) - else - fallback() - end - end, { 'i', 's' }) -end - -local function is_enabled() - local context = require('cmp.config.context') - - local is_in_comment = context.in_treesitter_capture('comment') or context.in_syntax_group('Comment') - if is_in_comment then - return false - end - - return true -end - -cmp.setup({ - enabled = is_enabled, - completion = { completeopt = 'menu,menuone,noinsert' }, - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, -- for lsp - { name = 'luasnip' }, -- for snippets - { name = 'lazydev', group_index = 0 }, -- for lazydev.nvim - { name = 'path' }, -- for filesystem - }, {}), - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - window = { - documentation = cmp.config.window.bordered(), - completion = { - border = 'rounded', - winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,Search:None', - col_offset = -3, - side_padding = 0, - }, - }, - mapping = cmp.mapping.preset.insert({ - [''] = snippet_jump(1), - [''] = snippet_jump(-1), - [''] = cmp.mapping.complete(), -- invoke completion - [''] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Insert }), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), - [''] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), - }), - ---@diagnostic disable-next-line: missing-fields - formatting = { - fields = { 'kind', 'abbr', 'menu' }, - format = function(entry, vim_item) - local kind = lspkind.cmp_format({ mode = 'symbol_text', maxwidth = 50 })(entry, vim_item) - local strings = vim.split(kind.kind, '%s', { trimempty = true }) - kind.kind = ' ' .. (strings[1] or '') .. ' ' -- left (icon) - kind.menu = ' ' .. (strings[2] or '') .. '' -- right (text) - return kind - end, - }, -}) - --- -- Customization for Pmenu --- vim.api.nvim_set_hl(0, 'PmenuSel', { bg = '#282C34', fg = 'NONE' }) --- vim.api.nvim_set_hl(0, 'Pmenu', { fg = '#C5CDD9', bg = '#22252A' }) --- -vim.api.nvim_set_hl(0, 'CmpItemAbbrDeprecated', { fg = '#ff8294', bg = 'NONE', strikethrough = true }) --- vim.api.nvim_set_hl(0, 'CmpItemAbbrMatch', { fg = '#82AAFF', bg = 'NONE', bold = true }) --- vim.api.nvim_set_hl(0, 'CmpItemAbbrMatchFuzzy', { fg = '#82AAFF', bg = 'NONE', bold = true }) --- vim.api.nvim_set_hl(0, 'CmpItemMenu', { fg = '#C792EA', bg = 'NONE', italic = true }) --- --- vim.api.nvim_set_hl(0, 'CmpItemKindField', { fg = '#EED8DA', bg = '#B5585F' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindProperty', { fg = '#EED8DA', bg = '#B5585F' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindEvent', { fg = '#EED8DA', bg = '#B5585F' }) --- --- vim.api.nvim_set_hl(0, 'CmpItemKindText', { fg = '#C3E88D', bg = '#9FBD73' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindEnum', { fg = '#C3E88D', bg = '#9FBD73' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindKeyword', { fg = '#C3E88D', bg = '#9FBD73' }) --- --- vim.api.nvim_set_hl(0, 'CmpItemKindConstant', { fg = '#FFE082', bg = '#D4BB6C' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindConstructor', { fg = '#FFE082', bg = '#D4BB6C' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindReference', { fg = '#FFE082', bg = '#D4BB6C' }) --- --- vim.api.nvim_set_hl(0, 'CmpItemKindFunction', { fg = '#EADFF0', bg = '#A377BF' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindStruct', { fg = '#EADFF0', bg = '#A377BF' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindClass', { fg = '#EADFF0', bg = '#A377BF' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindModule', { fg = '#EADFF0', bg = '#A377BF' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindOperator', { fg = '#EADFF0', bg = '#A377BF' }) --- --- vim.api.nvim_set_hl(0, 'CmpItemKindVariable', { fg = '#C5CDD9', bg = '#7E8294' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindFile', { fg = '#C5CDD9', bg = '#7E8294' }) --- --- vim.api.nvim_set_hl(0, 'CmpItemKindUnit', { fg = '#F5EBD9', bg = '#D4A959' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindSnippet', { fg = '#F5EBD9', bg = '#D4A959' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindFolder', { fg = '#F5EBD9', bg = '#D4A959' }) --- --- vim.api.nvim_set_hl(0, 'CmpItemKindMethod', { fg = '#DDE5F5', bg = '#6C8ED4' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindValue', { fg = '#DDE5F5', bg = '#6C8ED4' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindEnumMember', { fg = '#DDE5F5', bg = '#6C8ED4' }) --- --- vim.api.nvim_set_hl(0, 'CmpItemKindInterface', { fg = '#D8EEEB', bg = '#58B5A8' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindColor', { fg = '#D8EEEB', bg = '#58B5A8' }) --- vim.api.nvim_set_hl(0, 'CmpItemKindTypeParameter', { fg = '#D8EEEB', bg = '#58B5A8' }) diff --git a/.config/nvim/lua/custom/configs/language-servers.lua b/.config/nvim/lua/custom/configs/language-servers.lua deleted file mode 100644 index 1165994..0000000 --- a/.config/nvim/lua/custom/configs/language-servers.lua +++ /dev/null @@ -1,29 +0,0 @@ --- NOTE: A list of language servers (and potentially their config) --- Accepts either true to enable, false to disable or a table with settings -return { - -- lua_ls = { - -- settings = { - -- diagnostics = { - -- globals = { 'vim' }, - -- }, - -- workspace = { - -- library = { - -- [vim.fn.expand('$VIMRUNTIME/lua')] = true, - -- [vim.fn.stdpath('config') .. '/lua'] = true, - -- }, - -- }, - -- }, - -- }, -- lua - lua_ls = true, -- lua - clangd = true, -- C/C++ - gradle_ls = true, -- java package manager - jdtls = true, -- java eclipse lsp - kotlin_language_server = true, -- kotlin - pyright = true, -- python - rust_analyzer = true, -- rust - bashls = true, -- bash - taplo = true, -- toml - lemminx = true, -- xml - yamlls = true, -- yaml - jsonls = true, -- json -} diff --git a/.config/nvim/lua/custom/configs/lsp-keymaps.lua b/.config/nvim/lua/custom/configs/lsp-keymaps.lua deleted file mode 100644 index f43a03e..0000000 --- a/.config/nvim/lua/custom/configs/lsp-keymaps.lua +++ /dev/null @@ -1,58 +0,0 @@ -local severity = vim.diagnostic.severity -local function next_diagnostic(diagnostic_severity) - return function() - require('lspsaga.diagnostic'):goto_next({ severity = diagnostic_severity }) - end -end -local function prev_diagnostic(diagnostic_severity) - return function() - require('lspsaga.diagnostic'):goto_prev({ severity = diagnostic_severity }) - end -end -local function cursor_diagnostics() - vim.diagnostic.open_float({ - scope = 'cursor', - border = 'single', - }) -end - -local keymaps = { - { 'n', 'gd', 'Telescope lsp_definitions', { desc = '[G]oto [D]efinition' } }, - { 'n', 'gu', 'Telescope lsp_references', { desc = '[G]oto [U]sages' } }, - { 'n', 'gi', 'Telescope lsp_implementations', { desc = '[G]oto [I]mplementations' } }, - { 'n', 'gt', 'Telescope lsp_type_definitions', { desc = '[G]oto [T]ype Definitions' } }, - { 'n', 'ds', 'Telescope lsp_document_symbols', { desc = '[D]ocument [S]symbols' } }, - { 'n', 'ps', 'Telescope lsp_workspace_symbols', { desc = '[P]roject [S]ymbols' } }, - { { 'n', 'i' }, '', vim.lsp.buf.signature_help, { desc = 'Show [P]arameters' } }, - { 'n', 'K', 'Lspsaga hover_doc', { desc = 'Documentation' } }, - { 'n', 'R', 'Lspsaga rename', { desc = '[R]ename' } }, - { { 'n', 'i' }, '', 'Lspsaga code_action', { desc = 'Code Actions' } }, - { 'n', 'ca', 'Lspsaga code_action', { desc = '[C]ode [A]ctions' } }, - { 'n', 'ge', next_diagnostic(severity.ERROR), { desc = '[G]oto [E]rror' } }, - { 'n', 'gE', prev_diagnostic(severity.ERROR), { desc = '[G]oto [E]rror (prev)' } }, - { 'n', 'gw', next_diagnostic(severity.ERROR), { desc = '[G]oto [W]arning' } }, - { 'n', 'gW', prev_diagnostic(severity.ERROR), { desc = '[G]oto [W]arning (prev)' } }, - { 'n', 'D', cursor_diagnostics, { desc = '[D]iagnostics under cursor' } }, -} - -local M = {} - ---- Registers LSP keymaps for the given buffer ----@param bufnr number: the id of the buffer -M.setup = function(bufnr) - for _, keymap in ipairs(keymaps) do - local mode = keymap[1] - local lhs = keymap[2] - local rhs = keymap[3] - local opts = keymap[4] - - if not opts then - opts = {} - end - - opts.buffer = bufnr - vim.keymap.set(mode, lhs, rhs, opts) - end -end - -return M diff --git a/.config/nvim/lua/custom/configs/lsp.lua b/.config/nvim/lua/custom/configs/lsp.lua deleted file mode 100644 index afae5af..0000000 --- a/.config/nvim/lua/custom/configs/lsp.lua +++ /dev/null @@ -1,63 +0,0 @@ -local capabilities = require('cmp_nvim_lsp').default_capabilities() -local servers = require('custom.configs.language-servers') - -local lspconfig = require('lspconfig') -for name, config in pairs(servers) do - if config == true then - ---@diagnostic disable-next-line: cast-local-type - config = {} - end - ---@diagnostic disable-next-line: cast-local-type - config = vim.tbl_deep_extend('force', {}, { - capabilities = capabilities, - }, config) - - lspconfig[name].setup(config) -end - -vim.api.nvim_create_autocmd('LspAttach', { - callback = function(args) - local bufnr = args.buf - local client = assert(vim.lsp.get_client_by_id(args.data.client_id), 'must have valid client') - - local settings = servers[client.name] - if type(settings) ~= 'table' then - ---@diagnostic disable-next-line: cast-local-type - settings = {} - end - - -- Override server capabilities - if settings.server_capabilities then - for k, v in pairs(settings.server_capabilities) do - if v == vim.NIL then - v = nil - end - client.server_capabilities[k] = v - end - end - - -- Register LSP keymaps local to buffer - require('custom.configs.lsp-keymaps').setup(bufnr) - end, -}) - --- TODO: Decide if you want to use conform or not --- --- -- Autoformatting Setup --- require('conform').setup({ --- formatters_by_ft = { --- lua = { 'stylua' }, --- }, --- }) --- --- vim.api.nvim_create_autocmd('BufWritePre', { --- callback = function(args) --- require('conform').format({ --- bufnr = args.buf, --- lsp_fallback = true, --- quiet = true, --- }) --- end, --- }) - -vim.diagnostic.config({ virtual_text = false }) diff --git a/.config/nvim/lua/custom/configs/lualine.lua b/.config/nvim/lua/custom/configs/lualine.lua deleted file mode 100644 index ce581c4..0000000 --- a/.config/nvim/lua/custom/configs/lualine.lua +++ /dev/null @@ -1,92 +0,0 @@ -local lualine = require('lualine') -local lsp_progress = require('lsp-progress') - -local progress_filled = '█' -local progress_empty = '░' -local function progress_bar(percentage, width) - -- Ensure i is an integer between 0 and width (inclusive) - local i = math.max(0, math.min(math.floor(width * percentage), width)) - return string.rep(progress_filled, i) .. string.rep(progress_empty, width - i) -end - -local progress_bar_width = 10 -lsp_progress.setup({ - format = function(client_messages) -- global - local sign = ' LSP' - if #client_messages > 0 then - return sign .. ' ' .. table.concat(client_messages, ' ') - end - if #require('lsp-progress.api').lsp_clients() > 0 then - return sign - end - return '' - end, - client_format = function(_, _, series_messages) -- per lsp - return #series_messages > 0 and table.concat(series_messages, ', ') or nil - end, - series_format = function(title, message, percentage, done) -- per progress - local builder = {} - local has_title = false - local has_message = false - if type(title) == 'string' and string.len(title) > 0 then - table.insert(builder, title .. ':') - has_title = true - end - if percentage then - table.insert(builder, string.format('%.0f%%', percentage)) - table.insert(builder, 1, progress_bar(percentage / 100, progress_bar_width)) - end - if type(message) == 'string' and string.len(message) > 0 then - table.insert(builder, string.format('(%s)', message)) - has_message = true - end - if done and (has_title or has_message) then - table.insert(builder, ' ') - end - return table.concat(builder, ' ') - end, -}) - -lualine.setup({ - options = { - globalstatus = true, - theme = 'auto', - }, - sections = { - lualine_a = { { 'mode', icon = '' } }, - lualine_b = { - require('auto-session.lib').current_session_name, - { 'branch', icon = '' }, - { - 'diagnostics', - symbols = { - error = '󰅙 ', - warn = '󰀦 ', - info = '󰋼 ', - hint = '󰌵 ', - }, - }, - }, - lualine_c = { - function() - return lsp_progress.progress() - end, - }, - lualine_x = { - 'searchcount', - 'encoding', - 'fileformat', - 'filetype', - }, - lualine_y = { 'progress' }, - lualine_z = { 'location' }, - }, - extensions = { 'oil', 'trouble' }, -}) - --- Refresh lualine when lsp progress is updated -vim.api.nvim_create_autocmd('User', { - group = vim.api.nvim_create_augroup('lualine_augroup', { clear = true }), - pattern = 'LspProgressStatusUpdated', - callback = require('lualine').refresh, -}) diff --git a/.config/nvim/lua/custom/configs/mason.lua b/.config/nvim/lua/custom/configs/mason.lua deleted file mode 100644 index d7a537b..0000000 --- a/.config/nvim/lua/custom/configs/mason.lua +++ /dev/null @@ -1,33 +0,0 @@ --- NOTE: Not language servers but still make sure mason installs them -local ensure_installed = { - stylua = true, -- lua formatting -} -local servers = require('custom.configs.language-servers') - -require('mason').setup({ - ui = { - icons = { - package_installed = '✓', - package_pending = '➜', - package_uninstalled = '✗', - }, - }, -}) - -local servers_to_install = vim.tbl_filter(function(key) - local server = servers[key] - if type(server) == 'table' then - return true - else - return server - end -end, vim.tbl_keys(servers)) - -vim.list_extend(ensure_installed, servers_to_install) -require('mason-lspconfig').setup({ ensure_installed = servers_to_install }) - -require('mason-tool-installer').setup({ - ensure_installed = { - 'stylua', -- lua formatter - }, -}) diff --git a/.config/nvim/lua/custom/configs/telescope.lua b/.config/nvim/lua/custom/configs/telescope.lua deleted file mode 100644 index b554a33..0000000 --- a/.config/nvim/lua/custom/configs/telescope.lua +++ /dev/null @@ -1,40 +0,0 @@ -local telescope = require('telescope') -telescope.setup({ - pickers = { - find_files = { follow = true }, - grep_string = { additional_args = '--follow' }, - live_grep = { additional_args = '--follow' }, - }, - extensions = { - fzf = { - fuzzy = true, -- false will only do exact matching - override_generic_sorter = true, - override_file_sorter = true, - case_mode = 'smart_case', -- default "smart_case" or "ignore_case" or "respect_case" - }, - ['ui-select'] = { - require('telescope.themes').get_dropdown({}), - }, - }, -}) - -pcall(telescope.load_extension('ui-select')) -pcall(telescope.load_extension('fzf')) - -local builtin = require('telescope.builtin') -local function find_all() - builtin.find_files({ - cwd = '~', - hidden = true, - no_ignore = true, - no_ignore_parent = true, - }) -end - -vim.keymap.set('n', 'fs', builtin.find_files, { desc = '[F]ile [S]ystem' }) -vim.keymap.set('n', 'fa', find_all, { desc = '[F]ind [A]ll files' }) -vim.keymap.set('n', 'fh', builtin.help_tags, { desc = '[F]ind [H]elp' }) -vim.keymap.set('n', 'fm', builtin.man_pages, { desc = '[F]ind [M]an Pages' }) -vim.keymap.set('n', 'lv', builtin.live_grep, { desc = '[L]ive [G]rep' }) -vim.keymap.set('n', 'f.', builtin.oldfiles, { desc = '[F]ind Recent Files' }) -vim.keymap.set('n', 'th', builtin.colorscheme, { desc = 'List [Th]eme' }) diff --git a/.config/nvim/lua/custom/plugins/lspconfig.lua b/.config/nvim/lua/custom/plugins/lspconfig.lua index c6b85b5..20536e9 100644 --- a/.config/nvim/lua/custom/plugins/lspconfig.lua +++ b/.config/nvim/lua/custom/plugins/lspconfig.lua @@ -14,11 +14,11 @@ return { }, build = ':MasonUpdate', config = function() - require('lua.custom.configs.mason') + require('custom.config.mason') end, }, }, config = function() - require('lua.custom.configs.lsp') + require('custom.config.lsp') end, } diff --git a/.config/nvim/lua/custom/plugins/lualine.lua b/.config/nvim/lua/custom/plugins/lualine.lua index 00ec722..f1e5ec5 100644 --- a/.config/nvim/lua/custom/plugins/lualine.lua +++ b/.config/nvim/lua/custom/plugins/lualine.lua @@ -3,6 +3,6 @@ return { dependencies = { 'nvim-tree/nvim-web-devicons', 'linrongbin16/lsp-progress.nvim' }, event = 'VeryLazy', config = function() - require('custom.configs.lualine') + require('custom.config.lualine') end, } diff --git a/.config/nvim/lua/custom/plugins/nvim-cmp.lua b/.config/nvim/lua/custom/plugins/nvim-cmp.lua index 317c088..4860338 100644 --- a/.config/nvim/lua/custom/plugins/nvim-cmp.lua +++ b/.config/nvim/lua/custom/plugins/nvim-cmp.lua @@ -9,6 +9,6 @@ return { { 'L3MON4D3/LuaSnip', build = 'make install_jsregexp' }, -- snippets plugin }, config = function() - require('lua.custom.configs.completion') + require('custom.config.cmp') end, } diff --git a/.config/nvim/lua/custom/plugins/telescope.lua b/.config/nvim/lua/custom/plugins/telescope.lua index 945dc2e..af0534b 100644 --- a/.config/nvim/lua/custom/plugins/telescope.lua +++ b/.config/nvim/lua/custom/plugins/telescope.lua @@ -8,7 +8,7 @@ return { }, cmd = 'Telescope', config = function() - require('custom.configs.telescope') + require('custom.config.telescope') end, keys = { 'fs', -- cgit v1.3.1