summaryrefslogtreecommitdiff
path: root/lua/lvim/core/cmp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/lvim/core/cmp.lua')
-rw-r--r--lua/lvim/core/cmp.lua147
1 files changed, 113 insertions, 34 deletions
diff --git a/lua/lvim/core/cmp.lua b/lua/lvim/core/cmp.lua
index 408691a6..4ebc4d43 100644
--- a/lua/lvim/core/cmp.lua
+++ b/lua/lvim/core/cmp.lua
@@ -19,6 +19,7 @@ end
local function feedkeys(key, mode)
vim.api.nvim_feedkeys(T(key), mode, true)
end
+
M.methods.feedkeys = feedkeys
---when inside a snippet, seeks to the nearest luasnip field if possible, and checks if it is jumpable
@@ -113,6 +114,7 @@ local function jumpable(dir)
return luasnip.in_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable(1)
end
end
+
M.methods.jumpable = jumpable
M.config = function()
@@ -135,39 +137,13 @@ M.config = function()
keyword_length = 1,
},
experimental = {
- ghost_text = true,
+ ghost_text = false,
native_menu = false,
},
formatting = {
fields = { "kind", "abbr", "menu" },
max_width = 0,
- kind_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 = "īšĻ ",
- },
+ kind_icons = lvim.icons.kind,
source_names = {
nvim_lsp = "(LSP)",
emoji = "(Emoji)",
@@ -178,6 +154,8 @@ M.config = function()
luasnip = "(Snippet)",
buffer = "(Buffer)",
tmux = "(TMUX)",
+ copilot = "(Copilot)",
+ treesitter = "(TreeSitter)",
},
duplicates = {
buffer = 1,
@@ -189,10 +167,40 @@ M.config = function()
format = function(entry, vim_item)
local max_width = lvim.builtin.cmp.formatting.max_width
if max_width ~= 0 and #vim_item.abbr > max_width then
- vim_item.abbr = string.sub(vim_item.abbr, 1, max_width - 1) .. "â€Ļ"
+ vim_item.abbr = string.sub(vim_item.abbr, 1, max_width - 1) .. lvim.icons.ui.Ellipsis
end
if lvim.use_icons then
vim_item.kind = lvim.builtin.cmp.formatting.kind_icons[vim_item.kind]
+
+ -- TODO: not sure why I can't put this anywhere else
+ vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" })
+ if entry.source.name == "copilot" then
+ vim_item.kind = lvim.icons.git.Octoface
+ vim_item.kind_hl_group = "CmpItemKindCopilot"
+ end
+
+ vim.api.nvim_set_hl(0, "CmpItemKindTabnine", { fg = "#CA42F0" })
+ if entry.source.name == "cmp_tabnine" then
+ vim_item.kind = lvim.icons.misc.Robot
+ vim_item.kind_hl_group = "CmpItemKindTabnine"
+ end
+
+ vim.api.nvim_set_hl(0, "CmpItemKindCrate", { fg = "#F64D00" })
+ if entry.source.name == "crates" then
+ vim_item.kind = lvim.icons.misc.Package
+ vim_item.kind_hl_group = "CmpItemKindCrate"
+ end
+
+ if entry.source.name == "lab.quick_data" then
+ vim_item.kind = lvim.icons.misc.CircuitBoard
+ vim_item.kind_hl_group = "CmpItemKindConstant"
+ end
+
+ vim.api.nvim_set_hl(0, "CmpItemKindEmoji", { fg = "#FDE030" })
+ if entry.source.name == "emoji" then
+ vim_item.kind = lvim.icons.misc.Smiley
+ vim_item.kind_hl_group = "CmpItemKindEmoji"
+ end
end
vim_item.menu = lvim.builtin.cmp.formatting.source_names[entry.source.name]
vim_item.dup = lvim.builtin.cmp.formatting.duplicates[entry.source.name]
@@ -210,7 +218,50 @@ M.config = function()
documentation = cmp.config.window.bordered(),
},
sources = {
- { name = "nvim_lsp" },
+ {
+ name = "copilot",
+ -- keyword_length = 0,
+ max_item_count = 3,
+ trigger_characters = {
+ {
+ ".",
+ ":",
+ "(",
+ "'",
+ '"',
+ "[",
+ ",",
+ "#",
+ "*",
+ "@",
+ "|",
+ "=",
+ "-",
+ "{",
+ "/",
+ "\\",
+ "+",
+ "?",
+ " ",
+ -- "\t",
+ -- "\n",
+ },
+ },
+ },
+ {
+ name = "nvim_lsp",
+ entry_filter = function(entry, ctx)
+ local kind = require("cmp.types").lsp.CompletionItemKind[entry:get_kind()]
+ if kind == "Snippet" and ctx.prev_context.filetype == "java" then
+ return false
+ end
+ if kind == "Text" then
+ return false
+ end
+ return true
+ end,
+ },
+
{ name = "path" },
{ name = "luasnip" },
{ name = "cmp_tabnine" },
@@ -223,8 +274,8 @@ M.config = function()
{ name = "tmux" },
},
mapping = cmp.mapping.preset.insert {
- ["<C-k>"] = cmp.mapping.select_prev_item(),
- ["<C-j>"] = cmp.mapping.select_next_item(),
+ ["<C-k>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }),
+ ["<C-j>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }),
["<Down>"] = cmp.mapping(cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Select }, { "i" }),
["<Up>"] = cmp.mapping(cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Select }, { "i" }),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
@@ -247,7 +298,8 @@ M.config = function()
elseif jumpable(1) then
luasnip.jump(1)
elseif has_words_before() then
- cmp.complete()
+ -- cmp.complete()
+ fallback()
else
fallback()
end
@@ -283,11 +335,38 @@ M.config = function()
fallback() -- if not exited early, always fallback
end),
},
+ cmdline = {
+ enable = true,
+ options = {
+ {
+ type = ":",
+ sources = {
+ { name = "path" },
+ },
+ },
+ {
+ type = { "/", "?" },
+ sources = {
+ { name = "buffer" },
+ },
+ },
+ },
+ },
}
end
function M.setup()
- require("cmp").setup(lvim.builtin.cmp)
+ local cmp = require "cmp"
+ cmp.setup(lvim.builtin.cmp)
+
+ if lvim.builtin.cmp.cmdline.enable then
+ for _, option in ipairs(lvim.builtin.cmp.cmdline.options) do
+ cmp.setup.cmdline(option.type, {
+ mapping = cmp.mapping.preset.cmdline(),
+ sources = option.sources,
+ })
+ end
+ end
end
return M