diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index e83f59e..e95b228 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -1,110 +1,75 @@ --- copied from cmp-under, but I don't think I need the plugin for this. --- I might add some more of my own. -local function under_cmp(entry1, entry2) - local _, entry1_under = entry1.completion_item.label:find("^_+") - local _, entry2_under = entry2.completion_item.label:find("^_+") - entry1_under = entry1_under or 0 - entry2_under = entry2_under or 0 - if entry1_under > entry2_under then - return false - elseif entry1_under < entry2_under then - return true - end -end ----@param entry1 cmp.Entry ----@param entry2 cmp.Entry -local function snippets_down(entry1, entry2) - local types = require("cmp.types") - local kind1, kind2 = entry1:get_kind(), entry2:get_kind() - local Snippet = types.lsp.CompletionItemKind.Snippet - if kind1 == Snippet then - -- Only return if 2 is not a snippet - if kind2 ~= Snippet then return false end - elseif kind2 == Snippet then - return true - else -- Neither is a snippet, ignore it - return - end - -- Both are snippets, discourage nvim_lsp snippets - if entry1.source.name == "nvim_lsp" then return false end - if entry2.source.name == "nvim_lsp" then return true end -end - ----@type LazySpec return { - -- auto completion { - "hrsh7th/nvim-cmp", - version = false, -- last release is way too old - event = "InsertEnter", - dependencies = { - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - }, - opts = function() - local cmp = require("cmp") - local compare = cmp.config.compare - return { ---@type cmp.ConfigSchema - -- Change border of documentation hover window, See https://github.com/neovim/neovim/pull/13998. - window = { completion = { border = "rounded" }, documentation = { border = "rounded" } }, - completion = { completeopt = "menu,menuone,noinsert" }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), - [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.abort(), - [""] = cmp.mapping.confirm({ select = false }), -- Accept without explicit selection - [""] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - [""] = function(fallback) - cmp.abort() - fallback() - end, - }), - sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "path" } }, { { name = "buffer" } }), - formatting = { ---@type cmp.FormattingConfig|{} - format = function(_, item) - local icons = require("config.icons").kinds - if icons[item.kind] then item.kind = icons[item.kind] .. item.kind end - return item - end, + "saghen/blink.cmp", + version = "*", + opts_extend = { "sources.completion.enabled_providers", "sources.default" }, + dependencies = { "rafamadriz/friendly-snippets" }, + event = { "InsertEnter", "CmdlineEnter" }, + ---@module 'blink.cmp' + ---@type blink.cmp.Config + opts = { + snippets = { preset = "default" }, + appearance = { + nerd_font_variant = "mono", + kind_icons = require("config.icons").kinds, + }, + completion = { + accept = { + auto_brackets = { enabled = false }, }, - performance = { ---@type cmp.PerformanceConfig|{} - trigger_debounce_time = 500, - throttle = 550, - fetching_timeout = 80, + menu = { + border = "rounded", + draw = { + treesitter = { "lsp" }, + }, }, - experimental = { ghost_text = false }, -- Don't show the ghost text - sorting = { - priority_weight = 2, - comparators = { - compare.offset, - compare.exact, - snippets_down, - compare.score, - compare.recently_used, - compare.locality, - under_cmp, - compare.scopes, -- prioritize values in scope order - compare.kind, -- superseded by lsp_first -- just used for lowering text - compare.sort_text, - compare.length, - compare.order, + documentation = { + auto_show = true, + auto_show_delay_ms = 200, + window = { + border = "rounded", }, }, - } - end, - ---@param opts cmp.ConfigSchema - config = function(_, opts) - for _, source in ipairs(opts.sources) do - source.group_index = source.group_index or 1 - end - require("cmp").setup(opts) - end, + }, + sources = { + default = { "lsp", "buffer", "path", "snippets" }, + }, + cmdline = { + enabled = true, + keymap = { + preset = "cmdline", + [""] = false, + [""] = false, + }, + completion = { + list = { selection = { preselect = false } }, + menu = { auto_show = function() return vim.fn.getcmdtype() == ":" end }, + ghost_text = { enabled = true }, + }, + }, + keymap = { + preset = "enter", + [""] = { "select_and_accept" }, + }, + }, + }, + + -- lazydev + { + "saghen/blink.cmp", + opts = { + sources = { + per_filetype = { + lua = { inherit_defaults = true, "lazydev" }, + }, + providers = { + lazydev = { + name = "LazyDev", + module = "lazydev.integrations.blink", + score_offset = 100, -- show at a higher priority than lsp + }, + }, + }, + }, }, } diff --git a/lua/plugins/lsp/init.lua b/lua/plugins/lsp/init.lua index caaaab2..24e3899 100644 --- a/lua/plugins/lsp/init.lua +++ b/lua/plugins/lsp/init.lua @@ -51,10 +51,12 @@ return { --- Capabilities local has_cmp, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") + local has_blink, blink = pcall(require, "blink.cmp") local capabilities = vim.tbl_deep_extend( "force", vim.lsp.protocol.make_client_capabilities(), - has_cmp and cmp_nvim_lsp.default_capabilities() or {} + has_cmp and cmp_nvim_lsp.default_capabilities() or {}, + has_blink and blink.get_lsp_capabilities() or {} ) vim.lsp.config("*", { capabilities = capabilities }) end, @@ -112,17 +114,5 @@ return { }, }, }, - { -- optional completion source for require statements and module annotations - "hrsh7th/nvim-cmp", - optional = true, - opts = function(_, opts) - _ = _ ---@module 'cmp' - opts.sources = opts.sources or {} ---@type cmp.SourceConfig[] - opts.sources[#opts.sources + 1] = { - name = "lazydev", - group_index = 0, -- set group index to 0 to skip loading LuaLS completions - } - end, - }, -- { "justinsgithub/wezterm-types", lazy = true }, } diff --git a/lua/plugins/luasnip.lua b/lua/plugins/luasnip.lua index 2d9547f..e52346c 100644 --- a/lua/plugins/luasnip.lua +++ b/lua/plugins/luasnip.lua @@ -9,7 +9,7 @@ return { build = (not jit.os:find("Windows")) and "echo 'NOTE: jsregexp is optional, so not a big deal if it fails to build'; make install_jsregexp" or nil, - dependencies = { "rafamadriz/friendly-snippets", "nvim-cmp" }, + dependencies = { "rafamadriz/friendly-snippets" }, opts = { history = true, delete_check_events = "TextChanged" }, -- Note: in insert is handled in keymaps.lua keys = { @@ -25,14 +25,6 @@ return { "rafamadriz/friendly-snippets", config = function(self) return require("luasnip.loaders.from_vscode").lazy_load({ paths = self._.dir }) end, }, - { - "nvim-cmp", - dependencies = { "saadparwaiz1/cmp_luasnip" }, - opts = function(_, opts) - opts.snippet = { expand = function(args) require("luasnip").lsp_expand(args.body) end } - table.insert(opts.sources, { name = "luasnip" }) - end, - }, { "chrisgrieser/nvim-scissors", dependencies = "nvim-telescope/telescope.nvim", diff --git a/snippets/html.jsonc b/snippets/html.jsonc index b6fa0e8..05ebb28 100644 --- a/snippets/html.jsonc +++ b/snippets/html.jsonc @@ -1,17 +1,4 @@ { - // Place your snippets for html here. Each snippet is defined under a snippet name and has a prefix, body and - // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: - // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the - // same ids are connected. - // Example: - // "Print to console": { - // "prefix": "log", - // "body": [ - // "console.log('$1');", - // "$2" - // ], - // "description": "Log output to console" - // } "insert_strong": { "prefix": ["strong", "s", "b", "bold"], "body": ["$TM_SELECTED_TEXT$0"], diff --git a/snippets/java.jsonc b/snippets/java.jsonc index b9d4c50..9c1cb78 100644 --- a/snippets/java.jsonc +++ b/snippets/java.jsonc @@ -1,17 +1,4 @@ { - // Place your snippets for java here. Each snippet is defined under a snippet name and has a prefix, body and - // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: - // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the - // same ids are connected. - // Example: - // "Print to console": { - // "prefix": "log", - // "body": [ - // "console.log('$1');", - // "$2" - // ], - // "description": "Log output to console" - // } "System.out": { "prefix": ["sysout", "stdout"], "body": "System.out.println(${1:$TM_SELECTED_TEXT}", diff --git a/snippets/javascript.jsonc b/snippets/javascript.jsonc index d548b10..6615bdd 100644 --- a/snippets/javascript.jsonc +++ b/snippets/javascript.jsonc @@ -1,14 +1,4 @@ { - // Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and - // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: - // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the - // same ids are connected. - // Example: - // "Print to console": { - // "prefix": "log", - // "body": ["console.log('$1');", "$2"], - // "description": "Log output to console" - // }, "For loop i++": { "prefix": "for", "body": [ diff --git a/snippets/shellscript.jsonc b/snippets/shellscript.jsonc index 9a80a30..c17c836 100644 --- a/snippets/shellscript.jsonc +++ b/snippets/shellscript.jsonc @@ -1,17 +1,4 @@ { - // Place your snippets for shellscript here. Each snippet is defined under a snippet name and has a prefix, body and - // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: - // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the - // same ids are connected. - // Example: - // "Print to console": { - // "prefix": "log", - // "body": [ - // "console.log('$1');", - // "$2" - // ], - // "description": "Log output to console" - // } "Get User Confirmation": { "prefix": "confirm", "description": "Get a user's confirmation, default to yes",