Files
nvim-config/lua/completion.lua
2025-09-14 00:12:07 -04:00

185 lines
4.8 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
end,
},
formatting = {
format = function(entry, vim_item)
-- Ensure word is a string to prevent matcher errors
if vim_item.word and type(vim_item.word) ~= "string" then
vim_item.word = tostring(vim_item.word)
end
return vim_item
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<C-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" }),
}),
sources = cmp.config.sources({
{ name = "nvim_lua" },
-- { name = "copilot", group_index = 3 },
{ name = "nvim_lsp", group_index = 1 },
{ name = "path", group_index = 3 },
{ name = "luasnip", group_index = 2 },
{ name = "buffer" },
{ name = "calc" },
{ name = 'orgmode' },
-- { name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
{ name = "crates" },
-- { name = 'cmdline' },
-- { name = 'neorg' },
}),
})
-- Set configuration for specific filetype.
cmp.setup.filetype("gitcommit", {
sources = cmp.config.sources({
{ name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = "buffer" },
}),
})
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ "/", "?" }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" },
{ name = "cmdline" },
},
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
})
-- Set up lspconfig.
-- require("cmp_nvim_lsp").default_capabilities()
local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
-- require('lspconfig')['<YOUR_LSP_SERVER>'].setup {
-- capabilities = capabilities
-- }
require("lspconfig").clangd.setup({
capabilities = capabilities,
})
require("lspconfig").taplo.setup({
capabilities = capabilities,
})
require("lspconfig").marksman.setup({
capabilities = capabilities,
})
require("lspconfig").lua_ls.setup({
capabilities = capabilities,
})
require("lspconfig").rust_analyzer.setup({
capabilities = capabilities,
})
require("lspconfig").zls.setup({
capabilities = capabilities,
})
require("lspconfig").gopls.setup({
capabilities = capabilities,
settings = {
gopls = {
analyses = {
unusedparams = true,
unusedwrite = true,
shadow = true,
},
staticcheck = true,
usePlaceholders = true,
hints = {
assignVariableTypes = true,
compositeLiteralFields = true,
compositeLiteralTypes = true,
functionTypeParameters = true,
parameterNames = true,
rangeVariableTypes = true,
},
},
},
})
require("lspconfig").pyright.setup({
capabilities = capabilities,
settings = {
python = {
analysis = {
typeCheckingMode = "basic",
autoSearchPaths = true,
useLibraryCodeForTypes = true,
diagnosticMode = "workspace",
stubPath = "./typings",
},
},
},
})
require("lspconfig").nim_langserver.setup({
capabilities = capabilities,
})
-- require'lspconfig'.jedi_language_server.setup {
-- capabilities = capabilities,
-- }
require("lsp_signature").setup({
debug = false,
bind = true, -- registers signature handler
doc_lines = 10,
max_height = 12,
max_width = function() return math.floor(vim.api.nvim_win_get_width(0) * 0.8) end,
wrap = true,
floating_window = true, -- show the popup
floating_window_above_cur_line = true,
floating_window_off_x = 1,
floating_window_off_y = 0,
-- IMPORTANT: dont inline (you can change later if you want)
hint_enable = true,
hint_inline = function() return false end,
hint_prefix = "🐼 ",
hint_scheme = "String",
hi_parameter = "LspSignatureActiveParameter",
handler_opts = { border = "rounded" },
always_trigger = false,
extra_trigger_chars = { "(", "," }, -- good default
zindex = 200,
padding = "",
timer_interval = 200,
})