2024-01-12 14:19:26 +01:00
|
|
|
-- setting error signs
|
2024-01-11 15:46:01 +01:00
|
|
|
local function sign_define(args)
|
|
|
|
vim.fn.sign_define(args.name, {
|
|
|
|
texthl = args.name,
|
|
|
|
text = args.text,
|
|
|
|
numhl = "",
|
|
|
|
})
|
|
|
|
end
|
2023-12-24 12:06:23 +01:00
|
|
|
|
2024-01-11 15:46:01 +01:00
|
|
|
sign_define({ name = "DiagnosticSignError", text = "E" })
|
|
|
|
sign_define({ name = "DiagnosticSignWarn", text = "W" })
|
|
|
|
sign_define({ name = "DiagnosticSignHint", text = "H" })
|
|
|
|
sign_define({ name = "DiagnosticSignInfo", text = "I" })
|
2023-12-24 12:06:23 +01:00
|
|
|
|
2024-01-11 15:46:01 +01:00
|
|
|
-- diagnostic's aren't lsp dependent
|
|
|
|
vim.keymap.set("n", "<leader>vd", function()
|
|
|
|
vim.diagnostic.open_float()
|
|
|
|
end)
|
|
|
|
vim.keymap.set("n", "[d", function()
|
|
|
|
vim.diagnostic.goto_next()
|
|
|
|
end)
|
|
|
|
vim.keymap.set("n", "]d", function()
|
|
|
|
vim.diagnostic.goto_prev()
|
2023-12-24 12:06:23 +01:00
|
|
|
end)
|
|
|
|
|
2024-01-11 19:55:04 +01:00
|
|
|
-- lsp capabilites enabler
|
2024-01-11 15:46:01 +01:00
|
|
|
vim.api.nvim_create_autocmd("LspAttach", {
|
|
|
|
desc = "LSP Actions",
|
|
|
|
callback = function(event)
|
2024-01-11 19:55:04 +01:00
|
|
|
-- Enable omnifunc
|
2024-01-12 14:19:35 +01:00
|
|
|
-- vim.bo[event.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
|
2024-01-11 19:55:04 +01:00
|
|
|
|
|
|
|
-- Buffer local mappings
|
2024-01-11 15:46:01 +01:00
|
|
|
local opts = { buffer = event.buf }
|
|
|
|
vim.keymap.set("n", "K", function()
|
|
|
|
vim.lsp.buf.hover()
|
|
|
|
end, opts)
|
|
|
|
vim.keymap.set("n", "gd", function()
|
|
|
|
vim.lsp.buf.definition()
|
|
|
|
end, opts)
|
|
|
|
vim.keymap.set("n", "gD", function()
|
|
|
|
vim.lsp.buf.declaration()
|
|
|
|
end, opts)
|
|
|
|
vim.keymap.set("n", "gi", function()
|
|
|
|
vim.lsp.buf.implementation()
|
|
|
|
end, opts)
|
|
|
|
vim.keymap.set("n", "<leader>lca", function()
|
|
|
|
vim.lsp.buf.code_action()
|
|
|
|
end, opts)
|
|
|
|
vim.keymap.set("n", "<leader>lrn", function()
|
|
|
|
vim.lsp.buf.rename()
|
|
|
|
end, opts)
|
|
|
|
vim.keymap.set("i", "<C-h>", function()
|
|
|
|
vim.lsp.buf.signature_help()
|
|
|
|
end, opts)
|
|
|
|
end,
|
2023-12-24 12:06:23 +01:00
|
|
|
})
|
2023-12-24 14:19:45 +01:00
|
|
|
|
2024-01-12 14:20:14 +01:00
|
|
|
local lsp_capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
|
|
|
|
local default_setup = function(server)
|
|
|
|
require("lspconfig")[server].setup({
|
|
|
|
capabilities = lsp_capabilities,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2024-01-11 15:46:01 +01:00
|
|
|
-- setup mason and automatically install some language server's
|
2023-12-24 14:19:45 +01:00
|
|
|
require("mason").setup({})
|
|
|
|
require("mason-lspconfig").setup({
|
2024-01-11 15:46:01 +01:00
|
|
|
ensure_installed = { "lua_ls", "jsonls", "bashls", "pyright", "marksman", "gopls", "clangd" },
|
2024-01-12 14:20:14 +01:00
|
|
|
handlers = { default_setup },
|
2024-01-11 15:46:01 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
-- setup haskell language server manually cause it doesn't work with mason for xmonad
|
2024-01-12 14:20:14 +01:00
|
|
|
require("lspconfig").hls.setup({ capabilities = lsp_capabilities })
|
|
|
|
|
|
|
|
-- simple completion setup with snippet support
|
|
|
|
local cmp = require("cmp")
|
2024-01-11 15:46:01 +01:00
|
|
|
|
2024-01-12 14:20:14 +01:00
|
|
|
cmp.setup({
|
|
|
|
sources = {
|
|
|
|
{ name = "nvim_lsp" },
|
|
|
|
{ name = "snippy" },
|
|
|
|
{ name = "path" },
|
|
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert({
|
|
|
|
["<C-l>"] = cmp.mapping.confirm({ select = false }),
|
|
|
|
["<C-j>"] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible then
|
|
|
|
cmp.select_next_item()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "s" }),
|
|
|
|
["<C-k>"] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible then
|
|
|
|
cmp.select_prev_item()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "s" }),
|
|
|
|
}),
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
require("snippy").expand_snippet(args.body)
|
|
|
|
end,
|
2023-12-24 19:46:29 +01:00
|
|
|
},
|
2024-01-12 14:20:14 +01:00
|
|
|
formatting = {
|
|
|
|
format = require("lspkind").cmp_format({
|
|
|
|
mode = "symbol_text", -- show only symbol annotations
|
|
|
|
maxwidth = 50, -- prevent the popup from showing more than provided characters
|
|
|
|
ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
enabled = function()
|
|
|
|
-- disable completion in comments
|
|
|
|
local context = require("cmp.config.context")
|
|
|
|
return not context.in_treesitter_capture("comment") and not context.in_syntax_group("Comment")
|
|
|
|
end,
|
2023-12-24 14:19:45 +01:00
|
|
|
})
|