From 44f5c35d38f279233014f572966ec9264d517e8e Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Sat, 21 Dec 2024 20:10:28 -0500 Subject: [PATCH] feat: Luasnip working with blink.cmp --- nvim/m-housh/lua/plugins/blink.lua | 108 +++++++++++++-------------- nvim/m-housh/lua/plugins/cmp.lua | 2 +- nvim/m-housh/lua/plugins/lsp.lua | 10 +-- nvim/m-housh/lua/plugins/luasnip.lua | 2 +- nvim/m-housh/snippets/swift.lua | 4 +- 5 files changed, 61 insertions(+), 65 deletions(-) diff --git a/nvim/m-housh/lua/plugins/blink.lua b/nvim/m-housh/lua/plugins/blink.lua index 34940c0..27f24c0 100644 --- a/nvim/m-housh/lua/plugins/blink.lua +++ b/nvim/m-housh/lua/plugins/blink.lua @@ -1,58 +1,54 @@ +-- https://cmp.saghen.dev/ return { - { - "saghen/blink.cmp", - enabled = false, - dependencies = { - "rafamadriz/friendly-snippets", - --"L3MON4D3/LuaSnip", - }, - version = "v0.*", - opts = { - appearance = { - use_nvim_cmp_as_default = true, - nerd_font_variant = "mono", - }, - signature = { enabled = true }, - keymap = { - preset = "default", - [""] = { "accept", "fallback" }, - [""] = { - function(cmp) - cmp.show({ providers = { "snippets" } }) - end, - }, - --[""] = { "select_prev", "fallback" }, - --[""] = { "select_next", "fallback" }, - [""] = { - function(cmp) - if cmp.snippet_active() then - return cmp.accept() - else - return cmp.select_and_accept() - end - end, - "snippet_forward", - "fallback", - }, - }, - -- snippets = { - -- expand = function(snippet) - -- require("luasnip").lsp_expand(snippet) - -- end, - -- active = function(filter) - -- if filter and filter.direction then - -- return require("luasnip").jumpable(filter.direction) - -- end - -- return require("luasnip").in_snippet() - -- end, - -- jump = function(direction) - -- require("luasnip").jump(direction) - -- end, - -- }, - sources = { - default = { "lsp", "path", "snippets", "buffer" }, - }, - }, - opts_extend = { "sources.default" }, - }, + { + "saghen/blink.cmp", + enabled = true, + dependencies = { + -- "rafamadriz/friendly-snippets", + { "L3MON4D3/LuaSnip", version = "v2.*" }, + }, + version = "v0.*", + opts = { + signature = { enabled = true }, + sources = { + default = { "lsp", "path", "snippets", "buffer", "luasnip" }, + providers = { + lsp = { + name = "lsp", + enabled = true, + module = "blink.cmp.sources.lsp", + score_offset = 1000, -- higher = higher priority + }, + luasnip = { + name = "luasnip", + enabled = true, + module = "blink.cmp.sources.luasnip", + score_offset = 950, + }, + snippets = { + name = "snippets", + enabled = true, + module = "blink.cmp.sources.snippets", + score_offset = 900, + }, + }, + }, + snippets = { + expand = function(snippet) + require("luasnip").lsp_expand(snippet) + end, + active = function(filter) + if filter and filter.direction then + return require("luasnip").jumpable(filter.direction) + end + return require("luasnip").in_snippet() + end, + jump = function(direction) + require("luasnip").jump(direction) + end, + }, + }, + opts_extend = { "sources.default" }, + keymap = { preset = "default" }, + }, } diff --git a/nvim/m-housh/lua/plugins/cmp.lua b/nvim/m-housh/lua/plugins/cmp.lua index 1cdbfdb..e2f0f05 100755 --- a/nvim/m-housh/lua/plugins/cmp.lua +++ b/nvim/m-housh/lua/plugins/cmp.lua @@ -1,6 +1,6 @@ return { "hrsh7th/nvim-cmp", - enabled = true, + enabled = false, event = "VeryLazy", dependencies = { "hrsh7th/cmp-nvim-lsp", diff --git a/nvim/m-housh/lua/plugins/lsp.lua b/nvim/m-housh/lua/plugins/lsp.lua index 0ea5730..6305723 100755 --- a/nvim/m-housh/lua/plugins/lsp.lua +++ b/nvim/m-housh/lua/plugins/lsp.lua @@ -3,8 +3,8 @@ return { "neovim/nvim-lspconfig", event = { "BufReadPre", "BufNewFile" }, dependencies = { - "hrsh7th/cmp-nvim-lsp", - --"saghen/blink.cmp", + -- "hrsh7th/cmp-nvim-lsp", + "saghen/blink.cmp", { "antosha417/nvim-lsp-file-operations", config = true }, "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim", @@ -37,9 +37,9 @@ return { automatic_installation = true, }) local lspconfig = require("lspconfig") - local cmp_nvim_lsp = require("cmp_nvim_lsp") - local capabilities = cmp_nvim_lsp.default_capabilities() - --local capabilities = require("blink.cmp").get_lsp_capabilities() + -- local cmp_nvim_lsp = require("cmp_nvim_lsp") + -- local capabilities = cmp_nvim_lsp.default_capabilities() + local capabilities = require("blink.cmp").get_lsp_capabilities() local opts = { noremap = true, silent = true } local on_attach = function(_, bufnr) opts.buffer = bufnr diff --git a/nvim/m-housh/lua/plugins/luasnip.lua b/nvim/m-housh/lua/plugins/luasnip.lua index 609179a..97e36e3 100644 --- a/nvim/m-housh/lua/plugins/luasnip.lua +++ b/nvim/m-housh/lua/plugins/luasnip.lua @@ -24,7 +24,7 @@ return { end, }, }, - config = function(_, opts) + config = function() local ls = require("luasnip") ls.setup({ history = true, diff --git a/nvim/m-housh/snippets/swift.lua b/nvim/m-housh/snippets/swift.lua index b073696..a3d65fb 100644 --- a/nvim/m-housh/snippets/swift.lua +++ b/nvim/m-housh/snippets/swift.lua @@ -12,12 +12,12 @@ local rep = require("luasnip.extras").rep -- Add snippets ls.add_snippets("swift", { -- 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. s( { - trig = "@dc", + trig = "@DC", desc = "Add a dependency client.", }, fmt(