/
cmp.lua
96 lines (84 loc) · 2.38 KB
/
cmp.lua
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
local autopairs = require('nvim-autopairs')
local handlers = require('nvim-autopairs.completion.handlers')
local cmp = require('cmp')
local Kind = cmp.lsp.CompletionItemKind
local M = {}
M.filetypes = {
-- Alias to all filetypes
["*"] = {
["("] = {
kind = { Kind.Function, Kind.Method },
handler = handlers["*"]
}
},
python = {
["("] = {
kind = { Kind.Function, Kind.Method },
handler = handlers.python
}
},
clojure = {
["("] = {
kind = { Kind.Function, Kind.Method },
handler = handlers.lisp
}
},
clojurescript = {
["("] = {
kind = { Kind.Function, Kind.Method },
handler = handlers.lisp
}
},
fennel = {
["("] = {
kind = { Kind.Function, Kind.Method },
handler = handlers.lisp
}
},
janet = {
["("] = {
kind = { Kind.Function, Kind.Method },
handler = handlers.lisp
}
},
tex = false,
plaintex = false,
context = false,
haskell = false,
purescript = false,
sh = false,
bash = false
}
M.on_confirm_done = function(opts)
opts = vim.tbl_deep_extend('force', {
filetypes = M.filetypes
}, opts or {})
return function(evt)
if evt.commit_character then
return
end
local entry = evt.entry
local commit_character = entry:get_commit_characters()
local bufnr = vim.api.nvim_get_current_buf()
local filetype = vim.api.nvim_buf_get_option(bufnr, 'filetype')
local item = entry:get_completion_item()
-- Without options and fallback
if not opts.filetypes[filetype] and not opts.filetypes["*"] then
return
end
if opts.filetypes[filetype] == false then
return
end
-- If filetype is nil then use *
local completion_options = opts.filetypes[filetype] or opts.filetypes["*"]
local rules = vim.tbl_filter(function(rule)
return completion_options[rule.key_map]
end, autopairs.get_buf_rules(bufnr))
for char, value in pairs(completion_options) do
if vim.tbl_contains(value.kind, item.kind) then
value.handler(char, item, bufnr, rules, commit_character)
end
end
end
end
return M