From d8728b56e8a967f70f9a85a6724a62f63fcc2253 Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Fri, 8 Nov 2024 15:08:53 +0100 Subject: [PATCH] try blink.nvim instead of nvim-cmp --- lua/plugins/cmp.lua | 144 ++++++++++++++------------------------- lua/plugins/copilot.lua | 12 ++-- lua/plugins/lsp.lua | 32 +++++---- lua/plugins/snippets.lua | 9 +++ 4 files changed, 85 insertions(+), 112 deletions(-) create mode 100644 lua/plugins/snippets.lua diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index 337f125..64e3216 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -1,101 +1,61 @@ return { { - 'hrsh7th/nvim-cmp', - lazy = false, - priority = 100, - dependencies = { - 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-path', - 'hrsh7th/cmp-buffer', - { 'L3MON4D3/LuaSnip', build = 'make install_jsregexp' }, - 'saadparwaiz1/cmp_luasnip', - 'rafamadriz/friendly-snippets', - 'zbirenbaum/copilot-cmp', - 'onsails/lspkind.nvim', + 'saghen/blink.cmp', + lazy = false, -- lazy loading handled internally + -- optional: provides snippets for the snippet source + dependencies = 'rafamadriz/friendly-snippets', + + -- use a release tag to download pre-built binaries + version = 'v0.*', + -- OR build from source, requires nightly: https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust + -- build = 'cargo build --release', + -- If you use nix, you can build from source using latest nightly rust with: + -- build = 'nix run .#build-plugin', + + ---@module 'blink.cmp' + ---@type blink.cmp.Config + opts = { + -- 'default' for mappings similar to built-in completion + -- 'super-tab' for mappings similar to vscode (tab to accept, arrow keys to navigate) + -- 'enter' for mappings similar to 'super-tab' but with 'enter' to accept + -- see the "default configuration" section below for full documentation on how to define + -- your own keymap. + keymap = { preset = 'default' }, + + highlight = { + -- sets the fallback highlight groups to nvim-cmp's highlight groups + -- useful for when your theme doesn't support blink.cmp + -- will be removed in a future release, assuming themes add support + use_nvim_cmp_as_default = true, + }, + -- set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- adjusts spacing to ensure icons are aligned + nerd_font_variant = 'mono', + + -- experimental auto-brackets support + -- accept = { auto_brackets = { enabled = true } } + + -- experimental signature help support + -- trigger = { signature_help = { enabled = true } } }, - config = function() - vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } - vim.opt.shortmess:append 'c' + }, - local cmp = require 'cmp' - local lspkind = require 'lspkind' + -- LSP servers and clients communicate what features they support through "capabilities". + -- By default, Neovim support a subset of the LSP specification. + -- With blink.cmp, Neovim has *more* capabilities which are communicated to the LSP servers. + -- Explanation from TJ: https://youtu.be/m8C0Cq9Uv9o?t=1275 + -- + -- This can vary by config, but in-general for nvim-lspconfig: - cmp.setup { - sources = { - { name = 'copilot' }, - { name = 'luasnip' }, - { name = 'nvim_lsp' }, - { name = 'path' }, - { name = 'buffer' }, - }, - mapping = { - [''] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert }, - [''] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert }, - [''] = cmp.mapping( - cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Insert, - select = true, - }, - { 'i', 'c' } - ), - }, - - -- Enable luasnip to handle snippet expansion for nvim-cmp - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end, - }, - - formatting = { - expandable_indicator = true, - fields = { 'abbr', 'kind' }, - format = lspkind.cmp_format { - mode = 'symbol_text', -- show only symbol annotations - maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) - ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first) - show_labelDetails = true, -- show labelDetails in menu. Disabled by default - - -- The function below will be called before any actual modifications from lspkind - -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30)) - -- before = function(entry, vim_item) - -- return vim_item - -- end, - }, - }, - } - - -- Setup up vim-dadbod - cmp.setup.filetype({ 'sql' }, { - sources = { - { name = 'vim-dadbod-completion' }, - { name = 'buffer' }, - }, - }) - - local ls = require 'luasnip' - ls.config.set_config { - history = false, - updateevents = 'TextChanged,TextChangedI', - } - - for _, ft_path in ipairs(vim.api.nvim_get_runtime_file('lua/custom/snippets/*.lua', true)) do - loadfile(ft_path)() + { + 'neovim/nvim-lspconfig', + dependencies = { 'saghen/blink.cmp' }, + config = function(_, opts) + local lspconfig = require 'lspconfig' + for server, config in pairs(opts.servers or {}) do + config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities) + lspconfig[server].setup(config) end - - vim.keymap.set({ 'i', 's' }, '', function() - if ls.expand_or_jumpable() then - ls.expand_or_jump() - end - end, { silent = true }) - - vim.keymap.set({ 'i', 's' }, '', function() - if ls.jumpable(-1) then - ls.jump(-1) - end - end, { silent = true }) - - require('luasnip/loaders/from_vscode').lazy_load() end, }, } diff --git a/lua/plugins/copilot.lua b/lua/plugins/copilot.lua index 81bb3eb..31cee93 100644 --- a/lua/plugins/copilot.lua +++ b/lua/plugins/copilot.lua @@ -8,10 +8,10 @@ return { panel = { enabled = false }, }, }, - { - 'zbirenbaum/copilot-cmp', - config = function() - require('copilot_cmp').setup() - end, - }, + -- { + -- 'zbirenbaum/copilot-cmp', + -- config = function() + -- require('copilot_cmp').setup() + -- end, + -- }, } diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 307398b..c9fa58b 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -14,23 +14,25 @@ return { -- Schema information 'b0o/SchemaStore.nvim', + + -- cmp + 'saghen/blink.cmp', }, - config = function() - local util = require 'lspconfig.util' - - require('neodev').setup { - -- library = { - -- plugins = { "nvim-dap-ui" }, - -- types = true, - -- }, - } - - local capabilities = nil - if pcall(require, 'cmp_nvim_lsp') then - capabilities = require('cmp_nvim_lsp').default_capabilities() + config = function(_, opts) + -- require('neodev').setup { + -- library = { + -- plugins = { "nvim-dap-ui" }, + -- types = true, + -- }, + -- } + -- + local lspconfig = require 'lspconfig' + for server, config in pairs(opts.servers or {}) do + config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities) + lspconfig[server].setup(config) end - local lspconfig = require 'lspconfig' + local util = require 'lspconfig.util' local servers = { bashls = true, @@ -39,6 +41,8 @@ return { svelte = true, templ = true, cssls = true, + eslint = true, + ast_grep = true, ts_ls = { root_dir = function(fname) diff --git a/lua/plugins/snippets.lua b/lua/plugins/snippets.lua new file mode 100644 index 0000000..3513d70 --- /dev/null +++ b/lua/plugins/snippets.lua @@ -0,0 +1,9 @@ +return { + 'L3MON4D3/LuaSnip', + version = 'v2.*', + run = 'make install_jsregexp', + dependencies = { 'rafamadriz/friendly-snippets' }, + init = function() + require('luasnip.loaders.from_vscode').lazy_load() + end, +}