2024-04-20 13:42:06 +00:00
|
|
|
{ pkgs, dsl, ... }:
|
|
|
|
{
|
2022-11-28 05:31:17 +00:00
|
|
|
|
|
|
|
plugins = [
|
2024-12-08 16:43:47 +00:00
|
|
|
pkgs.vimPlugins.nvim-cmp
|
2022-11-28 05:31:17 +00:00
|
|
|
pkgs.vimPlugins.cmp-nvim-lsp
|
|
|
|
pkgs.vimPlugins.cmp-buffer
|
|
|
|
pkgs.vimPlugins.cmp-path
|
|
|
|
pkgs.vimPlugins.cmp-cmdline
|
|
|
|
pkgs.vimPlugins.cmp-nvim-lua
|
|
|
|
pkgs.vimPlugins.luasnip
|
|
|
|
pkgs.vimPlugins.cmp_luasnip
|
|
|
|
pkgs.vimPlugins.cmp-rg
|
|
|
|
];
|
|
|
|
|
|
|
|
use.cmp.setup = dsl.callWith {
|
|
|
|
|
|
|
|
# Disable in telescope buffers
|
|
|
|
enabled = dsl.rawLua ''
|
|
|
|
function()
|
|
|
|
if vim.bo.buftype == "prompt" then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
|
2023-07-30 03:56:41 +00:00
|
|
|
# Basic completion keybinds
|
2022-11-28 05:31:17 +00:00
|
|
|
mapping = {
|
2024-12-08 16:43:47 +00:00
|
|
|
"['<C-n>']" =
|
|
|
|
dsl.rawLua "require('cmp').mapping.select_next_item({ behavior = require('cmp').SelectBehavior.Insert }, { 'i', 'c' })";
|
|
|
|
"['<C-p>']" =
|
|
|
|
dsl.rawLua "require('cmp').mapping.select_prev_item({ behavior = require('cmp').SelectBehavior.Insert }, { 'i', 'c' })";
|
|
|
|
"['<Down>']" =
|
|
|
|
dsl.rawLua "require('cmp').mapping.select_next_item({ behavior = require('cmp').SelectBehavior.Select }, { 'i', 'c' })";
|
|
|
|
"['<Up>']" =
|
|
|
|
dsl.rawLua "require('cmp').mapping.select_prev_item({ behavior = require('cmp').SelectBehavior.Select }, { 'i', 'c' })";
|
2022-11-28 05:31:17 +00:00
|
|
|
"['<C-d>']" = dsl.rawLua "require('cmp').mapping.scroll_docs(-4)";
|
|
|
|
"['<C-f>']" = dsl.rawLua "require('cmp').mapping.scroll_docs(4)";
|
|
|
|
"['<C-e>']" = dsl.rawLua "require('cmp').mapping.abort()";
|
2024-12-08 16:43:47 +00:00
|
|
|
"['<C-y>']" =
|
|
|
|
dsl.rawLua "require('cmp').mapping.confirm({ behavior = require('cmp').ConfirmBehavior.Insert, select = true, }, { 'i', 'c' })";
|
|
|
|
"['<C-r>']" =
|
|
|
|
dsl.rawLua "require('cmp').mapping.confirm({ behavior = require('cmp').ConfirmBehavior.Replace, select = true, }, { 'i', 'c' })";
|
2022-11-28 05:31:17 +00:00
|
|
|
"['<Esc>']" = dsl.rawLua ''
|
|
|
|
function(_)
|
|
|
|
cmp.mapping({
|
|
|
|
i = cmp.mapping.abort(),
|
|
|
|
c = cmp.mapping.close(),
|
|
|
|
})
|
|
|
|
vim.cmd("stopinsert") --- Abort and leave insert mode
|
|
|
|
end
|
|
|
|
'';
|
2024-06-05 17:53:54 +00:00
|
|
|
"['<C-k>']" = dsl.rawLua ''
|
2022-11-28 05:31:17 +00:00
|
|
|
cmp.mapping(function(_)
|
|
|
|
if require("luasnip").expand_or_jumpable() then
|
|
|
|
require("luasnip").expand_or_jump()
|
|
|
|
end
|
|
|
|
end, { "i", "s" })
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-30 03:56:41 +00:00
|
|
|
# These are where the completion engine gets its suggestions
|
2022-11-28 05:31:17 +00:00
|
|
|
sources = [
|
2023-07-30 03:56:41 +00:00
|
|
|
{ name = "nvim_lua"; } # Fills in common Neovim lua functions
|
|
|
|
{ name = "nvim_lsp"; } # LSP results
|
|
|
|
{ name = "path"; } # Shell completion from current PATH
|
2022-11-28 05:31:17 +00:00
|
|
|
{
|
2023-07-30 03:56:41 +00:00
|
|
|
name = "buffer"; # Grep for text from the current text buffer
|
2022-11-28 05:31:17 +00:00
|
|
|
keyword_length = 3;
|
|
|
|
max_item_count = 10;
|
|
|
|
}
|
|
|
|
{
|
2023-07-30 03:56:41 +00:00
|
|
|
name = "rg"; # Grep for text from the current directory
|
2022-11-28 05:31:17 +00:00
|
|
|
keyword_length = 6;
|
|
|
|
max_item_count = 10;
|
2024-04-20 13:42:06 +00:00
|
|
|
option = {
|
|
|
|
additional_arguments = "--ignore-case";
|
|
|
|
};
|
2022-11-28 05:31:17 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-07-30 03:56:41 +00:00
|
|
|
# Styling of the completion menu
|
2022-11-28 05:31:17 +00:00
|
|
|
formatting = {
|
2024-04-20 13:42:06 +00:00
|
|
|
fields = [
|
|
|
|
"kind"
|
|
|
|
"abbr"
|
|
|
|
"menu"
|
|
|
|
];
|
2022-11-28 05:31:17 +00:00
|
|
|
format = dsl.rawLua ''
|
|
|
|
function(entry, vim_item)
|
|
|
|
local kind_icons = {
|
|
|
|
Text = "",
|
|
|
|
Method = "m",
|
|
|
|
Function = "",
|
|
|
|
Constructor = "",
|
|
|
|
Field = "",
|
|
|
|
Variable = "",
|
|
|
|
Class = "",
|
|
|
|
Interface = "",
|
|
|
|
Module = "",
|
|
|
|
Property = "",
|
|
|
|
Unit = "",
|
|
|
|
Value = "",
|
|
|
|
Enum = "",
|
|
|
|
Keyword = "",
|
|
|
|
Snippet = "",
|
|
|
|
Color = "",
|
|
|
|
File = "",
|
|
|
|
Reference = "",
|
|
|
|
Folder = "",
|
|
|
|
EnumMember = "",
|
|
|
|
Constant = "",
|
|
|
|
Struct = "",
|
|
|
|
Event = "",
|
|
|
|
Operator = "",
|
|
|
|
TypeParameter = "",
|
|
|
|
}
|
|
|
|
vim_item.kind = string.format("%s", kind_icons[vim_item.kind])
|
|
|
|
vim_item.menu = ({
|
|
|
|
buffer = "[Buffer]",
|
|
|
|
path = "[Path]",
|
|
|
|
rg = "[Grep]",
|
|
|
|
nvim_lsp = "[LSP]",
|
|
|
|
nvim_lua = "[Lua]",
|
|
|
|
})[entry.source.name]
|
|
|
|
return vim_item
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
experimental = {
|
|
|
|
native_menu = false; # Use cmp menu instead of Vim menu
|
|
|
|
ghost_text = true; # Show preview auto-completion
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-08 16:43:47 +00:00
|
|
|
lua' = ''
|
2022-11-28 05:31:17 +00:00
|
|
|
-- Use buffer source for `/`
|
|
|
|
require('cmp').setup.cmdline("/", {
|
2024-06-19 00:08:49 +00:00
|
|
|
mapping = {
|
|
|
|
['<C-n>'] = {
|
|
|
|
c = require('cmp').mapping.select_next_item({ behavior = require('cmp').SelectBehavior.Insert }, { 'i', 'c' })
|
|
|
|
},
|
|
|
|
['<C-p>'] = {
|
|
|
|
c = require('cmp').mapping.select_prev_item({ behavior = require('cmp').SelectBehavior.Insert }, { 'i', 'c' })
|
|
|
|
},
|
|
|
|
['<C-y>'] = {
|
|
|
|
c = require('cmp').mapping.confirm({ behavior = require('cmp').ConfirmBehavior.Insert, select = true, }, { 'i', 'c' })
|
|
|
|
},
|
|
|
|
['<C-r>'] = {
|
|
|
|
c = require('cmp').mapping.confirm({ behavior = require('cmp').ConfirmBehavior.Replace, select = true, }, { 'i', 'c' })
|
|
|
|
},
|
2022-11-28 05:31:17 +00:00
|
|
|
},
|
2024-06-19 00:08:49 +00:00
|
|
|
sources = require('cmp').config.sources({
|
|
|
|
{ name = "buffer", keyword_length = 5 },
|
|
|
|
}),
|
2022-11-28 05:31:17 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Use cmdline & path source for ':'
|
|
|
|
require('cmp').setup.cmdline(":", {
|
2024-06-19 00:08:49 +00:00
|
|
|
mapping = {
|
|
|
|
['<C-n>'] = {
|
|
|
|
c = require('cmp').mapping.select_next_item({ behavior = require('cmp').SelectBehavior.Insert }, { 'i', 'c' })
|
|
|
|
},
|
|
|
|
['<C-p>'] = {
|
|
|
|
c = require('cmp').mapping.select_prev_item({ behavior = require('cmp').SelectBehavior.Insert }, { 'i', 'c' })
|
|
|
|
},
|
|
|
|
['<C-y>'] = {
|
|
|
|
c = require('cmp').mapping.confirm({ behavior = require('cmp').ConfirmBehavior.Insert, select = true, }, { 'i', 'c' })
|
|
|
|
},
|
|
|
|
['<C-r>'] = {
|
|
|
|
c = require('cmp').mapping.confirm({ behavior = require('cmp').ConfirmBehavior.Replace, select = true, }, { 'i', 'c' })
|
|
|
|
},
|
|
|
|
},
|
2022-11-28 05:31:17 +00:00
|
|
|
sources = require('cmp').config.sources({
|
|
|
|
{ name = "path" },
|
|
|
|
}, {
|
|
|
|
{ name = "cmdline" },
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
'';
|
|
|
|
}
|