diff options
-rw-r--r-- | init.lua | 7 | ||||
-rw-r--r-- | lua/config/defaults.lua | 16 | ||||
-rw-r--r-- | lua/core/autopairs.lua | 52 | ||||
-rw-r--r-- | lua/core/builtins/init.lua | 2 | ||||
-rw-r--r-- | lua/core/cmp.lua | 123 | ||||
-rw-r--r-- | lua/core/compe.lua | 133 | ||||
-rw-r--r-- | lua/lsp/init.lua | 6 | ||||
-rw-r--r-- | lua/lsp/kind.lua | 31 | ||||
-rw-r--r-- | lua/plugins.lua | 44 |
9 files changed, 215 insertions, 199 deletions
@@ -52,10 +52,3 @@ if lsp_settings_status_ok then end require("keymappings").setup() - --- TODO: these guys need to be in language files --- if lvim.lang.emmet.active then --- require "lsp.emmet-ls" --- end --- if lvim.lang.tailwindcss.active then --- require "lsp.tailwind diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index 0f70a281..24455819 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -37,30 +37,30 @@ lvim = { lsp = { completion = { item_kind = { - " ī (Text) ", + " īž (Text) ", " īĻ (Method)", " ī (Function)", " īĨ (Constructor)", - " ī´˛ (Field)", - "[î] (Variable)", + " î (Field)", + " î (Variable)", " ī (Class)", " ī°Ž (Interface)", " ī¨ (Module)", - " īĒļ (Property)", - " īĩ (Unit)", + " î¤ (Property)", + " īĨŦ (Unit)", " īĸ (Value)", " īŠ (Enum)", " ī (Keyword)", " ī (Snippet)", " īŖ (Color)", - " ī (File)", + " ī (File)", " ī (Reference)", " ī (Folder)", " ī
(EnumMember)", " ī˛ (Constant)", - " īŗ¤ (Struct)", + " ī (Struct)", " ī§ (Event)", - " īĢ (Operator)", + " ī (Operator)", " ī (TypeParameter)", }, }, diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index 24aa1875..b728cbc1 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -20,36 +20,44 @@ function M.config() end M.setup = function() - -- skip it, if you use another global object - _G.MUtils = {} local autopairs = require "nvim-autopairs" local Rule = require "nvim-autopairs.rule" - - vim.g.completion_confirm_key = "" - MUtils.completion_confirm = function() - if vim.fn.pumvisible() ~= 0 then - if vim.fn.complete_info()["selected"] ~= -1 then - return vim.fn["compe#confirm"](autopairs.esc "<cr>") - else - return autopairs.esc "<cr>" - end - else - return autopairs.autopairs_cr() - end - end - - if package.loaded["compe"] then - require("nvim-autopairs.completion.compe").setup { - map_cr = lvim.builtin.autopairs.map_cr, - map_complete = lvim.builtin.autopairs.map_complete, - } - end + local cond = require "nvim-autopairs.conds" autopairs.setup { check_ts = lvim.builtin.autopairs.check_ts, ts_config = lvim.builtin.autopairs.ts_config, } + -- vim.g.completion_confirm_key = "" + + autopairs.add_rule(Rule("$$", "$$", "tex")) + autopairs.add_rules { + Rule("$", "$", { "tex", "latex" }) -- don't add a pair if the next character is % + :with_pair(cond.not_after_regex_check "%%") -- don't add a pair if the previous character is xxx + :with_pair(cond.not_before_regex_check("xxx", 3)) -- don't move right when repeat character + :with_move(cond.none()) -- don't delete if the next character is xx + :with_del(cond.not_after_regex_check "xx") -- disable add newline when press <cr> + :with_cr(cond.none()), + } + autopairs.add_rules { + Rule("$$", "$$", "tex"):with_pair(function(opts) + print(vim.inspect(opts)) + if opts.line == "aa $$" then + -- don't add pair on that line + return false + end + end), + } + + if package.loaded["cmp"] then + require("nvim-autopairs.completion.cmp").setup { + map_cr = true, -- map <CR> on insert mode + map_complete = true, -- it will auto insert `(` after select function or method item + auto_select = true, -- automatically select the first item + } + end + require("nvim-treesitter.configs").setup { autopairs = { enable = true } } local ts_conds = require "nvim-autopairs.ts-conds" diff --git a/lua/core/builtins/init.lua b/lua/core/builtins/init.lua index 32f96af5..dc9b5ff5 100644 --- a/lua/core/builtins/init.lua +++ b/lua/core/builtins/init.lua @@ -4,7 +4,7 @@ local builtins = { "keymappings", "core.which-key", "core.gitsigns", - "core.compe", + "core.cmp", "core.dashboard", "core.dap", "core.terminal", diff --git a/lua/core/cmp.lua b/lua/core/cmp.lua new file mode 100644 index 00000000..7f912544 --- /dev/null +++ b/lua/core/cmp.lua @@ -0,0 +1,123 @@ +local M = {} + +local check_backspace = function() + local col = vim.fn.col "." - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match "%s" +end + +local function T(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +local is_emmet_active = function() + local clients = vim.lsp.buf_get_clients() + + for _, client in pairs(clients) do + if client.name == "emmet_ls" then + return true + end + end + return false +end + +M.config = function() + local status_cmp_ok, cmp = pcall(require, "cmp") + if not status_cmp_ok then + return + end + local status_luasnip_ok, luasnip = pcall(require, "luasnip") + if not status_luasnip_ok then + return + end + lvim.builtin.cmp = { + formatting = { + format = function(entry, vim_item) + local icons = require("lsp.kind").icons + vim_item.kind = icons[vim_item.kind] + vim_item.menu = ({ + nvim_lsp = "(LSP)", + emoji = "(Emoji)", + path = "(Path)", + calc = "(Calc)", + cmp_tabnine = "(Tabnine)", + vsnip = "(Snippet)", + luasnip = "(Snippet)", + buffer = "(Buffer)", + })[entry.source.name] + vim_item.dup = ({ + buffer = 1, + path = 1, + nvim_lsp = 0, + })[entry.source.name] or 0 + return vim_item + end, + }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + documentation = { + border = { "â", "â", "âŽ", "â", "â¯", "â", "â°", "â" }, + }, + sources = { + { name = "nvim_lsp" }, + { name = "path" }, + { name = "luasnip" }, + { name = "cmp_tabnine" }, + { name = "nvim_lua" }, + { name = "buffer" }, + { name = "calc" }, + { name = "emoji" }, + { name = "treesitter" }, + { name = "crates" }, + }, + mapping = { + ["<C-d>"] = cmp.mapping.scroll_docs(-4), + ["<C-f>"] = cmp.mapping.scroll_docs(4), + -- TODO: potentially fix emmet nonsense + ["<Tab>"] = cmp.mapping(function() + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(T "<C-n>", "n") + elseif luasnip.expand_or_jumpable() then + vim.fn.feedkeys(T "<Plug>luasnip-expand-or-jump", "") + elseif check_backspace() then + vim.fn.feedkeys(T "<Tab>", "n") + elseif is_emmet_active() then + return vim.fn["cmp#complete"]() + else + vim.fn.feedkeys(T "<Tab>", "n") + end + end, { + "i", + "s", + }), + ["<S-Tab>"] = cmp.mapping(function(fallback) + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(T "<C-p>", "n") + elseif luasnip.jumpable(-1) then + vim.fn.feedkeys(T "<Plug>luasnip-jump-prev", "") + else + fallback() + end + end, { + "i", + "s", + }), + + ["<C-Space>"] = cmp.mapping.complete(), + ["<C-e>"] = cmp.mapping.close(), + ["<CR>"] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + }, + } + + M.setup = function() + require("luasnip/loaders/from_vscode").lazy_load() + require("cmp").setup(lvim.builtin.cmp) + end +end + +return M diff --git a/lua/core/compe.lua b/lua/core/compe.lua deleted file mode 100644 index 9eb3dcfa..00000000 --- a/lua/core/compe.lua +++ /dev/null @@ -1,133 +0,0 @@ -local M = {} - -M.config = function() - lvim.builtin.compe = { - active = true, - on_config_done = nil, - autocomplete = true, - debug = false, - min_length = 1, - preselect = "enable", - throttle_time = 80, - source_timeout = 200, - incomplete_delay = 400, - max_abbr_width = 100, - max_kind_width = 100, - max_menu_width = 100, - documentation = { - border = "single", - winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder", - max_width = 120, - min_width = 60, - max_height = math.floor(vim.o.lines * 0.3), - min_height = 1, - }, - -- documentation = true, - - source = { - path = { kind = " ī (Path)" }, - buffer = { kind = " ī (Buffer)" }, - calc = { kind = " īŦ (Calc)" }, - vsnip = { kind = " ī (Snippet)" }, - nvim_lsp = { kind = " î (LSP)" }, - nvim_lua = false, - spell = { kind = " ī (Spell)" }, - tags = false, - vim_dadbod_completion = false, - snippets_nvim = false, - ultisnips = false, - treesitter = false, - emoji = { kind = " ī˛ (Emoji)", filetypes = { "markdown", "text" } }, - -- for emoji press : (idk if that in compe tho) - }, - - keymap = { - values = { - insert_mode = { - -- ["<Tab>"] = { 'pumvisible() ? "<C-n>" : "<Tab>"', { silent = true, noremap = true, expr = true } }, - -- ["<S-Tab>"] = { 'pumvisible() ? "<C-p>" : "<S-Tab>"', { silent = true, noremap = true, expr = true } }, - ["<C-Space>"] = { "compe#complete()", { silent = true, noremap = true, expr = true } }, - ["<C-e>"] = { "compe#close('<C-e>')", { silent = true, noremap = true, expr = true } }, - ["<C-f>"] = { "compe#scroll({ 'delta': +4 })", { silent = true, noremap = true, expr = true } }, - ["<C-d>"] = { "compe#scroll({ 'delta': -4 })", { silent = true, noremap = true, expr = true } }, - }, - }, - opts = { - insert_mode = { noremap = true, silent = true, expr = true }, - }, - }, - } -end - -M.setup = function() - vim.g.vsnip_snippet_dir = lvim.vsnip_dir - - local compe = require "compe" - - compe.setup(lvim.builtin.compe) - - local t = function(str) - return vim.api.nvim_replace_termcodes(str, true, true, true) - end - - local check_back_space = function() - local col = vim.fn.col "." - 1 - if col == 0 or vim.fn.getline("."):sub(col, col):match "%s" then - return true - else - return false - end - end - - local is_emmet_active = function() - local clients = vim.lsp.buf_get_clients() - - for _, client in pairs(clients) do - if client.name == "emmet_ls" then - return true - end - end - return false - end - - -- Use (s-)tab to: - --- move to prev/next item in completion menuone - --- jump to prev/next snippet's placeholder - _G.tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "<C-n>" - elseif vim.fn.call("vsnip#jumpable", { 1 }) == 1 then - return t "<Plug>(vsnip-jump-next)" - elseif check_back_space() then - return t "<Tab>" - elseif is_emmet_active() then - return vim.fn["compe#complete"]() - else - return t "<Tab>" - end - end - - _G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "<C-p>" - elseif vim.fn.call("vsnip#jumpable", { -1 }) == 1 then - return t "<Plug>(vsnip-jump-prev)" - else - return t "<S-Tab>" - end - end - - local keymap = require "keymappings" - keymap.load(lvim.builtin.compe.keymap.values, lvim.builtin.compe.keymap.opts) - - vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) - - if lvim.builtin.compe.on_config_done then - lvim.builtin.compe.on_config_done(compe) - end -end - -return M diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index a734293a..edac2245 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -65,6 +65,12 @@ function M.common_capabilities() "additionalTextEdits", }, } + + local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") + if not status_ok then + return + end + capabilities = cmp_nvim_lsp.update_capabilities(capabilities) return capabilities end diff --git a/lua/lsp/kind.lua b/lua/lsp/kind.lua new file mode 100644 index 00000000..b78fd318 --- /dev/null +++ b/lua/lsp/kind.lua @@ -0,0 +1,31 @@ +local M = {} + +M.icons = { + Class = "ī ", + Color = "îĢ ", + Constant = "ī˛ ", + Constructor = "īĨ ", + Enum = "īŠ", + EnumMember = "ī
", + Event = "ī§ ", + Field = "î ", + File = "ī", + Folder = "ī ", + Function = "ī ", + Interface = "ī°Ž ", + Keyword = "ī ", + Method = "î ", + Module = "ī¨ ", + Operator = "ī", + Property = "î¤ ", + Reference = "ī ", + Snippet = "ī ", + Struct = "ī ", + Text = "īž ", + TypeParameter = "ī ", + Unit = "īĨŦ", + Value = "īĸ ", + Variable = "īĻ ", +} + +return M diff --git a/lua/plugins.lua b/lua/plugins.lua index ef9ae041..be614c5f 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -24,49 +24,36 @@ return { end, disable = not lvim.builtin.telescope.active, }, - - -- Completion & Snippets + -- Install nvim-cmp, and buffer source as a dependency { - "hrsh7th/nvim-compe", - event = "InsertEnter", + "hrsh7th/nvim-cmp", config = function() - require("core.compe").setup() + require("core.cmp").setup() end, - disable = not lvim.builtin.compe.active, - -- wants = "vim-vsnip", - -- requires = { - -- { - -- "hrsh7th/vim-vsnip", - -- wants = "friendly-snippets", - -- event = "InsertCharPre", - -- }, - -- { - -- "rafamadriz/friendly-snippets", - -- event = "InsertCharPre", - -- }, - -- }, - }, - { - "hrsh7th/vim-vsnip", - -- wants = "friendly-snippets", - event = "InsertEnter", - disable = not lvim.builtin.compe.active, + requires = { + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-path", + "hrsh7th/cmp-nvim-lua", + }, }, { "rafamadriz/friendly-snippets", - event = "InsertCharPre", - disable = not lvim.builtin.compe.active, + -- event = "InsertCharPre", + -- disable = not lvim.builtin.compe.active, }, -- Autopairs { "windwp/nvim-autopairs", -- event = "InsertEnter", - after = "nvim-compe", + after = "nvim-cmp", config = function() require("core.autopairs").setup() end, - disable = not lvim.builtin.autopairs.active or not lvim.builtin.compe.active, + disable = not lvim.builtin.autopairs.active, }, -- Treesitter @@ -98,6 +85,7 @@ return { require("core.gitsigns").setup() end, event = "BufRead", + commit = "25d4b182ece5b03cd4b2d8c196f3c38e0df58801", disable = not lvim.builtin.gitsigns.active, }, |