diff --git a/lua/core/settings.lua b/lua/core/settings.lua index fc0308f..69c617c 100644 --- a/lua/core/settings.lua +++ b/lua/core/settings.lua @@ -76,3 +76,4 @@ vim.opt.shortmess = "aItTF" -- hide buffers instead of closing vim.opt.hidden = true +vim.opt.winborder = 'rounded' diff --git a/lua/plugin/cmp.lua b/lua/plugin/cmp.lua new file mode 100644 index 0000000..4a0195a --- /dev/null +++ b/lua/plugin/cmp.lua @@ -0,0 +1,152 @@ +return { + "saghen/blink.cmp", + build = 'cargo +nightly build --release', + dependencies = { + { "L3MON4D3/LuaSnip", version = "v2.*" } + }, + lazy = true, + opts = { + snippets = { preset = 'luasnip' }, + sources = { + default = { 'buffer', 'lsp', 'path', 'snippets' }, + }, + fuzzy = { implementation = 'prefer_rust' }, + appearance = { + nerd_font_variant = 'mono', + 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 = "󰅲" + } + }, + completion = { + keyword = { + range = 'full' + }, + ghost_text = { + enabled = true + }, + menu = { + winhighlight = 'Normal:NormalFloat,FloatBorder:FloatBorder,CursorLine:CursorLine,Search:None', + min_width = 40, + max_height = 25, + draw = { + columns = { { 'label', 'label_description', gap = 1 }, { 'kind_icon', 'kind', gap = 1 } }, + components = { + label = { + highlight = function(ctx) + -- label and label details + local highlights = { + { 0, #ctx.label, group = ctx.deprecated and 'DiagnosticFloatingWarn' or 'NormalFloator' }, + } + if ctx.label_detail then + table.insert(highlights, { #ctx.label, #ctx.label + #ctx.label_detail, group = 'NormalFloat' }) + end + + return highlights + end, + }, + } + } + }, + documentation = { + auto_show = true, + auto_show_delay_ms = 0, + window = { + + winhighlight = 'Normal:NormalFloat,FloatBorder:FloatBorder,CursorLine:CursorLine', + } + }, + }, + keymap = { + [''] = { 'hide', 'show', 'fallback' }, + [''] = { 'accept', 'fallback' }, + [''] = { + function(cmp) + if cmp.snippet_active() then + return cmp.accept() + else + return cmp.select_next() + end + end, + 'snippet_forward', + 'fallback' + }, + [''] = { + function(cmp) + if cmp.snippet_active() then + return cmp.accept() + else + return cmp.select_prev() + end + end, + 'snippet_backward', + 'fallback' + }, + [''] = { 'select_prev', 'fallback' }, + [''] = { 'select_next', 'fallback' }, + [''] = { 'scroll_documentation_up', 'fallback' }, + [''] = { 'scroll_documentation_down', 'fallback' }, + [''] = { 'show_signature', 'hide_signature', 'fallback' }, + }, + signature = { + enabled = true, + window = { + winhighlight = 'Normal:NormalFloat,FloatBorder:FloatBorder', + } + }, + cmdline = { + keymap = { preset = 'inherit', [''] = { 'accept_and_enter', 'fallback' } }, + completion = { + menu = { + auto_show = function() + local type = vim.fn.getcmdtype() + -- Search forward and backward + if type == "/" or type == "?" then + return false + end + -- Commands + if type == ":" then + return true + end + return false + end, + } + }, + sources = function() + local type = vim.fn.getcmdtype() + -- Search forward and backward + if type == "/" or type == "?" then + return { "buffer" } + end + -- Commands + if type == ":" then + return { "cmdline" } + end + return {} + end, + }, + } +} diff --git a/lua/plugin/lsp.lua b/lua/plugin/lsp.lua index cad49a6..cd0f74c 100644 --- a/lua/plugin/lsp.lua +++ b/lua/plugin/lsp.lua @@ -4,13 +4,7 @@ return { dependencies = { "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim", - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "hrsh7th/cmp-cmdline", - "hrsh7th/nvim-cmp", - "L3MON4D3/LuaSnip", - "saadparwaiz1/cmp_luasnip", + "saghen/blink.cmp", "nvim-telescope/telescope-ui-select.nvim", "nvimtools/none-ls.nvim", 'nvim-treesitter/nvim-treesitter', @@ -18,147 +12,10 @@ return { "jay-babu/mason-null-ls.nvim", }, config = function() - -- autocomplete -- - - 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 has_words_before = function() - unpack = unpack or table.unpack - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and - vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - end - - local luasnip = require("luasnip") - local cmp = require("cmp") - cmp.setup({ - formatting = { - format = function(entry, vim_item) - -- Kind icons - vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind - -- Source - vim_item.menu = ({ - buffer = "", - nvim_lsp = "", - luasnip = "", - nvim_lua = "", - latex_symbols = "", - })[entry.source.name] - return vim_item - end - }, - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - end, - }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.abort() - else - cmp.complete() - end - end), - [''] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() - -- they way you will only jump inside the snippet region - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif has_words_before() then - cmp.complete() - 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' }, - { name = 'luasnip' }, -- For luasnip users. - { - name = 'buffer', - option = { - get_bufnrs = function() - return vim.api.nvim_list_bufs() - end - }, - }, - }, { - }), - -- Set configuration for specific filetype. - -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). - cmp.setup.cmdline({ '/', '?' }, { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = 'buffer' } - } - }), - -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). - cmp.setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = 'path' } - }, { - { name = 'cmdline' } - }) - }) - }) - - -- setup -- - local client_capabilities = vim.lsp.protocol.make_client_capabilities() - local cmp_capabilities = require('cmp_nvim_lsp').default_capabilities() - - local capabilities = vim.tbl_deep_extend( - "force", - client_capabilities, - cmp_capabilities - ) + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = vim.tbl_deep_extend('force', capabilities, require('blink.cmp').get_lsp_capabilities({}, false)) -- mason -- @@ -255,7 +112,6 @@ return { prefix = '●', -- Could be '●', '■', 'x', '▎', or anything else }, }) - end, } } diff --git a/lua/plugin/obsidian.lua b/lua/plugin/obsidian.lua index 70a83f6..cd8c109 100644 --- a/lua/plugin/obsidian.lua +++ b/lua/plugin/obsidian.lua @@ -22,12 +22,12 @@ return { path = "~/notes", }, }, - completion = { - -- Set to false to disable completion. - nvim_cmp = true, - -- Trigger completion at 2 chars. - min_chars = 1, - }, + -- completion = { + -- -- Set to false to disable completion. + -- nvim_cmp = true, + -- -- Trigger completion at 2 chars. + -- min_chars = 1, + -- }, mappings = { -- Overrides the 'gf' mapping to work on markdown/wiki links within your vault.