feat: Luasnip working with blink.cmp

This commit is contained in:
2024-12-21 20:10:28 -05:00
parent 25ddde6e12
commit 44f5c35d38
5 changed files with 61 additions and 65 deletions

View File

@@ -1,58 +1,54 @@
-- https://cmp.saghen.dev/
return { return {
{ {
"saghen/blink.cmp", "saghen/blink.cmp",
enabled = false, enabled = true,
dependencies = { dependencies = {
"rafamadriz/friendly-snippets", -- "rafamadriz/friendly-snippets",
--"L3MON4D3/LuaSnip", { "L3MON4D3/LuaSnip", version = "v2.*" },
}, },
version = "v0.*", version = "v0.*",
opts = { opts = {
appearance = { signature = { enabled = true },
use_nvim_cmp_as_default = true, sources = {
nerd_font_variant = "mono", default = { "lsp", "path", "snippets", "buffer", "luasnip" },
}, providers = {
signature = { enabled = true }, lsp = {
keymap = { name = "lsp",
preset = "default", enabled = true,
["<CR>"] = { "accept", "fallback" }, module = "blink.cmp.sources.lsp",
["<C-space>"] = { score_offset = 1000, -- higher = higher priority
function(cmp) },
cmp.show({ providers = { "snippets" } }) luasnip = {
end, name = "luasnip",
}, enabled = true,
--["<C-k>"] = { "select_prev", "fallback" }, module = "blink.cmp.sources.luasnip",
--["<C-j>"] = { "select_next", "fallback" }, score_offset = 950,
["<C-n>"] = { },
function(cmp) snippets = {
if cmp.snippet_active() then name = "snippets",
return cmp.accept() enabled = true,
else module = "blink.cmp.sources.snippets",
return cmp.select_and_accept() score_offset = 900,
end },
end, },
"snippet_forward", },
"fallback", snippets = {
}, expand = function(snippet)
}, require("luasnip").lsp_expand(snippet)
-- snippets = { end,
-- expand = function(snippet) active = function(filter)
-- require("luasnip").lsp_expand(snippet) if filter and filter.direction then
-- end, return require("luasnip").jumpable(filter.direction)
-- active = function(filter) end
-- if filter and filter.direction then return require("luasnip").in_snippet()
-- return require("luasnip").jumpable(filter.direction) end,
-- end jump = function(direction)
-- return require("luasnip").in_snippet() require("luasnip").jump(direction)
-- end, end,
-- jump = function(direction) },
-- require("luasnip").jump(direction) },
-- end, opts_extend = { "sources.default" },
-- }, keymap = { preset = "default" },
sources = { },
default = { "lsp", "path", "snippets", "buffer" },
},
},
opts_extend = { "sources.default" },
},
} }

View File

@@ -1,6 +1,6 @@
return { return {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
enabled = true, enabled = false,
event = "VeryLazy", event = "VeryLazy",
dependencies = { dependencies = {
"hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-nvim-lsp",

View File

@@ -3,8 +3,8 @@ return {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" }, event = { "BufReadPre", "BufNewFile" },
dependencies = { dependencies = {
"hrsh7th/cmp-nvim-lsp", -- "hrsh7th/cmp-nvim-lsp",
--"saghen/blink.cmp", "saghen/blink.cmp",
{ "antosha417/nvim-lsp-file-operations", config = true }, { "antosha417/nvim-lsp-file-operations", config = true },
"williamboman/mason.nvim", "williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim", "williamboman/mason-lspconfig.nvim",
@@ -37,9 +37,9 @@ return {
automatic_installation = true, automatic_installation = true,
}) })
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
local cmp_nvim_lsp = require("cmp_nvim_lsp") -- local cmp_nvim_lsp = require("cmp_nvim_lsp")
local capabilities = cmp_nvim_lsp.default_capabilities() -- local capabilities = cmp_nvim_lsp.default_capabilities()
--local capabilities = require("blink.cmp").get_lsp_capabilities() local capabilities = require("blink.cmp").get_lsp_capabilities()
local opts = { noremap = true, silent = true } local opts = { noremap = true, silent = true }
local on_attach = function(_, bufnr) local on_attach = function(_, bufnr)
opts.buffer = bufnr opts.buffer = bufnr

View File

@@ -24,7 +24,7 @@ return {
end, end,
}, },
}, },
config = function(_, opts) config = function()
local ls = require("luasnip") local ls = require("luasnip")
ls.setup({ ls.setup({
history = true, history = true,

View File

@@ -12,12 +12,12 @@ local rep = require("luasnip.extras").rep
-- Add snippets -- Add snippets
ls.add_snippets("swift", { ls.add_snippets("swift", {
-- Add a dependency snippet. -- Add a dependency snippet.
s({ trig = "@d", desc = "Add a dependency." }, fmt("@Dependency(\\.{}) var {}", { i(1), rep(1) })), s({ trig = "@Dep", desc = "Add a dependency." }, fmt("@Dependency(\\.{}) var {}", { i(1), rep(1) })),
-- Add a dependency client. -- Add a dependency client.
s( s(
{ {
trig = "@dc", trig = "@DC",
desc = "Add a dependency client.", desc = "Add a dependency client.",
}, },
fmt( fmt(