Repository navigation
Expand file tree
/
Copy pathcmp.lua
More file actions
84 lines (80 loc) · 3.18 KB
/
Copy pathcmp.lua
File metadata and controls
84 lines (80 loc) · 3.18 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
-- =============================================================================
-- AUTOCOMPLETE SETTINGS (CMP)
-- =============================================================================
-- Sets up the popup menu for autocomplete suggestions.
-- Combines recommendations from the active LSP server, open buffer contents,
-- file paths, and snippet expansions.
-- =============================================================================
return {
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-nvim-lsp", -- source: LSP suggestions
"hrsh7th/cmp-buffer", -- source: text within current file
"hrsh7th/cmp-path", -- source: file system paths
"L3MON4D3/LuaSnip", -- snippet engine
"saadparwaiz1/cmp_luasnip", -- adapter to bind luasnip into cmp
},
config = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered({
winhighlight = "Normal:Normal,FloatBorder:FloatBorder,CursorLine:Visual,Search:None",
}),
documentation = cmp.config.window.bordered({
winhighlight = "Normal:Normal,FloatBorder:FloatBorder,CursorLine:Visual,Search:None",
}),
},
mapping = cmp.mapping.preset.insert({
-- Move down in the completion menu
["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
-- Move up in the completion menu
["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
-- Scroll docs window
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
-- Close completion menu
["<C-e>"] = cmp.mapping.abort(),
-- Confirm selection (CR / Enter)
["<CR>"] = cmp.mapping.confirm({ select = true }),
-- Tab navigation behavior
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
-- Shift-Tab navigation behavior
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
sources = cmp.config.sources({
{ name = "copilot", priority = 1000 }, -- Copilot completions (when enabled)
{ name = "nvim_lsp", priority = 900 }, -- LSP completions
{ name = "luasnip", priority = 750 }, -- snippets
{ name = "path", priority = 500 }, -- file path autocomplete
}, {
{ name = "buffer", priority = 250 }, -- buffer words
}),
})
end,
},
}