From 25db33aa81caa54f71a05a8307d6f6794a9c09ab Mon Sep 17 00:00:00 2001 From: CronyAkatsuki Date: Fri, 12 Jan 2024 14:20:14 +0100 Subject: [PATCH] Brought cmp back untile nvim 0.10 and mini.snippet --- after/plugin/lsp.lua | 70 ++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index 099f941..8592ec4 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -56,31 +56,65 @@ vim.api.nvim_create_autocmd("LspAttach", { end, }) +local lsp_capabilities = require("cmp_nvim_lsp").default_capabilities() + +local default_setup = function(server) + require("lspconfig")[server].setup({ + capabilities = lsp_capabilities, + }) +end + -- setup mason and automatically install some language server's require("mason").setup({}) require("mason-lspconfig").setup({ ensure_installed = { "lua_ls", "jsonls", "bashls", "pyright", "marksman", "gopls", "clangd" }, -}) - --- automatically setup already installed lsp's -require("mason-lspconfig").setup_handlers({ - function(server_name) - require("lspconfig")[server_name].setup({}) - end, + handlers = { default_setup }, }) -- setup haskell language server manually cause it doesn't work with mason for xmonad -require("lspconfig").hls.setup({}) +require("lspconfig").hls.setup({ capabilities = lsp_capabilities }) --- autocompletion using mini.completion -require("mini.completion").setup({ - lsp_completion = { - source_func = "omnifunc", - auto_setup = false, +-- simple completion setup with snippet support +local cmp = require("cmp") + +cmp.setup({ + sources = { + { name = "nvim_lsp" }, + { name = "snippy" }, + { name = "path" }, }, - fallback_action = "", + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.confirm({ select = false }), + [""] = cmp.mapping(function(fallback) + if cmp.visible then + cmp.select_next_item() + else + fallback() + end + end, { "i", "s" }), + [""] = 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, + }, + 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, }) - --- bind ctrl j and k to move beetwen completion items -vim.keymap.set("i", "", [[pumvisible() ? "\" : "\"]], { expr = true }) -vim.keymap.set("i", "", [[pumvisible() ? "\" : "\"]], { expr = true })