diff options
| author | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2022-07-09 14:35:02 +0200 |
|---|---|---|
| committer | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2022-07-09 14:35:02 +0200 |
| commit | b65f8c6c939139d5aeafef381517f894608ef518 (patch) | |
| tree | c8e0c81d3b2e141992088e25f07fcfd37804fdf1 /after/plugin | |
| parent | afd9b1b96861f1148b34f2007ec33fab9b6e2190 (diff) | |
| download | nvim-conf-b65f8c6c939139d5aeafef381517f894608ef518.tar.gz nvim-conf-b65f8c6c939139d5aeafef381517f894608ef518.zip | |
some improvements
Diffstat (limited to 'after/plugin')
| -rw-r--r-- | after/plugin/completition.lua | 205 |
1 files changed, 115 insertions, 90 deletions
diff --git a/after/plugin/completition.lua b/after/plugin/completition.lua index 9d1e4e9..8b260d2 100644 --- a/after/plugin/completition.lua +++ b/after/plugin/completition.lua @@ -1,106 +1,131 @@ local ok, cmp = pcall(require, "cmp") if not ok then - return + return end -local lspkind = require "lspkind" -local luasnip = require "luasnip" -local cmp_autopairs = require "nvim-autopairs.completion.cmp" +local lspkind = require("lspkind") +local luasnip = require("luasnip") +local cmp_autopairs = require("nvim-autopairs.completion.cmp") -cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })) +cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({ map_char = { tex = "" } })) -cmp.setup { - mapping = { - ["<C-d>"] = cmp.mapping.scroll_docs(-4), - ["<C-f>"] = cmp.mapping.scroll_docs(4), - ["<C-e>"] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.close() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { "i", "s" }), - ["<C-n>"] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.choice_active() then - luasnip.change_choice(1) - else - fallback() - end - end, { "i", "s" }), - ["<C-p>"] = cmp.mapping.select_prev_item(), - ["<C-y>"] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Insert, - select = true, - }, - ["<c-space>"] = cmp.mapping.complete(), - }, - sources = { - { name = "nvim_lua" }, - { name = "nvim_lsp" }, - { name = "path" }, - { name = "luasnip" }, - { - name = "buffer", - keyword_length = 5, - option = { - get_bufnrs = function() - local bufs = {} - for _, win in ipairs(vim.api.nvim_list_wins()) do - bufs[vim.api.nvim_win_get_buf(win)] = true - end - return vim.tbl_keys(bufs) - end - } - }, - }, +cmp.setup({ + mapping = { + ["<C-d>"] = cmp.mapping.scroll_docs(-4), + ["<C-f>"] = cmp.mapping.scroll_docs(4), + ["<C-e>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.close() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + ["<C-n>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.choice_active() then + luasnip.change_choice(1) + else + fallback() + end + end, { "i", "s" }), + ["<C-p>"] = cmp.mapping.select_prev_item(), + ["<C-y>"] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }), + ["<c-space>"] = cmp.mapping.complete(), + }, + sources = { + { name = "nvim_lua" }, + { name = "nvim_lsp" }, + { name = "path" }, + { name = "luasnip" }, + { + name = "buffer", + keyword_length = 5, + option = { + get_bufnrs = function() + local bufs = {} + for _, win in ipairs(vim.api.nvim_list_wins()) do + bufs[vim.api.nvim_win_get_buf(win)] = true + end + return vim.tbl_keys(bufs) + end, + }, + }, + }, - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, - formatting = { - format = lspkind.cmp_format { - with_text = true, - menu = { - buffer = "[buf]", - nvim_lsp = "[LSP]", - nvim_lua = "[api]", - path = "[path]", - luasnip = "[snip]", - ["vim-dadbod-completion"] = "[DB]", - } - } - }, + formatting = { + format = lspkind.cmp_format({ + with_text = true, + menu = { + buffer = "[buf]", + nvim_lsp = "[LSP]", + nvim_lua = "[api]", + path = "[path]", + luasnip = "[snip]", + ["vim-dadbod-completion"] = "[DB]", + }, + }), + }, - experimental = { - native_menu = false, + experimental = { + native_menu = false, - ghost_text = true, - } -} + ghost_text = true, + }, +}) -vim.api.nvim_create_autocmd( - "FileType", - { - pattern = "sql,mysql,plsql", - callback = function() - require('cmp').setup.buffer({ sources = {{ name = 'vim-dadbod-completion' }} }) - end - } -) +-- 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 `/` (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline("/", { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer" }, + }, +}) + +-- 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" }, + }), +}) + +cmp.setup.filetype({ "sql", "mysql", "plsql" }, { + sources = cmp.config.sources({ + { name = "vim-dadbod-completion" }, + }, { + { name = "buffer" }, + }), +}) -- Setup lspconfig. - local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) - -- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled. - require('lspconfig')['emmet_ls'].setup { - capabilities = capabilities - } +local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) +-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled. +require("lspconfig")["emmet_ls"].setup({ + capabilities = capabilities, +}) local Group = require("colorbuddy.group").Group local g = require("colorbuddy.group").groups |