diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index ae85073..93f1c1d 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -1,19 +1,24 @@ { "LuaSnip": { "branch": "master", "commit": "f3b3d3446bcbfa62d638b1903ff00a78b2b730a1" }, "catppuccin": { "branch": "main", "commit": "c0de3b46811fe1ce3912e2245a9dfbea6b41c300" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" }, "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, - "copilot.vim": { "branch": "release", "commit": "8f24a74d5937c1fb28fbce5caf05ffc633093fc5" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "copilot.vim": { "branch": "release", "commit": "69455be5d4a892206bc08365ba3648a597485943" }, + "fidget.nvim": { "branch": "main", "commit": "4e854f3299e21d1c18279add340428a97520fc44" }, "harpoon": { "branch": "master", "commit": "ccae1b9bec717ae284906b0bf83d720e59d12b91" }, "lazy.nvim": { "branch": "main", "commit": "aedcd79811d491b60d0a6577a9c1701063c2a609" }, - "lsp-zero.nvim": { "branch": "v3.x", "commit": "009ace7a0ca360d9299ff7eb33364b5c16556561" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "21d33d69a81f6351e5a5f49078b2e4f0075c8e73" }, "mason.nvim": { "branch": "main", "commit": "3b5068f0fc565f337d67a2d315d935f574848ee7" }, - "neoconf.nvim": { "branch": "main", "commit": "faab415b0ba57f0a15a82210f346f662e6551e1a" }, + "neoconf.nvim": { "branch": "main", "commit": "98980b5300e7a5e7f93e8dbf81c98cc3daa55df7" }, "nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" }, "nvim-lspconfig": { "branch": "master", "commit": "b1a11b042d015df5b8f7f33aa026e501b639c649" }, "nvim-treesitter": { "branch": "master", "commit": "db12bd416e2764420047e4a5d6b96fe44e4377d5" }, "plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" }, "telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" }, + "trouble.nvim": { "branch": "main", "commit": "f1168feada93c0154ede4d1fe9183bf69bac54ea" }, "undotree": { "branch": "master", "commit": "9dbbf3b7d19dda0d22ceca461818e4739ad8154d" }, "vim-fugitive": { "branch": "master", "commit": "2e88f14a585c014691904ba8fe39e6ea851c9422" }, "vim-tmux-navigator": { "branch": "master", "commit": "38b1d0402c4600543281dc85b3f51884205674b6" }, diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua index e430aee..25704f5 100644 --- a/.config/nvim/lua/plugins/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -1,39 +1,114 @@ return { - { - 'VonHeikemen/lsp-zero.nvim', - branch = 'v3.x', - lazy = true, - config = false, - init = function() - -- Disable automatic setup, we are doing it manually - vim.g.lsp_zero_extend_cmp = 0 - vim.g.lsp_zero_extend_lspconfig = 0 - end, - }, - { - 'williamboman/mason.nvim', - lazy = false, - config = true, - }, - - -- Autocompletion - { - 'hrsh7th/nvim-cmp', - event = 'InsertEnter', + { 'neovim/nvim-lspconfig', dependencies = { - {'L3MON4D3/LuaSnip'}, + 'williamboman/mason.nvim', + 'williamboman/mason-lspconfig.nvim', + 'folke/neoconf.nvim', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-cmdline', + 'hrsh7th/nvim-cmp', + 'L3MON4D3/LuaSnip', + 'saadparwaiz1/cmp_luasnip', + { 'j-hui/fidget.nvim', tag = 'v1.4.0' }, }, - config = function() - -- Here is where you configure the autocompletion settings. - local lsp_zero = require('lsp-zero') - lsp_zero.extend_cmp() - -- And you can configure cmp even more, if you want to. + config = function() local cmp = require('cmp') - local cmp_action = lsp_zero.cmp_action() + local cmp_lsp = require('cmp_nvim_lsp') + local capabilities = cmp_lsp.default_capabilities() + require('fidget').setup({}) + require('mason').setup() + require('mason-lspconfig').setup({ + ensure_installed = {'eslint', 'tsserver', 'rust_analyzer', 'lua_ls', 'clangd', 'volar', 'pylsp'}, + }) + + require("mason-lspconfig").setup_handlers { + -- The first entry (without a key) will be the default handler + -- and will be called for each installed server that doesn't have + -- a dedicated handler. + function (server_name) -- default handler (optional) + local server_config = { + capabilities = capabilities, + } + if require("neoconf").get(server_name .. ".disable") then -- disable servers with neoconfg + return + end + if server_name == "volar" then -- TODO: fix for tsserver should i keep this can i just uninstall tsserver and use only volar? + server_config.filetypes = { 'vue', 'typescript', 'javascript' } + end + require("lspconfig")[server_name].setup(server_config) + end, + + -- Next, you can provide a dedicated handler for specific servers. + -- For example, a handler override for the `rust_analyzer`: + -- ["rust_analyzer"] = function () + -- require("rust-tools").setup {} + -- end + + -- configure lua server to fix vim warning + ["lua_ls"] = function () + local lspconfig = require("lspconfig") + lspconfig.lua_ls.setup { + capabilities = capabilities, + settings = { + Lua = { + diagnostics = { + globals = { "vim" } + } + } + } + } + end, + } + -- end mason_lspconfig setup handlers + -- setup keymaps: + -- Global mappings. + -- See `:help vim.diagnostic.*` for documentation on any of the below functions + vim.keymap.set('n', 'e', vim.diagnostic.open_float) + vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) + vim.keymap.set('n', ']d', vim.diagnostic.goto_next) + vim.keymap.set('n', 'q', vim.diagnostic.setloclist) + + -- Use LspAttach autocommand to only map the following keys + -- after the language server attaches to the current buffer + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local opts = { buffer = ev.buf } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('i', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format { async = true } + end, opts) + end, + }) + + + local cmp_select_behavior = { behavior = cmp.SelectBehavior.Select } cmp.setup({ - formatting = lsp_zero.cmp_format(), + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + end, + }, mapping = cmp.mapping.preset.insert({ -- `Enter` key to confirm completion [''] = cmp.mapping.confirm({select = false}), @@ -42,70 +117,35 @@ return { [''] = cmp.mapping.complete(), -- Tab to change item in completion menu - [''] = cmp_action.tab_complete(), + [''] = cmp.mapping.select_next_item(cmp_select_behavior), -- Shift+Tab goes to the previus item in the completion menu - [''] = cmp_action.select_prev_or_fallback(), + [''] = cmp.mapping.select_prev_item(cmp_select_behavior), -- Navigate between documentation [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.scroll_docs(-4), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, -- For luasnip users. + }, + { + { name = 'buffer' }, }) }) - lsp_zero.set_preferences({ - sign_icons = {} - }) - end - }, - - -- LSP - { - 'neovim/nvim-lspconfig', - cmd = {'LspInfo', 'LspInstall', 'LspStart'}, - event = {'BufReadPre', 'BufNewFile'}, - dependencies = { - {'hrsh7th/cmp-nvim-lsp'}, - {'williamboman/mason-lspconfig.nvim'}, - }, - config = function() - -- This is where all the LSP shenanigans will live - local lsp_zero = require('lsp-zero') - lsp_zero.extend_lspconfig() - - --- if you want to know more about lsp-zero and mason.nvim - --- read this: https://github.com/VonHeikemen/lsp-zero.nvim/blob/v3.x/doc/md/guides/integrate-with-mason-nvim.md - lsp_zero.on_attach(function(client, bufnr) - -- see :help lsp-zero-keybindings - -- to learn the available actions - lsp_zero.default_keymaps({buffer = bufnr}) - end) - - require('mason-lspconfig').setup({ - ensure_installed = {'eslint', 'tsserver', 'rust_analyzer', 'lua_ls', - 'clangd', 'volar', 'pylsp'}, - handlers = { - lsp_zero.default_setup, - lua_ls = function() - -- (Optional) Configure lua language server for neovim - local lua_opts = lsp_zero.nvim_lua_ls() - require('lspconfig').lua_ls.setup(lua_opts) - end, - } - }) - - require('mason-lspconfig').setup_handlers({ - function(server_name) - local server_config = {} - if require("neoconf").get(server_name .. ".disable") then - return - end - if server_name == "volar" then - server_config.filetypes = { 'vue', 'typescript', 'javascript' } - end - require('lspconfig')[server_name].setup(server_config) - end, - }) + -- end cmp setup + vim.diagnostic.config({ + float = { + focusable = false, + style = 'minimal', + border = 'rounded', + source = 'always', + header = '', + prefix = '', + } + }) end } } diff --git a/.config/nvim/lua/plugins/trouble.lua b/.config/nvim/lua/plugins/trouble.lua new file mode 100644 index 0000000..60bb5fd --- /dev/null +++ b/.config/nvim/lua/plugins/trouble.lua @@ -0,0 +1,17 @@ +return { + "folke/trouble.nvim", + config = function () + require('trouble').setup({ icons = false }) + vim.keymap.set('n', 'tt', function () + require('trouble').toggle() + end) + + vim.keymap.set('n', '[t', function () + require('trouble').next({skip_groups = true, jump = true}) + end) + + vim.keymap.set('n', ']t', function () + require('trouble').previous({skip_groups = true, jump = true}) + end) + end, +}