try blink.nvim instead of nvim-cmp

This commit is contained in:
Thomas Ruoff
2024-11-08 15:08:53 +01:00
parent 0ab84b5e7a
commit d8728b56e8
4 changed files with 85 additions and 112 deletions

View File

@@ -1,101 +1,61 @@
return { return {
{ {
'hrsh7th/nvim-cmp', 'saghen/blink.cmp',
lazy = false, lazy = false, -- lazy loading handled internally
priority = 100, -- optional: provides snippets for the snippet source
dependencies = { dependencies = 'rafamadriz/friendly-snippets',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-path', -- use a release tag to download pre-built binaries
'hrsh7th/cmp-buffer', version = 'v0.*',
{ 'L3MON4D3/LuaSnip', build = 'make install_jsregexp' }, -- OR build from source, requires nightly: https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust
'saadparwaiz1/cmp_luasnip', -- build = 'cargo build --release',
'rafamadriz/friendly-snippets', -- If you use nix, you can build from source using latest nightly rust with:
'zbirenbaum/copilot-cmp', -- build = 'nix run .#build-plugin',
'onsails/lspkind.nvim',
---@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' -- LSP servers and clients communicate what features they support through "capabilities".
local lspkind = require 'lspkind' -- 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 = { 'neovim/nvim-lspconfig',
{ name = 'copilot' }, dependencies = { 'saghen/blink.cmp' },
{ name = 'luasnip' }, config = function(_, opts)
{ name = 'nvim_lsp' }, local lspconfig = require 'lspconfig'
{ name = 'path' }, for server, config in pairs(opts.servers or {}) do
{ name = 'buffer' }, config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities)
}, lspconfig[server].setup(config)
mapping = {
['<C-n>'] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
['<C-p>'] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
['<C-y>'] = 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)()
end end
vim.keymap.set({ 'i', 's' }, '<c-k>', function()
if ls.expand_or_jumpable() then
ls.expand_or_jump()
end
end, { silent = true })
vim.keymap.set({ 'i', 's' }, '<c-j>', function()
if ls.jumpable(-1) then
ls.jump(-1)
end
end, { silent = true })
require('luasnip/loaders/from_vscode').lazy_load()
end, end,
}, },
} }

View File

@@ -8,10 +8,10 @@ return {
panel = { enabled = false }, panel = { enabled = false },
}, },
}, },
{ -- {
'zbirenbaum/copilot-cmp', -- 'zbirenbaum/copilot-cmp',
config = function() -- config = function()
require('copilot_cmp').setup() -- require('copilot_cmp').setup()
end, -- end,
}, -- },
} }

View File

@@ -14,23 +14,25 @@ return {
-- Schema information -- Schema information
'b0o/SchemaStore.nvim', 'b0o/SchemaStore.nvim',
-- cmp
'saghen/blink.cmp',
}, },
config = function() config = function(_, opts)
local util = require 'lspconfig.util' -- require('neodev').setup {
-- library = {
require('neodev').setup { -- plugins = { "nvim-dap-ui" },
-- library = { -- types = true,
-- plugins = { "nvim-dap-ui" }, -- },
-- types = true, -- }
-- }, --
} local lspconfig = require 'lspconfig'
for server, config in pairs(opts.servers or {}) do
local capabilities = nil config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities)
if pcall(require, 'cmp_nvim_lsp') then lspconfig[server].setup(config)
capabilities = require('cmp_nvim_lsp').default_capabilities()
end end
local lspconfig = require 'lspconfig' local util = require 'lspconfig.util'
local servers = { local servers = {
bashls = true, bashls = true,
@@ -39,6 +41,8 @@ return {
svelte = true, svelte = true,
templ = true, templ = true,
cssls = true, cssls = true,
eslint = true,
ast_grep = true,
ts_ls = { ts_ls = {
root_dir = function(fname) root_dir = function(fname)

9
lua/plugins/snippets.lua Normal file
View File

@@ -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,
}