dotfiles/.config/nvim/lua/tsousa/plugins/lsp.lua

242 lines
8.9 KiB
Lua
Raw Normal View History

2024-01-27 18:23:43 +00:00
return {
{
2024-02-03 23:06:03 +00:00
'hrsh7th/nvim-cmp',
2024-01-27 18:23:43 +00:00
dependencies = {
2024-02-04 18:05:23 +00:00
'hrsh7th/cmp-nvim-lsp', -- lsp
'hrsh7th/cmp-nvim-lua', -- Nvim API completions
'hrsh7th/cmp-buffer', --buffer completions
'hrsh7th/cmp-path', --path completions
'hrsh7th/cmp-cmdline', --cmdline completions
2024-02-03 00:10:19 +00:00
'saadparwaiz1/cmp_luasnip',
2024-01-27 18:23:43 +00:00
'L3MON4D3/LuaSnip',
2024-02-03 00:10:19 +00:00
'onsails/lspkind.nvim',
2024-02-03 23:06:03 +00:00
'zbirenbaum/copilot.lua',
'zbirenbaum/copilot-cmp',
2024-01-27 18:23:43 +00:00
},
config = function()
local cmp_status_ok, cmp = pcall(require, "cmp")
if not cmp_status_ok then
return
end
local snip_status_ok, luasnip = pcall(require, "luasnip")
if not snip_status_ok then
return
end
2024-02-03 00:10:19 +00:00
local ok, lspkind = pcall(require, "lspkind")
if not ok then
return
end
2024-02-03 23:06:03 +00:00
-- this is to make copilot-cmp work better
require("copilot").setup({
suggestion = { enabled = false },
panel = { enabled = false },
})
require("copilot_cmp").setup()
2024-02-03 00:10:19 +00:00
lspkind.init {
symbol_map = {
Copilot = "",
},
}
vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" })
2024-01-27 18:23:43 +00:00
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"
end
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body) -- For `luasnip` users.
end,
},
mapping = {
2024-02-03 00:10:19 +00:00
["<C-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
["<C-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
["<C-e>"] = cmp.mapping.abort(),
["<C-y>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true
},
{ "i", "c" }
),
2024-01-27 18:23:43 +00:00
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
2024-02-03 00:10:19 +00:00
2024-01-27 18:23:43 +00:00
["<C-k>"] = cmp.mapping(function(fallback)
if luasnip.expandable() then
luasnip.expand()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif check_backspace() then
fallback()
else
fallback()
end
end),
["<C-j>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end
),
},
formatting = {
2024-02-03 00:10:19 +00:00
-- fields = { "kind", "abbr", "menu" },
format = lspkind.cmp_format {
with_text = true,
menu = {
buffer = "[buf]",
nvim_lsp = "[lsp]",
2024-02-03 23:06:03 +00:00
copilot = "[cop]",
2024-02-03 00:10:19 +00:00
luasnip = "[snip]",
nvim_lsp_signature_help = "[sig]",
nvim_lua = "[lua]",
path = "[path]",
},
},
2024-01-27 18:23:43 +00:00
},
sources = cmp.config.sources(
{
2024-02-03 00:10:19 +00:00
{ name = "nvim_lsp", },
{ name = 'nvim_lua' },
2024-02-03 23:06:03 +00:00
{ name = "copilot" },
2024-01-27 18:23:43 +00:00
{ name = 'luasnip' },
2024-02-03 00:10:19 +00:00
--{ name = 'nvim_lsp_signature_help' },
2024-01-27 18:23:43 +00:00
{ name = 'orgmode' }
},
{
--This sources will only show up if there aren't any sources from the other list
2024-02-03 00:10:19 +00:00
{ name = 'path' },
2024-01-27 18:23:43 +00:00
{ name = "buffer", keyword_length = 5 },
}
),
2024-02-03 00:10:19 +00:00
sorting = {
comparators = {
cmp.config.compare.offset,
cmp.config.compare.exact,
cmp.config.compare.score,
-- copied from cmp-under, but I don't think I need the plugin for this.
-- I might add some more of my own.
function(entry1, entry2)
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
return false
elseif entry1_under < entry2_under then
return true
end
end,
2024-01-27 18:23:43 +00:00
2024-02-03 00:10:19 +00:00
cmp.config.compare.kind,
cmp.config.compare.sort_text,
cmp.config.compare.length,
cmp.config.compare.order,
},
2024-01-27 18:23:43 +00:00
},
2024-02-03 00:10:19 +00:00
experimental = {
2024-02-03 23:06:03 +00:00
ghost_text = true,
2024-02-03 00:10:19 +00:00
native_menu = false,
},
2024-01-27 18:23:43 +00:00
}
end,
},
{
"neovim/nvim-lspconfig",
dependencies = {
"hrsh7th/nvim-cmp",
2024-01-27 18:23:43 +00:00
"williamboman/mason-lspconfig.nvim",
"williamboman/mason.nvim",
2024-01-29 00:38:04 +00:00
"j-hui/fidget.nvim",
2024-01-27 18:23:43 +00:00
},
config = function()
2024-02-04 18:05:23 +00:00
require("fidget").setup({
notification = {
window = {
winblend = 0,
}
}
})
2024-02-08 15:03:11 +00:00
2024-01-27 18:23:43 +00:00
vim.api.nvim_create_augroup("_mason", { clear = true })
require("mason").setup({
PATH = "skip",
ui = {
icons = {
2024-02-08 15:03:11 +00:00
package_installed = "",
package_pending = "󱥸",
package_uninstalled = ""
}
2024-01-27 18:23:43 +00:00
},
max_concurrent_installers = 10,
})
2024-01-29 00:38:04 +00:00
local mason_lspconfig = require("mason-lspconfig")
2024-01-27 18:23:43 +00:00
local lspconfig = require("lspconfig")
-- ADD NVIM CMP AS A CAPABILITY
local lsp_defaults = lspconfig.util.default_config
local capabilities = vim.tbl_deep_extend(
'force',
lsp_defaults.capabilities,
require('cmp_nvim_lsp').default_capabilities()
)
-- keybinds for diagnostics
vim.keymap.set('n', '<leader>vd', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
2024-02-08 15:03:11 +00:00
-- external (non mason) lsps
lspconfig.rust_analyzer.setup({
on_init = on_init,
flags = lsp_flags,
capabilities = capabilities,
cmd = {
"rustup", "run", "stable", "rust-analyzer",
}
})
2024-01-27 18:23:43 +00:00
mason_lspconfig.setup({
2024-01-29 00:38:04 +00:00
ensure_installed = {
2024-02-08 15:03:11 +00:00
lua_ls,
2024-01-29 00:38:04 +00:00
},
automatic_installation = true,
handlers = {
function(server_name)
lspconfig[server_name].setup({
on_init = on_init,
flags = lsp_flags,
capabilities = capabilities,
})
end,
-- add here other custom overrides
["lua_ls"] = function()
lspconfig.lua_ls.setup({
settings = {
Lua = {
diagnostics = { globals = { "vim" } }
}
}
})
end,
}
2024-01-27 18:23:43 +00:00
})
end
2024-01-29 00:38:04 +00:00
},
2024-01-27 18:23:43 +00:00
}