diff --git a/lua/options.lua b/lua/options.lua index 7ed6911..7331876 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -38,6 +38,9 @@ local options = { vim.g.have_nerd_font = true +-- no python remote plugins; skip provider host probe (~40ms shell spawn on .py files) +vim.g.loaded_python3_provider = 0 + vim.opt.shortmess:append("c") -- don't give |ins-completion-menu| messages vim.opt.iskeyword:append("-") -- hyphenated words recognized by searches -- stylua: ignore end diff --git a/lua/plugins/blink.lua b/lua/plugins/blink.lua new file mode 100644 index 0000000..009b5b4 --- /dev/null +++ b/lua/plugins/blink.lua @@ -0,0 +1,131 @@ +local kind_icons = { + Text = "󰉿", + Method = "󰆧", + Function = "󰊕", + Constructor = "", + Field = "󰜢", + Variable = "󰀫", + Class = "󰠱", + Interface = "", + Module = "", + Property = "󰜢", + Unit = "󰑭", + Value = "󰎠", + Enum = "", + Keyword = "󰌋", + Snippet = "", + Color = "󰏘", + File = "󰈙", + Reference = "󰈇", + Folder = "󰉋", + EnumMember = "", + Constant = "󰏿", + Struct = "󰙅", + Event = "", + Operator = "󰆕", + TypeParameter = "", +} + +local filetypes_without_autocomplete = { + NeogitCommitMessage = true, + TelescopePrompt = true, + gitcommit = true, + markdown = true, +} + +return { + "saghen/blink.cmp", + version = "*", -- use a release tag, downloads prebuilt fuzzy binary + event = { "InsertEnter", "CmdlineEnter" }, + dependencies = { + "L3MON4D3/LuaSnip", + "ribru17/blink-cmp-spell", + }, + ---@module 'blink.cmp' + ---@type blink.cmp.Config + opts = { + enabled = function() + return not filetypes_without_autocomplete[vim.bo.filetype] + end, + + snippets = { preset = "luasnip" }, + + appearance = { + kind_icons = kind_icons, + }, + + -- confirm (no preselect), abort + -- cycle forward + snippet jump, cycle backward + keymap = { + preset = "none", + [""] = { "accept", "fallback" }, + [""] = { "hide", "fallback" }, + [""] = { "select_next", "snippet_forward", "fallback" }, + [""] = { "select_prev", "snippet_backward", "fallback" }, + }, + + completion = { + list = { + -- do not select first item (mimics preselect=false, noselect) + selection = { preselect = false, auto_insert = false }, + }, + menu = { + border = "rounded", + draw = { + columns = { + { "kind_icon" }, + { "label", "label_description", gap = 1 }, + { "source_name" }, + }, + components = { + source_name = { + text = function(ctx) + return "[" .. ctx.source_name .. "]" + end, + }, + }, + }, + }, + documentation = { + auto_show = true, + window = { border = "rounded" }, + }, + }, + + signature = { + enabled = true, + window = { border = "rounded" }, + }, + + sources = { + default = { "lsp", "snippets", "buffer", "path", "spell" }, + providers = { + lsp = { min_keyword_length = 3, max_items = 5 }, + snippets = { min_keyword_length = 3, max_items = 3 }, + buffer = { min_keyword_length = 3, max_items = 5 }, + spell = { + name = "Spell", + module = "blink-cmp-spell", + min_keyword_length = 3, + max_items = 5, + opts = { + enable_in_context = function() + return true + end, + }, + }, + }, + }, + + -- cmdline: blink defaults handle `:` `/` `?` (path + cmdline sources) + cmdline = { + keymap = { preset = "cmdline" }, + completion = { + menu = { auto_show = true }, + }, + }, + + fuzzy = { implementation = "prefer_rust_with_warning" }, + }, + opts_extend = { "sources.default" }, +} diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua deleted file mode 100644 index 01cce33..0000000 --- a/lua/plugins/cmp.lua +++ /dev/null @@ -1,198 +0,0 @@ -vim.api.nvim_create_autocmd("FileType", { - callback = function() - local filetypes_wo_autocomplete = { - "NeogitCommitMessage", - "TelescopePrompt", - "gitcommit", - "markdown", - } - for _, f in ipairs(filetypes_wo_autocomplete) do - if vim.bo.filetype == f then - require("cmp").setup.filetype(f, { - enabled = false, - }) - end - end - end, -}) - -return { - "hrsh7th/nvim-cmp", - event = { "BufEnter", "BufReadPre", "BufNewFile" }, - dependencies = { - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-nvim-lua", - "hrsh7th/cmp-cmdline", - "hrsh7th/cmp-path", - "f3fora/cmp-spell", - "hrsh7th/cmp-nvim-lsp-signature-help", - "saadparwaiz1/cmp_luasnip", - "lukas-reineke/cmp-under-comparator", - }, - config = function() - local kind_icons = { - Text = "󰉿", - Method = "󰆧", - Function = "󰊕", - Constructor = "", - Field = "󰜢", - Variable = "󰀫", - Class = "󰠱", - Interface = "", - Module = "", - Property = "󰜢", - Unit = "󰑭", - Value = "󰎠", - Enum = "", - Keyword = "󰌋", - Snippet = "", - Color = "󰏘", - File = "󰈙", - Reference = "󰈇", - Folder = "󰉋", - EnumMember = "", - Constant = "󰏿", - Struct = "󰙅", - Event = "", - Operator = "󰆕", - TypeParameter = "", - } - - local cmp = require("cmp") - local cmplsp = require("cmp_nvim_lsp") - local compare = require("cmp.config.compare") - local luasnip = require("luasnip") - local types = require("cmp.types") - - cmplsp.setup() - - local modified_priority = { - [types.lsp.CompletionItemKind.Variable] = types.lsp.CompletionItemKind.Method, - [types.lsp.CompletionItemKind.Snippet] = 0, -- top - [types.lsp.CompletionItemKind.Keyword] = 0, -- top - [types.lsp.CompletionItemKind.Text] = 100, -- bottom - } - - local function modified_kind(kind) - return modified_priority[kind] or kind - end - - local buffers = { - name = "buffer", - option = { - keyword_length = 3, - get_bufnrs = function() -- from all buffers (less than 1MB) - local bufs = {} - for _, bufn in ipairs(vim.api.nvim_list_bufs()) do - local buf_size = vim.api.nvim_buf_get_offset(bufn, vim.api.nvim_buf_line_count(bufn)) - if buf_size < 1024 * 1024 then - table.insert(bufs, bufn) - end - end - return bufs - end, - }, - } - - local spelling = { - name = "spell", - max_item_count = 5, - keyword_length = 3, - option = { - keep_all_entries = false, - enable_in_context = function() - return true - end, - }, - } - - cmp.setup { - preselect = false, - completion = { - completeopt = "menu,menuone,preview,noselect", - }, - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - formatting = { - fields = { "abbr", "kind", "menu" }, - format = function(entry, vim_item) - local kind = vim_item.kind - vim_item.kind = " " .. (kind_icons[kind] or "?") .. "" - local source = entry.source.name - vim_item.menu = "[" .. source .. "]" - - return vim_item - end, - }, - sorting = { - priority_weight = 1.0, - comparators = { - compare.offset, - compare.exact, - compare.recently_used, - function(entry1, entry2) -- sort by compare kind (Variable, Function etc) - local kind1 = modified_kind(entry1:get_kind()) - local kind2 = modified_kind(entry2:get_kind()) - if kind1 ~= kind2 then - return kind1 - kind2 < 0 - end - end, - compare.score, - require("cmp-under-comparator").under, - compare.kind, - }, - }, - mapping = cmp.mapping.preset.insert { - [""] = cmp.mapping.confirm { select = false }, -- do not select first item - [""] = cmp.mapping.abort(), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { "i", "s" }), - }, - sources = cmp.config.sources({ - { name = "nvim_lsp", max_item_count = 5 }, - { name = "luasnip", max_item_count = 3 }, - { name = "nvim_lua", max_item_count = 5 }, - { name = "nvim_lsp_signature_help", max_item_count = 5 }, - }, { - buffers, - spelling, - }), - performance = { - max_view_entries = 20, - }, - window = { documentation = cmp.config.window.bordered(), completion = cmp.config.window.bordered() }, - } - - -- `:` cmdline setup. - cmp.setup.cmdline(":", { - completion = { keyword_length = 3 }, - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = "path" }, - }, { - { name = "cmdline" }, - }), - matching = { disallow_symbol_nonprefix_matching = false }, - }) - end, -} diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua index f334408..1995ea0 100644 --- a/lua/plugins/lspconfig.lua +++ b/lua/plugins/lspconfig.lua @@ -32,6 +32,12 @@ vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { return { "neovim/nvim-lspconfig", config = function() + -- advertise blink.cmp completion capabilities to every server + local ok_blink, blink = pcall(require, "blink.cmp") + if ok_blink then + vim.lsp.config("*", { capabilities = blink.get_lsp_capabilities() }) + end + local path = vim.fn.stdpath("config") .. "/lua/language-servers" local files = vim.fn.readdir(path) diff --git a/lua/plugins/noice.lua b/lua/plugins/noice.lua index 436dd0d..7ee9853 100644 --- a/lua/plugins/noice.lua +++ b/lua/plugins/noice.lua @@ -10,6 +10,11 @@ return { lsp_doc_border = false, -- add a border to hover docs and signature help }, routes = { + { + -- pyright re-analyzes on every keystroke and spams progress; + filter = { event = "lsp", kind = "progress", find = "[Pp]yright" }, + opts = { skip = true }, + }, { filter = { any = { diff --git a/lua/plugins/tokyonight.lua b/lua/plugins/tokyonight.lua index 816860b..1e1fb2a 100644 --- a/lua/plugins/tokyonight.lua +++ b/lua/plugins/tokyonight.lua @@ -2,6 +2,8 @@ local highlight = vim.api.nvim_set_hl return { "folke/tokyonight.nvim", + lazy = false, + priority = 1000, opts = { transparent = true, style = "night",