From e184d7cee358abc277a51f040cacf236f1eaceab Mon Sep 17 00:00:00 2001 From: JP Appel Date: Fri, 16 Aug 2024 16:28:22 -0400 Subject: removed lspzero, updated keymaps --- nvim/lua/plugins/diagnostics.lua | 67 ++++++ nvim/lua/plugins/fugitive.lua | 7 +- nvim/lua/plugins/init.lua | 14 +- nvim/lua/plugins/lsp.lua | 87 ++++++++ nvim/lua/plugins/lspzero.lua | 16 -- nvim/lua/plugins/nvim-cmp.lua | 452 ++++++++++++++++----------------------- nvim/lua/plugins/oil.lua | 8 +- nvim/lua/plugins/sql.lua | 28 +++ nvim/lua/plugins/telescope.lua | 2 +- 9 files changed, 382 insertions(+), 299 deletions(-) create mode 100644 nvim/lua/plugins/diagnostics.lua create mode 100644 nvim/lua/plugins/lsp.lua delete mode 100644 nvim/lua/plugins/lspzero.lua create mode 100644 nvim/lua/plugins/sql.lua (limited to 'nvim/lua/plugins') diff --git a/nvim/lua/plugins/diagnostics.lua b/nvim/lua/plugins/diagnostics.lua new file mode 100644 index 0000000..78c3f02 --- /dev/null +++ b/nvim/lua/plugins/diagnostics.lua @@ -0,0 +1,67 @@ +return { + 'folke/trouble.nvim', + opts = {}, + cmd = 'Trouble', + keys = { + { + "df", + function() + local trouble = require("trouble") + local opts = { + mode = "diagnostics", + focus = true, + follow = false + } + if trouble.is_open(opts) then + trouble.close(opts) + else + trouble.open(opts) + end + end, + desc = "Diagnostics (Trouble)", + }, + { + "dF", + function() + local trouble = require("trouble") + local opts = { + mode = "diagnostics", + focus = true, + follow = false, + filter = { buf = 0 } + } + if not trouble.is_open(opts) then + trouble.open(opts) + trouble.focus(opts) + else + trouble.close(opts) + end + end, + desc = "Buffer Diagnostics (Trouble)", + }, + { + "[d", + function() + require("trouble").prev({ mode = "diagnostics", jump = true }) + end, + desc = "Previous project wide diagnostic" + }, + { + "]d", + function() + require("trouble").next({ mode = "diagnostics", jump = true }) + end, + desc = "Next project wide diagnostic" + }, + { + "dl", + "Trouble loclist toggle", + desc = "Location List (Trouble)", + }, + { + "dq", + "Trouble qflist toggle", + desc = "Quickfix List (Trouble)", + }, + }, +} diff --git a/nvim/lua/plugins/fugitive.lua b/nvim/lua/plugins/fugitive.lua index a203ea8..0607bdb 100644 --- a/nvim/lua/plugins/fugitive.lua +++ b/nvim/lua/plugins/fugitive.lua @@ -1,6 +1,7 @@ return { 'tpope/vim-fugitive', -- close to native git command integrations - keys = { - {"gs", vim.cmd.Git, desc = "Git Status"} - } + -- keys = { + -- { "gs", vim.cmd.Git, desc = "Git Status" } + -- }, + cmd = {'Git'} } diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua index 60d9c90..12d22b1 100644 --- a/nvim/lua/plugins/init.lua +++ b/nvim/lua/plugins/init.lua @@ -6,29 +6,25 @@ return { { 'numToStr/Comment.nvim', -- faster commentting - lazy = false, + event = 'BufEnter', opts = { mappings = { basic = true, extra = false } }, - -- config = function() - -- require('Comment').setup() - -- end }, { "j-hui/fidget.nvim", - config = function () - require("fidget").setup({}) - end + event = { 'LspAttach' }, + opts = {} }, { 'ap/vim-css-color', - ft = {'css', 'scss', 'sass'} - } + ft = { 'css', 'scss', 'sass' } + }, -- cosmetic -- 'kyazdani42/nvim-web-devicons', diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..0089033 --- /dev/null +++ b/nvim/lua/plugins/lsp.lua @@ -0,0 +1,87 @@ +local lspconfig = { + 'neovim/nvim-lspconfig', + lazy = false, + dependencies = { + 'williamboman/mason.nvim', + 'williamboman/mason-lspconfig' + }, + keys = { + { + 'gd', + function() + vim.lsp.buf.definition() + end, + mode = 'n', + desc = "Go to definition" + }, + { + 'r', + function () + vim.lsp.buf.rename() + end, + mode = 'n', + desc = "Rename symbol" + }, + { + 'la', + function () + vim.lsp.buf.code_action() + end, + mode = {'n', 's'}, + desc = "Show code actions" + }, + { + 'lr', + function () + vim.lsp.buf.references() + end, + mode = 'n', + desc = "Add symbol references to qf" + }, + { + '', + function () + vim.lsp.buf.signature_help() + end, + mode = 'i', + desc = "Show signature help" + } + } +} + +local mason = { + 'williamboman/mason.nvim', + opts = {} +} + +local mason_lspconfig = { + 'williamboman/mason-lspconfig.nvim', + dependencies = { + 'williamboman/mason.nvim', + }, + opts = { + handlers = { + function(server_name) + require('lspconfig')[server_name].setup({}) + end + }, + ["lua_ls"] = function () + require('lspconfig').lua_ls.setup({ + settings = { + Lua = { + diagnostics = { + globals = { "vim" } + } + } + } + }) + end + } +} + + +return { + mason, + mason_lspconfig, + lspconfig, +} diff --git a/nvim/lua/plugins/lspzero.lua b/nvim/lua/plugins/lspzero.lua deleted file mode 100644 index 66c4709..0000000 --- a/nvim/lua/plugins/lspzero.lua +++ /dev/null @@ -1,16 +0,0 @@ -return { - 'VonHeikemen/lsp-zero.nvim', - branch = 'v2.x', - dependencies = { - -- LSP Support - {'neovim/nvim-lspconfig'}, -- Required - {'williamboman/mason.nvim'}, -- Optional - {'williamboman/mason-lspconfig.nvim'}, -- Optional - - -- Autocompletion - -- TODO: move dependencies - {'hrsh7th/nvim-cmp'}, -- Required - {'hrsh7th/cmp-nvim-lsp'}, -- Required - {'L3MON4D3/LuaSnip'}, -- Required - } -} diff --git a/nvim/lua/plugins/nvim-cmp.lua b/nvim/lua/plugins/nvim-cmp.lua index ac588f6..3f13d1f 100644 --- a/nvim/lua/plugins/nvim-cmp.lua +++ b/nvim/lua/plugins/nvim-cmp.lua @@ -1,288 +1,202 @@ --- modified from https://github.com/VonHeikemen/dotfiles +local icons = { + Text = "", + Method = "󰆧", + Function = "󰊕", + Constructor = "", + Field = "󰇽", + Variable = "󰂡", + Class = "󰠱", + Interface = "", + Module = "", + Property = "󰜢", + Unit = "", + Value = "󰎠", + Enum = "", + Keyword = "󰌋", + Snippet = "", + Color = "󰏘", + File = "󰈙", + Reference = "", + Folder = "󰉋", + EnumMember = "", + Constant = "󰏿", + Struct = "", + Event = "", + Operator = "󰆕", + TypeParameter = "󰅲", +} -local Plugins = {} +local luasnip = { + "L3MON4D3/LuaSnip", + version = "v2.*", + build = "make install_jsregexp", + keys = { + { + '', + function() + local ls = require('luasnip') + if ls.expand_or_jumpable() then + ls.expand_or_jump() + end + end, + mode = { 'i', 's' }, + desc = 'Previous snippet jump' + }, + { + '', + function() + local ls = require('luasnip') + if ls.jumpable(-1) then + ls.jump(-1) + end + end, + mode = { 'i', 's' }, + desc = 'Next snippet jump' + } + }, + lazy = true +} --- FIXME: plugin not loading correctly +local cmp_path = { + 'hrsh7th/cmp-path', + event = 'InsertEnter' +} --- Autocompletion -local cmp_plugin = { - 'hrsh7th/nvim-cmp', - event = 'InsertEnter', - dependencies = { - -- Sources - 'hrsh7th/cmp-buffer', - 'hrsh7th/cmp-path', - 'saadparwaiz1/cmp_luasnip', - 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-nvim-lua', +local cmp_luasnip = { + 'saadparwaiz1/cmp_luasnip', + dependencies = { "L3MON4D3/LuaSnip" }, + event = 'InsertEnter' +} - -- Snippets - {'L3MON4D3/LuaSnip'}, +local cmp_lua = { + 'hrsh7th/cmp-nvim-lua', + ft = { + "lua", "vim" } } -local user = {autocomplete = true} - -table.insert(Plugins, cmp_plugin) - -table.insert(Plugins, { - 'aspeddro/cmp-pandoc.nvim', - enabled = true, - -- event = 'InsertEnter', - ft = {'markdown', 'pandoc', 'rmd'}, - dependencies = { - 'nvim-lua/plenary.nvim', - 'jbyuki/nabla.nvim' - }, - opts = { - crossref = { - enable_nabla = true - } - } -}) - -cmp_plugin.config = function() - user.augroup = vim.api.nvim_create_augroup('compe_cmds', {clear = true}) - vim.api.nvim_create_user_command('UserCmpEnable', user.enable_cmd, {}) - - local cmp = require('cmp') - local luasnip = require('luasnip') - - local select_opts = {behavior = cmp.SelectBehavior.Select} - local cmp_enable = cmp.get_config().enabled - - user.config = { - enabled = function() - if user.autocomplete then - return cmp_enable() - end - - return false - end, - completion = { - completeopt = 'menu,menuone', - }, - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - sources = { - { name = 'path'}, - { name = 'nvim_lsp'}, - { name = 'buffer', keyword_length = 4}, - { name = 'luasnip'}, - { name = 'cmp_pandoc' }, - { name = 'emoji' }, - }, - window = { - documentation = { - border = 'rounded', - max_height = 15, - max_width = 50, - zindex = 50, - } +local cmp_pandoc = { + 'aspeddro/cmp-pandoc.nvim', + -- FIXME: weird issues when using bibliographies + enabled = false, + dependencies = { + 'nvim-lua/plenary.nvim', }, - formatting = { - fields = {'menu', 'abbr', 'kind'}, - format = function(entry, item) - local menu = { - nvim_lsp = '[LSP]', - luasnip = '[Snip]', - buffer = '[Buffer]', - path = '[Path]', - nvim_lua = '[Lua]', - cmp_pandoc = '[Pandoc]', - emoiji = '[Emoji]' + -- ft = { 'pandoc', 'markdown', 'rmd' } + opts = { + bibliography = { + documentation = true, + }, + crossref = { + documentation = true, + enable_nabla = false } - - item.menu = menu[entry.source.name] - return item - end, - }, - mapping = { - [''] = cmp.mapping.scroll_docs(-5), - [''] = cmp.mapping.scroll_docs(5), - - [''] = cmp.mapping.select_prev_item(select_opts), - [''] = cmp.mapping.select_next_item(select_opts), - - -- TODO: test - -- [''] = cmp.mapping.select_prev_item(select_opts), - -- [''] = cmp.mapping.select_next_item(select_opts), - - [''] = cmp.mapping(function(fallback) - if luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, {'i', 's'}), - - [''] = cmp.mapping(function(fallback) - if luasnip.jumpable(1) then - luasnip.jump(1) - else - fallback() - end - end, {'i', 's'}), - - [''] = cmp.mapping(function() - if cmp.visible() then - user.set_autocomplete(false) - cmp.abort() - else - user.set_autocomplete(true) - cmp.complete() - end - end), - - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.confirm({select = true}) - elseif luasnip.jumpable(1) then - luasnip.jump(1) - elseif user.check_back_space() then - fallback() - else - user.set_autocomplete(true) - cmp.complete() - end - end, {'i', 's'}), - - [''] = cmp.mapping(function() - if luasnip.jumpable(-1) then - luasnip.jump(-1) - else - user.insert_tab() - end - end, {'i', 's'}), } - } - - cmp.setup(user.config) -end - -function user.set_autocomplete(new_value) - local old_value = user.autocomplete - - if new_value == old_value then - return - end - - if new_value == false then - -- restore autocomplete in the next word - vim.api.nvim_buf_set_keymap( - 0, - 'i', - '', - 'UserCmpEnable', - {noremap = true} - ) - - -- restore when leaving insert mode - vim.api.nvim_create_autocmd('InsertLeave', { - group = user.augroup, - command = 'UserCmpEnable', - once = true, - }) - end - - user.autocomplete = new_value -end - - -function user.check_back_space() - local col = vim.fn.col('.') - 1 - if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then - return true - else - return false - end -end - -function user.enable_cmd() - if user.autocomplete then - return - end +} - pcall(vim.api.nvim_buf_del_keymap, 0, 'i', '') - user.set_autocomplete(true) -end +local cmp_lsp = { + -- TODO: lazy load on lsp load + 'hrsh7th/cmp-nvim-lsp', + event = 'LspAttach', + dependencies = { + 'neovim/nvim-lspconfig' + }, +} -function user.insert_tab() - vim.api.nvim_feedkeys( - vim.api.nvim_replace_termcodes('', true, true, true), - 'n', - true - ) -end +local cmp_buffer = { + 'hrsh7th/cmp-buffer', + event = 'BufEnter' +} --- return Plugins +local cmp = { + 'hrsh7th/nvim-cmp', + config = function() + local cmp = require('cmp') + cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path', keyword_length = 2 }, + { name = 'buffer', keyword_length = 4 }, + }, + window = { + -- completion = cmp.config.window.bordered(), + -- documentation = cmp.config.window.bordered() + }, + formatting = { + -- fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + -- item.kind = string.format('%s %s', icons[item.kind], item.kind) + item.kind = icons[item.kind] .. ' ' .. item.kind + local menu = { + nvim_lsp = '[LSP]', + luasnip = '[Snip]', + buffer = '[Buffer]', + path = '[Path] foo', + nvim_lua = '[Lua]', + cmp_pandoc = '[Pandoc]', + emoiji = '[Emoji]', + } + menu['vim-dadbod-completion'] = '[dadbod]' + item.menu = menu[entry.source.name] + return item + end + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-5), + [''] = cmp.mapping.scroll_docs(5), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.confirm({ select = true }) + else + fallback() + end + end, { 'i', 's' }) + }) + }) + cmp.setup.filetype({ 'pandoc', 'markdown', 'rmd' }, { + sources = { + { name = 'luasnip' }, + { name = 'path', keyword_length = 3 }, + { name = 'buffer' }, + { name = 'emoji' }, + -- { name = 'cmp_pandoc' }, + } + }) + cmp.setup.filetype({ "lua", "vim" }, { + sources = { + { name = 'luasnip' }, + { name = 'nvim_lsp' }, + { name = 'nvim_lua' }, + { name = 'luansip' }, + { name = 'buffer' }, + { name = 'path' } + } + }) + cmp.setup.filetype({ "sql" }, { + sources = { + { name = 'vim-dadbod-completion' }, + { name = 'buffer' } + } + }) + end +} return { - { - "L3MON4D3/LuaSnip", - version = "v2.*", - build = "make install_jsregexp" - }, + luasnip, -- completion sources - { - 'hrsh7th/cmp-path', - }, - { - 'saadparwaiz1/cmp_luasnip' - }, - { -- TODO: lazy load on filtetype - 'hrsh7th/cmp-nvim-lua' - }, - { - -- TODO: lazy load on lsp load - 'hrsh7th/cmp-nvim-lsp', - dependencies= { - 'neovim/nvim-lspconfig' - }, - }, - { - 'hrsh7th/cmp-buffer', - }, - { - 'hrsh7th/nvim-cmp', - config = function() - local cmp = require('cmp') - cmp.setup({ - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end - }, - sources = { - { name = 'nvim_lsp'}, - { name = 'luasnip'}, - { name = 'path' }, - { name = 'nvim_lua' }, - { name = 'buffer', keyword_length = 4 }, - { name = 'emoji' } - }, - window = { - -- TODO: style cmp windows - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered() - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-5), - [''] = cmp.mapping.scroll_docs(5), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.confirm({select = true }) - else - fallback() - end - end, {'i', 's'}) - }) - }) - end - }, + cmp_path, + cmp_luasnip, + cmp_lua, + cmp_lsp, + cmp_buffer, + -- cmp_pandoc, + cmp, -- { -- 'kdheepak/cmp-latex-symbols', diff --git a/nvim/lua/plugins/oil.lua b/nvim/lua/plugins/oil.lua index 40a485e..20ce22f 100644 --- a/nvim/lua/plugins/oil.lua +++ b/nvim/lua/plugins/oil.lua @@ -5,7 +5,13 @@ return { keys = { { "ef", function() - vim.cmd('topleft vsplit +Oil') + local filetype = vim.o.ft + if filetype == "oil" then + vim.cmd('q') + else + vim.cmd('topleft vsplit +Oil') + end + -- TODO: check for other open oil instances end, desc = "Open Oil file explorer in a far left split, similar to :Lexplore" } }, diff --git a/nvim/lua/plugins/sql.lua b/nvim/lua/plugins/sql.lua new file mode 100644 index 0000000..253aed4 --- /dev/null +++ b/nvim/lua/plugins/sql.lua @@ -0,0 +1,28 @@ +local dadbod = { + "tpope/vim-dadbod", + lazy = true +} +local dadbod_completions = { + 'kristijanhusak/vim-dadbod-completion', + ft = { 'sql', 'mysql', 'plsql' }, + lazy = true +} +local dadbod_ui = { + 'kristijanhusak/vim-dadbod-ui', + dependencies = { + dadbod, + dadbod_completions + }, + cmd = { + 'DBUI', + 'DBUIToggle', + 'DBUIAddConnection', + 'DBUIFindBuffer', + }, + init = function() + vim.g.db_ui_use_nerd_fonts = 1 + end, +} +return { + dadbod_ui, +} diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua index a11664c..2e925c3 100644 --- a/nvim/lua/plugins/telescope.lua +++ b/nvim/lua/plugins/telescope.lua @@ -14,7 +14,7 @@ return { require("telescope.builtin").buffers() end }, - {"gf", function() + {"fg", function() require("telescope.builtin").live_grep() end }, -- cgit v1.2.3