diff options
Diffstat (limited to 'lua/core')
| -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 | 
4 files changed, 154 insertions, 156 deletions
| 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 | 
