This is the first commit that actually adds files to the repo. Yes it's a bad commit but now the major features are here
104 lines
2.5 KiB
Lua
104 lines
2.5 KiB
Lua
local utilities = require('sherlock5512.utilities')
|
|
local required = {"lspkind","luasnip","cmp"}
|
|
local modules = utilities.require_modules(required)
|
|
|
|
if not modules then
|
|
return
|
|
end
|
|
|
|
-- lspkind MUST be initialised before use
|
|
modules.lspkind.init()
|
|
|
|
-- I define a default set of configs that are shared across all filetypes,
|
|
-- This way I can have fietype specific configs without using autocommands.
|
|
local defaultSources = modules.cmp.config.sources({
|
|
{ name = "nvim_lsp" },
|
|
{ name = "luasnip" },
|
|
{ name = "path" },
|
|
})
|
|
|
|
local defaultSnippet = {
|
|
expand = function (args)
|
|
modules.luasnip.lsp_expand(args.body)
|
|
end
|
|
}
|
|
|
|
local defaultMapping = {
|
|
["<Tab>"] = modules.cmp.mapping(function(fallback)
|
|
if modules.cmp.visible() then
|
|
modules.cmp.select_next_item()
|
|
elseif modules.luasnip.expand_or_locally_jumpable() then
|
|
modules.luasnip.expand_or_jump()
|
|
else
|
|
fallback()
|
|
end
|
|
end, {"i","s"}),
|
|
|
|
["<S-Tab>"] = modules.cmp.mapping(function(fallback)
|
|
if modules.cmp.visible() then
|
|
modules.cmp.select_prev_item()
|
|
elseif modules.luasnip.locally_jumpable(-1) then
|
|
modules.luasnip.jump(-1)
|
|
else
|
|
fallback()
|
|
end
|
|
end, {"i","s"}),
|
|
|
|
["<C-n>"] = modules.cmp.mapping.select_next_item {behaviour = modules.cmp.SelectBehavior.Insert},
|
|
["<C-p>"] = modules.cmp.mapping.select_prev_item {behaviour = modules.cmp.SelectBehavior.Insert},
|
|
["<C-b>"] = modules.cmp.mapping.scroll_docs(-4),
|
|
["<C-f>"] = modules.cmp.mapping.scroll_docs(4),
|
|
["<C-e>"] = modules.cmp.mapping.abort(),
|
|
["<CR>"] = modules.cmp.mapping.confirm({ select = false })
|
|
}
|
|
|
|
local defaultFormat = modules.lspkind.cmp_format ({
|
|
mode = "symbol_text",
|
|
menu = {
|
|
buffer = "[BUF]",
|
|
nvim_lsp = "[LSP]",
|
|
path = "[PTH]",
|
|
luasnip = "[SNP]",
|
|
emoji = "[EMJ]",
|
|
},
|
|
maxwidth = 50,
|
|
ellipsis_char = "…"
|
|
})
|
|
|
|
modules.cmp.setup {
|
|
snippet = defaultSnippet,
|
|
sources = defaultSources,
|
|
mapping = defaultMapping,
|
|
formatting = {
|
|
format = defaultFormat
|
|
}
|
|
}
|
|
|
|
-- I'm not sure if the mappings are referenced after configuring,
|
|
-- Just in case I deepcopy them before changing things.
|
|
local mdSources = vim.deepcopy(defaultSources)
|
|
table.insert(mdSources,{ name = "emoji"} )
|
|
|
|
modules.cmp.setup.filetype('markdown',{
|
|
snippet = defaultSnippet,
|
|
sources = mdSources,
|
|
mapping = defaultMapping,
|
|
})
|
|
|
|
-- completion for searches
|
|
modules.cmp.setup.cmdline({ '/', '?' }, {
|
|
mapping = modules.cmp.mapping.preset.cmdline(),
|
|
sources = {
|
|
{ name = 'buffer' }
|
|
}
|
|
})
|
|
|
|
modules.cmp.setup.cmdline(':', {
|
|
mapping = modules.cmp.mapping.preset.cmdline(),
|
|
sources = modules.cmp.config.sources({
|
|
{ name = 'path' }
|
|
}, {
|
|
{ name = 'cmdline' }
|
|
})
|
|
})
|