feat: move to blink.cmp from cmp
This commit is contained in:
@@ -59,7 +59,7 @@ end
|
||||
|
||||
-- used to enable autocompletion (assign to every lsp server config)
|
||||
-- local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||
M.capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
M.capabilities = require("blink.cmp").get_lsp_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||
M.capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
return {
|
||||
-- competion
|
||||
"hrsh7th/nvim-cmp",
|
||||
event = { "InsertEnter", "LspAttach" },
|
||||
dependencies = {
|
||||
{ "hrsh7th/cmp-buffer" }, -- source for text in buffer
|
||||
{ "hrsh7th/cmp-path" }, -- source for file system paths
|
||||
{ "L3MON4D3/LuaSnip" }, -- snippet engine
|
||||
{ "saadparwaiz1/cmp_luasnip" }, -- for autocompletion
|
||||
{ "rafamadriz/friendly-snippets" }, -- useful snippets
|
||||
{ "onsails/lspkind.nvim" }, -- icons for cmp
|
||||
},
|
||||
config = function()
|
||||
local cmp = require("cmp")
|
||||
local lspkind = require("lspkind")
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
require("luasnip.loaders.from_vscode").load({ paths = { "~/.config/nvim/snippets" } })
|
||||
luasnip.setup({})
|
||||
|
||||
-- luasnip.filetype_extend("htmldjango", { "html" })
|
||||
|
||||
cmp.setup({
|
||||
completion = {
|
||||
completeopt = "menu,menuone,preview,noselect",
|
||||
},
|
||||
|
||||
window = {
|
||||
documentation = cmp.config.window.bordered({
|
||||
border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
|
||||
}),
|
||||
completion = cmp.config.window.bordered({
|
||||
border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
|
||||
winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None",
|
||||
}),
|
||||
},
|
||||
|
||||
snippet = { -- configure how nvim-cmp interacts with snippet engine
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.ConfirmBehavior.Select }), -- next suggestion
|
||||
["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.ConfirmBehavior.Select }), -- prev suggestion
|
||||
["<C-S-J>"] = cmp.mapping.scroll_docs(4, { behavior = cmp.ConfirmBehavior.Select }), -- docs forward
|
||||
["<C-S-K>"] = cmp.mapping.scroll_docs(-4, { behavior = cmp.ConfirmBehavior.Select }), -- docs back
|
||||
["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions
|
||||
["<C-q>"] = cmp.mapping.abort(), -- close completion window
|
||||
["<CR>"] = cmp.mapping.confirm({ select = false }), -- autocomplete if selected
|
||||
-- Mapping for Tab key
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true })
|
||||
else
|
||||
-- Otherwise, fallback (insert a tab character)
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
|
||||
-- Mapping for jumping in snippets
|
||||
["<C-p>"] = cmp.mapping(function(fallback)
|
||||
if require("luasnip").jumpable() then
|
||||
-- Jump backwards if inside a snippet
|
||||
require("luasnip").jump()
|
||||
else
|
||||
-- Otherwise, fallback (insert a tab character)
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
|
||||
-- Mapping for jumping backwards in snippets
|
||||
["<C-S-p>"] = cmp.mapping(function(fallback)
|
||||
if require("luasnip").jumpable() then
|
||||
-- Jump backwards if inside a snippet
|
||||
require("luasnip").jump()
|
||||
else
|
||||
-- Otherwise, fallback (insert a tab character)
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
}),
|
||||
|
||||
-- sources for autocompletion
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" }, -- lsp
|
||||
{ name = "luasnip" }, -- snippets
|
||||
{ name = "buffer" }, -- text within current buffer
|
||||
{ name = "path" }, -- file system paths
|
||||
}),
|
||||
|
||||
formatting = {
|
||||
fields = { "icon", "abbr", "menu" },
|
||||
format = lspkind.cmp_format({
|
||||
mode = "symbol", -- 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)
|
||||
-- can also be a function to dynamically calculate max width such as
|
||||
-- maxwidth = function() return math.floor(0.45 * vim.o.columns) end,
|
||||
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,
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
local opts = { silent = true }
|
||||
opts.desc = "next snippet placeholder"
|
||||
vim.keymap.set({ "i", "s" }, "<C-,>", function()
|
||||
luasnip.jump(1)
|
||||
end, opts)
|
||||
|
||||
opts.desc = "previous snippet placeholder"
|
||||
vim.keymap.set({ "i", "s" }, "<C-.>", function()
|
||||
luasnip.jump(-1)
|
||||
end, opts)
|
||||
|
||||
opts.desc = "LuaSnip unlink"
|
||||
vim.keymap.set({ "i", "n" }, "<C-s>", function()
|
||||
luasnip.unlink_current()
|
||||
end, opts)
|
||||
end,
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
return {
|
||||
"saghen/blink.cmp",
|
||||
-- optional: provides snippets for the snippet source
|
||||
dependencies = { "rafamadriz/friendly-snippets", "L3MON4D3/LuaSnip" },
|
||||
|
||||
-- use a release tag to download pre-built binaries
|
||||
version = "1.*",
|
||||
|
||||
---@module 'blink.cmp'
|
||||
---@type blink.cmp.Config
|
||||
opts = {
|
||||
-- 'default' (recommended) for mappings similar to built-in completions (C-y to accept)
|
||||
-- 'super-tab' for mappings similar to vscode (tab to accept)
|
||||
-- 'enter' for enter to accept
|
||||
-- 'none' for no mappings
|
||||
--
|
||||
-- All presets have the following mappings:
|
||||
-- C-space: Open menu or open docs if already open
|
||||
-- C-n/C-p or Up/Down: Select next/previous item
|
||||
-- C-e: Hide menu
|
||||
-- C-k: Toggle signature help (if signature.enabled = true)
|
||||
--
|
||||
-- See :h blink-cmp-config-keymap for defining your own keymap
|
||||
keymap = {
|
||||
preset = "super-tab",
|
||||
["<C-k>"] = { "select_prev", "fallback" },
|
||||
["<C-j>"] = { "select_next", "fallback" },
|
||||
["<C-n>"] = { "show_documentation", "hide_documentation" },
|
||||
["<C-S-j>"] = { "scroll_documentation_down", "scroll_signature_down" },
|
||||
["<C-S-k>"] = { "scroll_documentation_up", "scroll_signature_up" },
|
||||
["<C-,>"] = { "snippet_backward", "fallback" },
|
||||
["<C-.>"] = { "snippet_forward", "fallback" },
|
||||
["<C-s>"] = { "show_signature", "hide_signature", "fallback" },
|
||||
},
|
||||
|
||||
appearance = {
|
||||
-- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
|
||||
-- Adjusts spacing to ensure icons are aligned
|
||||
nerd_font_variant = "mono",
|
||||
},
|
||||
|
||||
-- (Default) Only show the documentation popup when manually triggered
|
||||
completion = {
|
||||
documentation = { auto_show = false },
|
||||
list = {
|
||||
cycle = { from_top = true, from_bottom = true },
|
||||
selection = {
|
||||
auto_insert = false
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
-- Default list of enabled providers defined so that you can extend it
|
||||
-- elsewhere in your config, without redefining it, due to `opts_extend`
|
||||
sources = {
|
||||
default = { "lsp", "path", "snippets", "buffer" },
|
||||
},
|
||||
|
||||
-- (Default) Rust fuzzy matcher for typo resistance and significantly better performance
|
||||
-- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation,
|
||||
-- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"`
|
||||
--
|
||||
-- See the fuzzy documentation for more information
|
||||
fuzzy = { implementation = "prefer_rust_with_warning" },
|
||||
},
|
||||
opts_extend = { "sources.default" },
|
||||
}
|
||||
@@ -6,7 +6,6 @@ return {
|
||||
-- lsp configuration
|
||||
"neovim/nvim-lspconfig",
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
{ "antosha417/nvim-lsp-file-operations", config = true },
|
||||
"mfussenegger/nvim-jdtls",
|
||||
},
|
||||
@@ -18,6 +17,13 @@ return {
|
||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
|
||||
end
|
||||
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
require("luasnip.loaders.from_vscode").load({ paths = { "~/.config/nvim/snippets" } })
|
||||
luasnip.setup({})
|
||||
|
||||
-- ───────────────────────────────────────────────────────────────────
|
||||
-- ╭───────────────────────────────────────────────╮
|
||||
-- │ Import configs from other files │
|
||||
|
||||
@@ -15,11 +15,9 @@ return {
|
||||
})
|
||||
require("noice").setup({
|
||||
lsp = {
|
||||
-- override markdown rendering so that **cmp** and other plugins use **Treesitter**
|
||||
override = {
|
||||
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
|
||||
["vim.lsp.util.stylize_markdown"] = true,
|
||||
["cmp.entry.get_documentation"] = true, -- requires hrsh7th/nvim-cmp
|
||||
},
|
||||
progress = {
|
||||
format = "lsp_progress",
|
||||
|
||||
Reference in New Issue
Block a user