-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmp.nix
199 lines (190 loc) · 5.45 KB
/
cmp.nix
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
{
plugins = {
cmp-buffer.enable = true;
cmp-cmdline.enable = true;
cmp-emoji.enable = true;
cmp-nvim-lsp.enable = true;
cmp-nvim-lsp-document-symbol.enable = true;
cmp-nvim-lsp-signature-help.enable = true;
cmp-path.enable = true;
cmp_luasnip.enable = true;
cmp-treesitter.enable = true;
cmp-git.enable = true;
cmp-npm.enable = true;
cmp = {
enable = true;
luaConfig.pre = ''
require("cmp-npm").setup({})
'';
settings = {
autoEnableSources = true;
experimental = {
ghost_text = {
hl_group = "CmpGhostText";
};
};
performance = {
debounce = 150;
fetchingTimeout = 500;
maxViewEntries = 30;
};
snippet.expand =
# lua
''
function(args)
require('luasnip').lsp_expand(args.body)
end
'';
sources = [
{name = "nvim_lsp_signature_help";}
{
name = "npm";
keyword_length = 4;
}
{
name = "path";
keywordLength = 3;
}
{name = "emoji";}
{name = "treesitter";}
{
name = "luasnip";
keywordLength = 3;
}
{
name = "buffer";
option.get_bufnrs.__raw = "vim.api.nvim_list_bufs";
keywordLength = 3;
}
];
formatting = {
fields = ["abbr" "kind" "menu"];
};
completion = {
completeopt = "menu,menuone,noinsert";
};
window = {
completion = {
scrollbar = false;
sidePadding = 0;
border = "rounded";
};
settings.documentation = {
border = "rounded";
};
};
mapping = {
"<C-n>" = "cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert })";
"<C-p>" = "cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert })";
"<Down>" = "cmp.mapping.select_next_item()";
"<Up>" = "cmp.mapping.select_prev_item()";
"<C-j>" = "cmp.mapping.select_next_item()";
"<C-k>" = "cmp.mapping.select_prev_item()";
"<C-d>" = "cmp.mapping.scroll_docs(-4)";
"<C-f>" = "cmp.mapping.scroll_docs(4)";
"<C-Space>" = "cmp.mapping.complete()";
"<C-e>" = "cmp.mapping.close()";
"<CR>" =
# lua
''
cmp.mapping(function(fallback)
if cmp.visible() then
if require("luasnip").expandable() then
require("luasnip").expand()
else
cmp.confirm({select = true})
end
else
fallback()
end
end)
'';
"<S-CR>" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })";
"<C-CR>" =
# lua
''
function(fallback)
cmp.abort()
fallback()
end
'';
"<Tab>" =
# lua
''
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif require("luasnip").expand_or_locally_jumpable() then
require("luasnip").expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s"})
'';
"<S-Tab>" =
# lua
''
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif require("luasnip").locally_jumpable(-1) then
require("luasnip").jump(-1)
else
fallback()
end
end, { "i", "s" })
'';
};
};
};
};
extraConfigLuaPre =
# lua
''
function has_words_before()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local cmp = require("cmp")
'';
extraConfigLua =
# lua
''
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
-- 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' },
}
)
})
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',
options = { ignore_cmds = { 'Man', '!' } }
},
}
),
})
'';
}