1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
local cmp = require "cmp"
local lspkind = require "lspkind"
local luasnip = require "luasnip"
local cmp_autopairs = require "nvim-autopairs.completion.cmp"
local compare = require "cmp.config.compare"
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = { tex = "" } })
cmp.setup {
window = {
completion = {
border = "rounded",
-- winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None',
-- winblend = vim.o.pumblend,
-- scrolloff = 0,
-- col_offset = 0,
-- side_padding = 1,
-- scrollbar = true,
},
documentation = {
-- max_height = math.floor(WIDE_HEIGHT * (WIDE_HEIGHT / vim.o.lines)),
-- max_width = math.floor((WIDE_HEIGHT * 2) * (vim.o.columns / (WIDE_HEIGHT * 2 * 16 / 9))),
border = "rounded",
-- winhighlight = 'FloatBorder:NormalFloat',
-- winblend = vim.o.pumblend,
},
},
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-l>"] = cmp.mapping.select_next_item(),
["<C-y>"] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Insert,
select = true,
},
["<c-space>"] = cmp.mapping.complete(),
},
sources = {
{ name = "dictionary" },
{ name = "nvim_lua" },
{ name = "nvim_lsp" },
{ name = "path" },
{ name = "luasnip" },
{ name = "copilot" },
{
name = "buffer",
keyword_length = 4,
option = {
get_bufnrs = function()
local bufs = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
local bufnr = vim.api.nvim_win_get_buf(win)
if vim.api.nvim_buf_get_option(bufnr, "buftype") ~= "terminal" then
bufs[bufnr] = true
end
end
return vim.tbl_keys(bufs)
end,
},
},
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
formatting = {
format = function (entry, vim_item)
lspkind.cmp_format {
with_text = true,
menu = {
buffer = "[buf]",
nvim_lsp = "[ ]",
nvim_lua = "[api]",
path = "[path]",
luasnip = "[snip]",
copilot = "[ﮧ ]",
["vim-dadbod-completion"] = "[DB]",
},
}
local KIND_ICONS = {
Tailwind = '',
Color = ' ',
-- Class = 7,
-- Constant = '',
-- Constructor = 4,
-- Enum = 13,
-- EnumMember = 20,
-- Event = 23,
-- Field = 5,
-- File = 17,
-- Folder = 19,
-- Function = 3,
-- Interface = 8,
-- Keyword = 14,
-- Method = 2,
-- Module = 9,
-- Operator = 24,
-- Property = 10,
-- Reference = 18,
Snippet = " ",
-- Struct = 22,
-- Text = "",
-- TypeParameter = 25,
-- Unit = 11,
-- Value = 12,
-- Variable = 6
}
if vim_item.kind == 'Color' and entry.completion_item.documentation then
local _, _, r, g, b =
---@diagnostic disable-next-line: param-type-mismatch
string.find(entry.completion_item.documentation, '^rgb%((%d+), (%d+), (%d+)')
if r and g and b then
local color = string.format('%02x', r) .. string.format('%02x', g) .. string.format('%02x', b)
local group = 'Tw_' .. color
if vim.api.nvim_call_function('hlID', { group }) < 1 then
vim.api.nvim_command('highlight' .. ' ' .. group .. ' ' .. 'guifg=#' .. color)
end
vim_item.kind = KIND_ICONS.Tailwind
vim_item.kind_hl_group = group
return vim_item
end
end
vim_item.kind = KIND_ICONS[vim_item.kind] or vim_item.kind
return vim_item
end
},
sorting = {
priority_weight = 2,
comparators = {
compare.kind,
compare.sort_text,
},
},
experimental = {
native_menu = false,
ghost_text = false,
},
}
vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" })
-- 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" },
}),
})
|