diff options
Diffstat (limited to '.config/nvim/lua/plugins/cmp.lua')
-rw-r--r-- | .config/nvim/lua/plugins/cmp.lua | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua index 2e8fade..097d413 100644 --- a/.config/nvim/lua/plugins/cmp.lua +++ b/.config/nvim/lua/plugins/cmp.lua | |||
@@ -3,14 +3,22 @@ return { | |||
3 | "hrsh7th/nvim-cmp", | 3 | "hrsh7th/nvim-cmp", |
4 | dependencies = { | 4 | dependencies = { |
5 | "hrsh7th/cmp-nvim-lsp", | 5 | "hrsh7th/cmp-nvim-lsp", |
6 | "hrsh7th/cmp-nvim-lsp-signature-help", | ||
6 | "hrsh7th/cmp-nvim-lua", | 7 | "hrsh7th/cmp-nvim-lua", |
7 | "hrsh7th/cmp-buffer", | 8 | "hrsh7th/cmp-buffer", |
8 | "hrsh7th/cmp-path", | 9 | "hrsh7th/cmp-path", |
9 | "hrsh7th/cmp-omni", | 10 | "hrsh7th/cmp-omni", |
10 | "hrsh7th/cmp-nvim-lsp-signature-help", | 11 | "micangl/cmp-vimtex", |
11 | "L3MON4D3/LuaSnip", | 12 | "L3MON4D3/LuaSnip", |
12 | "saadparwaiz1/cmp_luasnip", | 13 | "saadparwaiz1/cmp_luasnip", |
13 | }, | 14 | }, |
15 | opts = function(_, opts) | ||
16 | opts.sources = opts.sources or {} | ||
17 | table.insert(opts.sources, { | ||
18 | name = "lazydev", | ||
19 | group_index = 0, -- set group index to 0 to skip loading LuaLS completions | ||
20 | }) | ||
21 | end, | ||
14 | config = function() | 22 | config = function() |
15 | local cmp = require("cmp") | 23 | local cmp = require("cmp") |
16 | local luasnip = require("luasnip") | 24 | local luasnip = require("luasnip") |
@@ -45,15 +53,13 @@ return { | |||
45 | TypeParameter = "", | 53 | TypeParameter = "", |
46 | } | 54 | } |
47 | 55 | ||
48 | ---@diagnostic disable-next-line: missing-fields | ||
49 | cmp.setup({ | 56 | cmp.setup({ |
50 | enabled = function() | 57 | enabled = function() |
51 | -- disable autocompletion in telescope prompt | 58 | -- disable autocompletion in telescope prompt |
52 | local buftype = vim.api.nvim_buf_get_option(0, "buftype") | 59 | local buftype = vim.api.nvim_get_option_value("buftype", {}) |
53 | 60 | ||
54 | return buftype ~= "prompt" | 61 | return buftype ~= "prompt" |
55 | end, | 62 | end, |
56 | ---@diagnostic disable-next-line: missing-fields | ||
57 | completion = { | 63 | completion = { |
58 | completeopt = "menu,menuone,noselect", | 64 | completeopt = "menu,menuone,noselect", |
59 | }, | 65 | }, |
@@ -67,32 +73,25 @@ return { | |||
67 | end, | 73 | end, |
68 | }, | 74 | }, |
69 | mapping = cmp.mapping.preset.insert({ | 75 | mapping = cmp.mapping.preset.insert({ |
70 | ["<C-f>"] = cmp.mapping.scroll_docs(-4), | 76 | ["<C-l>"] = cmp.mapping.confirm({ |
71 | ["<C-d>"] = cmp.mapping.scroll_docs(4), | ||
72 | ["<CR>"] = cmp.mapping.confirm({ | ||
73 | behavior = cmp.ConfirmBehavior.Replace, | 77 | behavior = cmp.ConfirmBehavior.Replace, |
74 | select = false, | 78 | select = true, |
75 | }), | 79 | }), |
76 | ["<Tab>"] = cmp.mapping(function(fallback) | 80 | ["<Tab>"] = cmp.mapping(function(fallback) |
77 | if cmp.visible() then | 81 | if luasnip.locally_jumpable(1) then |
78 | cmp.select_next_item() | 82 | luasnip.jump(1) |
79 | elseif luasnip.expand_or_jumpable() then | ||
80 | luasnip.expand_or_jump() | ||
81 | else | 83 | else |
82 | fallback() | 84 | fallback() |
83 | end | 85 | end |
84 | end, { "i", "s" }), | 86 | end, { "i", "s" }), |
85 | ["<S-Tab>"] = cmp.mapping(function(fallback) | 87 | ["<S-Tab>"] = cmp.mapping(function(fallback) |
86 | if cmp.visible() then | 88 | if luasnip.locally_jumpable(-1) then |
87 | cmp.select_prev_item() | ||
88 | elseif luasnip.jumpable(-1) then | ||
89 | luasnip.jump(-1) | 89 | luasnip.jump(-1) |
90 | else | 90 | else |
91 | fallback() | 91 | fallback() |
92 | end | 92 | end |
93 | end, { "i", "s" }), | 93 | end, { "i", "s" }), |
94 | }), | 94 | }), |
95 | ---@diagnostic disable-next-line: missing-fields | ||
96 | formatting = { | 95 | formatting = { |
97 | fields = { "kind", "abbr", "menu" }, | 96 | fields = { "kind", "abbr", "menu" }, |
98 | format = function(entry, vim_item) | 97 | format = function(entry, vim_item) |
@@ -106,15 +105,18 @@ return { | |||
106 | buffer = "[ ]", | 105 | buffer = "[ ]", |
107 | path = "[ ]", | 106 | path = "[ ]", |
108 | })[entry.source.name] | 107 | })[entry.source.name] |
109 | return vim_item | 108 | -- return vim_item |
109 | return require("nvim-highlight-colors").format(entry, vim_item) | ||
110 | end, | 110 | end, |
111 | }, | 111 | }, |
112 | sources = { | 112 | sources = { |
113 | { name = "nvim_lsp" }, | 113 | { name = "nvim_lsp" }, |
114 | { name = "nvim_lsp_signature_help" }, | 114 | { name = "nvim_lua" }, |
115 | { name = "luasnip" }, | ||
116 | { name = "buffer" }, | 115 | { name = "buffer" }, |
117 | { name = "path" }, | 116 | { name = "path" }, |
117 | { name = "vimtex" }, | ||
118 | { name = "nvim_lsp_signature_help" }, | ||
119 | { name = "luasnip" }, | ||
118 | }, | 120 | }, |
119 | }) | 121 | }) |
120 | 122 | ||
@@ -126,7 +128,6 @@ return { | |||
126 | ) | 128 | ) |
127 | 129 | ||
128 | -- use omnifunc in vimwiki to complete paths and tags | 130 | -- use omnifunc in vimwiki to complete paths and tags |
129 | ---@diagnostic disable-next-line: missing-fields | ||
130 | cmp.setup.filetype('vimwiki', { | 131 | cmp.setup.filetype('vimwiki', { |
131 | sources = cmp.config.sources({ | 132 | sources = cmp.config.sources({ |
132 | { name = "omni" }, | 133 | { name = "omni" }, |
@@ -142,7 +143,7 @@ return { | |||
142 | }, | 143 | }, |
143 | { | 144 | { |
144 | 'mireq/luasnip-snippets', | 145 | 'mireq/luasnip-snippets', |
145 | dependencies = {'L3MON4D3/LuaSnip'}, | 146 | dependencies = { 'L3MON4D3/LuaSnip' }, |
146 | init = function() | 147 | init = function() |
147 | require('luasnip_snippets.common.snip_utils').setup() | 148 | require('luasnip_snippets.common.snip_utils').setup() |
148 | end | 149 | end |
@@ -166,15 +167,10 @@ return { | |||
166 | -- Required to automatically include base snippets, like "c" snippets for "cpp" | 167 | -- Required to automatically include base snippets, like "c" snippets for "cpp" |
167 | load_ft_func = require('luasnip_snippets.common.snip_utils').load_ft_func, | 168 | load_ft_func = require('luasnip_snippets.common.snip_utils').load_ft_func, |
168 | ft_func = require('luasnip_snippets.common.snip_utils').ft_func, | 169 | ft_func = require('luasnip_snippets.common.snip_utils').ft_func, |
169 | -- To enable auto expansin | 170 | -- To enable auto expansion |
170 | enable_autosnippets = true, | 171 | enable_autosnippets = true, |
171 | -- Uncomment to enable visual snippets triggered using <c-x> | ||
172 | -- store_selection_keys = '<c-x>', | ||
173 | }) | 172 | }) |
174 | -- LuaSnip key bindings | 173 | require("luasnip.loaders.from_lua").lazy_load({ paths = "./lua/luasnippets" }) |
175 | vim.keymap.set({"i", "s"}, "<C-l>", function() if ls.expand_or_jumpable() then ls.expand_or_jump() else vim.api.nvim_input('<C-l>') end end, {silent = true}) | ||
176 | vim.keymap.set({"i", "s"}, "<C-k>", function() ls.jump(-1) end, {silent = true}) | ||
177 | vim.keymap.set({"i", "s"}, "<C-E>", function() if ls.choice_active() then ls.change_choice(1) end end, {silent = true}) | ||
178 | end | 174 | end |
179 | 175 | ||
180 | }, | 176 | }, |