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
|
local lsp = require("tobyvin.lsp")
local M = {}
M.enabled = function()
local ctx = require("cmp.config.context")
local enabled = require("cmp.config.default")().enabled() or require("cmp_dap").is_dap_buffer()
if vim.api.nvim_get_mode().mode ~= "c" then
enabled = enabled and not ctx.in_treesitter_capture("comment")
enabled = enabled and not ctx.in_syntax_group("Comment")
end
return enabled
end
M.expand_snip = function(args)
require("luasnip").lsp_expand(args.body)
end
M.setup = function()
local status_ok, cmp = pcall(require, "cmp")
if not status_ok then
vim.notify("Failed to load module 'cmd'", vim.log.levels.ERROR)
return
end
lsp.configs.default = vim.tbl_extend("force", lsp.configs.default, {
capabilities = require("cmp_nvim_lsp").default_capabilities(),
})
cmp.setup({
enabled = M.enabled,
snippet = {
expand = M.expand_snip,
},
mapping = cmp.mapping.preset.cmdline({
["<C-p>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "s" }),
["<C-n>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "s" }),
["<S-Tab>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "s" }),
["<Tab>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "s" }),
["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "s" }),
["<C-u>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "s" }),
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "s" }),
["<C-e>"] = cmp.mapping(cmp.mapping.close(), { "i", "s" }),
["<CR>"] = cmp.mapping(
cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
-- select = true,
}),
{ "i", "s" }
),
}),
ghost_text = true,
sources = {
{ name = "nvim_lsp", group_index = 1 },
{ name = "nvim_lua", group_index = 1 },
{ name = "path", group_index = 1 },
{ name = "luasnip", group_index = 1 },
{ name = "dap", group_index = 1 },
{ name = "buffer", keyword_length = 3, group_index = 2 },
},
})
cmp.setup.filetype({ "tex", "bib" }, {
sources = {
{ name = "latex_symbols" },
},
})
cmp.setup.filetype("gitcommit", {
sources = {
{ name = "git" },
{ name = "commit" },
{ name = "conventionalcommits" },
},
})
cmp.setup.filetype("json", {
sources = {
{ name = "npm" },
},
})
cmp.setup.filetype("toml", {
sources = {
{ name = "crates" },
},
})
cmp.setup.cmdline(":", {
sources = {
{ name = "cmdline_history", max_item_count = 10 },
{ name = "cmdline", max_item_count = 10 },
},
})
cmp.setup.cmdline("/", {
sources = {
{ name = "buffer", max_item_count = 10 },
{ name = "cmdline_history", max_item_count = 10 },
},
})
cmp.setup.cmdline("?", {
sources = {
{ name = "buffer", max_item_count = 10 },
{ name = "cmdline_history", max_item_count = 10 },
},
})
cmp.setup.cmdline("@", {
sources = {
{ name = "cmdline_history", max_item_count = 10 },
},
})
end
return M
|