chore(nvim): a bunch of things
This commit is contained in:
parent
9d8f5b9f53
commit
b375840efb
13 changed files with 513 additions and 377 deletions
|
@ -10,10 +10,23 @@ end
|
|||
require("luasnip/loaders/from_vscode").lazy_load()
|
||||
|
||||
local check_backspace = function()
|
||||
local col = vim.fn.col "." - 1
|
||||
return col == 0 or vim.fn.getline("."):sub(col, col):match "%s"
|
||||
local col = vim.fn.col(".") - 1
|
||||
return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
|
||||
end
|
||||
|
||||
local lspkind_status_ok, lspkind = pcall(require, "lspkind")
|
||||
if not lspkind_status_ok then
|
||||
return
|
||||
end
|
||||
|
||||
cmp.event:on("menu_opened", function()
|
||||
vim.b.copilot_suggestion_hidden = true
|
||||
end)
|
||||
|
||||
cmp.event:on("menu_closed", function()
|
||||
vim.b.copilot_suggestion_hidden = false
|
||||
end)
|
||||
|
||||
-- some other good icons
|
||||
local kind_icons = {
|
||||
Text = "",
|
||||
|
@ -46,26 +59,27 @@ local kind_icons = {
|
|||
}
|
||||
-- find more here: https://www.nerdfonts.com/cheat-sheet
|
||||
|
||||
cmp.setup {
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body) -- For `luasnip` users.
|
||||
end,
|
||||
},
|
||||
mapping = {
|
||||
["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
|
||||
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
|
||||
["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
|
||||
["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
|
||||
["<C-u>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-d>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-e>"] = cmp.mapping.abort(),
|
||||
["<C-y>"] = cmp.mapping(
|
||||
cmp.mapping.confirm({
|
||||
behavior = cmp.ConfirmBehavior.Insert,
|
||||
select = true,
|
||||
}),
|
||||
{ "i", "c" }
|
||||
),
|
||||
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
|
||||
["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
|
||||
["<C-e>"] = cmp.mapping {
|
||||
i = cmp.mapping.abort(),
|
||||
c = cmp.mapping.close(),
|
||||
},
|
||||
-- Accept currently selected item. If none selected, do nothing.
|
||||
["<CR>"] = cmp.mapping.confirm {
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = false
|
||||
},
|
||||
["<C-k>"] = cmp.mapping(function(fallback)
|
||||
if luasnip.expandable() then
|
||||
luasnip.expand()
|
||||
|
@ -83,47 +97,29 @@ cmp.setup {
|
|||
else
|
||||
fallback()
|
||||
end
|
||||
end
|
||||
),
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, {
|
||||
"i",
|
||||
"s",
|
||||
}),
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, {
|
||||
"i",
|
||||
"s",
|
||||
}),
|
||||
end),
|
||||
},
|
||||
formatting = {
|
||||
fields = { "kind", "abbr", "menu" },
|
||||
format = function(entry, vim_item)
|
||||
-- Kind icons
|
||||
-- if vim.tbl_contains({ "nvim_lsp" }, entry.source.name) then
|
||||
-- tailwind = require("tailwindcss-colorizer-cmp")
|
||||
-- return tailwind.formatter(entry, vim_item)
|
||||
-- else
|
||||
vim_item.kind = string.format('[%s %s]', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind
|
||||
vim_item.menu = ({
|
||||
nvim_lsp = "[LSP]",
|
||||
["vim-dadbod-completion"] = "[]",
|
||||
nvim_lua = "[LSP]",
|
||||
path = "[Path]",
|
||||
})[entry.source.name]
|
||||
return vim_item
|
||||
-- end
|
||||
end,
|
||||
format = lspkind.cmp_format({
|
||||
mode = "symbol_text", -- show only symbol annotations
|
||||
maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
|
||||
-- can also be a function to dynamically calculate max width such as
|
||||
-- maxwidth = function() return math.floor(0.45 * vim.o.columns) end,
|
||||
ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
|
||||
show_labelDetails = true, -- show labelDetails in menu. Disabled by default
|
||||
|
||||
-- The function below will be called before any actual modifications from lspkind
|
||||
-- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
|
||||
before = function(entry, vim_item)
|
||||
vim_item.menu = ({
|
||||
nvim_lsp = "[LSP]",
|
||||
nvim_lua = "[LSP]",
|
||||
path = "[Path]",
|
||||
})[entry.source.name]
|
||||
return vim_item
|
||||
end,
|
||||
}),
|
||||
},
|
||||
sorting = {
|
||||
comparators = {
|
||||
|
@ -133,8 +129,8 @@ cmp.setup {
|
|||
|
||||
--Make entries that start with underline appear after
|
||||
function(entry1, entry2)
|
||||
local _, entry1_under = entry1.completion_item.label:find "^_+"
|
||||
local _, entry2_under = entry2.completion_item.label:find "^_+"
|
||||
local _, entry1_under = entry1.completion_item.label:find("^_+")
|
||||
local _, entry2_under = entry2.completion_item.label:find("^_+")
|
||||
entry1_under = entry1_under or 0
|
||||
entry2_under = entry2_under or 0
|
||||
if entry1_under > entry2_under then
|
||||
|
@ -143,51 +139,17 @@ cmp.setup {
|
|||
return true
|
||||
end
|
||||
end,
|
||||
}
|
||||
},
|
||||
sources = cmp.config.sources(
|
||||
{
|
||||
{
|
||||
name = "nvim_lsp",
|
||||
entry_filter = function(entry, context)
|
||||
local kind = entry:get_kind()
|
||||
vim.api.nvim_out_write(kind .. '\n')
|
||||
if kind == "Text" then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
},
|
||||
|
||||
{ name = 'orgmode' },
|
||||
{ name = 'nvim_lua' },
|
||||
{ name = 'luasnip' },
|
||||
--{ name = "vim-dadbod-completion" },
|
||||
{ name = "path" },
|
||||
},
|
||||
{
|
||||
--This sources will only show up if there aren't any sources from the other list
|
||||
{ name = "buffer", keyword_length = 5 },
|
||||
}
|
||||
),
|
||||
confirm_opts = {
|
||||
behavior = cmp.ConfirmBehavior.Replace,
|
||||
select = false,
|
||||
},
|
||||
window = {
|
||||
documentation = cmp.config.window.bordered(),
|
||||
completion = cmp.config.window.bordered({
|
||||
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None"
|
||||
})
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "nvim_lua" },
|
||||
{ name = "luasnip" },
|
||||
{ name = "path" },
|
||||
}, {
|
||||
{ name = "buffer", keyword_length = 5 },
|
||||
}),
|
||||
})
|
||||
|
||||
},
|
||||
experimental = {
|
||||
ghost_text = false,
|
||||
native_menu = false,
|
||||
},
|
||||
}
|
||||
|
||||
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
|
||||
cmp.event:on(
|
||||
'confirm_done',
|
||||
cmp_autopairs.on_confirm_done()
|
||||
)
|
||||
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
|
||||
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue