summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/custom/config
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/custom/config')
-rw-r--r--.config/nvim/lua/custom/config/cmp.lua122
-rw-r--r--.config/nvim/lua/custom/config/language-servers.lua29
-rw-r--r--.config/nvim/lua/custom/config/lsp-keymaps.lua58
-rw-r--r--.config/nvim/lua/custom/config/lsp.lua63
-rw-r--r--.config/nvim/lua/custom/config/lualine.lua92
-rw-r--r--.config/nvim/lua/custom/config/mason.lua33
-rw-r--r--.config/nvim/lua/custom/config/telescope.lua40
7 files changed, 437 insertions, 0 deletions
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({
+ ['<Tab>'] = snippet_jump(1),
+ ['<S-Tab>'] = snippet_jump(-1),
+ ['<C-Space>'] = cmp.mapping.complete(), -- invoke completion
+ ['<CR>'] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Insert }),
+ ['<C-u>'] = cmp.mapping.scroll_docs(-4),
+ ['<C-d>'] = cmp.mapping.scroll_docs(4),
+ ['<C-m>'] = cmp.mapping.abort(),
+ ['<C-n>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
+ ['<C-p>'] = 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', '<cmd>Telescope lsp_definitions<cr>', { desc = '[G]oto [D]efinition' } },
+ { 'n', 'gu', '<cmd>Telescope lsp_references<cr>', { desc = '[G]oto [U]sages' } },
+ { 'n', 'gi', '<cmd>Telescope lsp_implementations<cr>', { desc = '[G]oto [I]mplementations' } },
+ { 'n', 'gt', '<cmd>Telescope lsp_type_definitions<cr>', { desc = '[G]oto [T]ype Definitions' } },
+ { 'n', '<leader>ds', '<cmd>Telescope lsp_document_symbols<cr>', { desc = '[D]ocument [S]symbols' } },
+ { 'n', '<leader>ps', '<cmd>Telescope lsp_workspace_symbols<cr>', { desc = '[P]roject [S]ymbols' } },
+ { { 'n', 'i' }, '<C-p>', vim.lsp.buf.signature_help, { desc = 'Show [P]arameters' } },
+ { 'n', 'K', '<cmd>Lspsaga hover_doc<cr>', { desc = 'Documentation' } },
+ { 'n', 'R', '<cmd>Lspsaga rename<cr>', { desc = '[R]ename' } },
+ { { 'n', 'i' }, '<M-Enter>', '<cmd>Lspsaga code_action<cr>', { desc = 'Code Actions' } },
+ { 'n', '<leader>ca', '<cmd>Lspsaga code_action<cr><Esc>', { 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', '<leader>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', '<leader>fs', builtin.find_files, { desc = '[F]ile [S]ystem' })
+vim.keymap.set('n', '<leader>fa', find_all, { desc = '[F]ind [A]ll files' })
+vim.keymap.set('n', '<leader>fh', builtin.help_tags, { desc = '[F]ind [H]elp' })
+vim.keymap.set('n', '<leader>fm', builtin.man_pages, { desc = '[F]ind [M]an Pages' })
+vim.keymap.set('n', '<leader>lv', builtin.live_grep, { desc = '[L]ive [G]rep' })
+vim.keymap.set('n', '<leader>f.', builtin.oldfiles, { desc = '[F]ind Recent Files' })
+vim.keymap.set('n', '<leader>th', builtin.colorscheme, { desc = 'List [Th]eme' })