-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathnvim-cmp.lua
More file actions
139 lines (129 loc) · 3.65 KB
/
nvim-cmp.lua
File metadata and controls
139 lines (129 loc) · 3.65 KB
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
local lspkind = require("lspkind")
local cmp = require("cmp")
local function sorting()
local comparators = {
cmp.config.compare.sort_text,
-- Below is the default comparitor list and order for nvim-cmp
cmp.config.compare.offset,
-- cmp.config.compare.scopes, --this is commented in nvim-cmp too
cmp.config.compare.exact,
cmp.config.compare.score,
cmp.config.compare.recently_used,
cmp.config.compare.locality,
cmp.config.compare.kind,
cmp.config.compare.length,
cmp.config.compare.order,
}
return {
priority_weight = 2,
comparators = comparators,
}
end
local menu = {
nvim_lsp = "[LSP]",
luasnip = "[Lsnip]",
path = "[Path]",
copilot = "[Copilot]",
-- buffer = "[Buffer]",
}
local lsp_ui = require("kide.lsp.lsp_ui")
cmp.setup({
enabled = function()
return vim.api.nvim_buf_get_option(0, "buftype") ~= "prompt" or require("cmp_dap").is_dap_buffer()
end,
window = {
completion = cmp.config.window.bordered({
border = lsp_ui.hover_actions.border,
winhighlight = lsp_ui.window.winhighlight,
}),
documentation = cmp.config.window.bordered({
border = lsp_ui.hover_actions.border,
winhighlight = lsp_ui.window.winhighlight,
}),
},
sorting = sorting(),
-- 指定 snippet 引擎
snippet = {
expand = function(args)
-- For `vsnip` users.
-- vim.fn["vsnip#anonymous"](args.body)
-- For `luasnip` users.
require("luasnip").lsp_expand(args.body)
-- For `ultisnips` users.
-- vim.fn["UltiSnips#Anon"](args.body)
-- For `snippy` users.
-- require'snippy'.expand_snippet(args.body)
end,
},
-- 来源
sources = cmp.config.sources({
{ name = "copilot" },
{ name = "nvim_lsp" },
-- For vsnip users.
-- { name = 'vsnip' },
-- For luasnip users.
{ name = "luasnip" },
--For ultisnips users.
-- { name = 'ultisnips' },
-- -- For snippy users.
-- { name = 'snippy' },
}, {
{ name = "path" },
{ name = "buffer" },
}),
-- 快捷键
mapping = require("kide.core.keybindings").cmp(cmp),
-- 使用lspkind-nvim显示类型图标
formatting = {
format = lspkind.cmp_format({
with_text = true, -- do not show text alongside icons
maxwidth = 50,
before = function(entry, vim_item)
-- Source 显示提示来源
vim_item.menu = lspkind.symbolic(vim_item.menu, {})
local m = vim_item.menu and vim_item.menu or ""
local ms
if entry.source.source.client and entry.source.source.client.name == "rime_ls" then
ms = "[rime]"
else
ms = menu[entry.source.name] and menu[entry.source.name] .. m or m
end
vim_item.menu = ms
-- 判断 ms 长度,如果大于40,就截取前40个字符
if #ms > 40 then
vim_item.menu = string.sub(ms, 1, 40) .. "..."
end
return vim_item
end,
}),
},
})
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ "/" }, {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "nvim_lsp_document_symbol" },
}, {
{ name = "buffer" },
}),
})
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({ "dap-repl", "dapui_watches", "dapui_hover" }, {
sources = {
{ name = "dap" },
},
})