-
Notifications
You must be signed in to change notification settings - Fork 31
/
cmp.nix
192 lines (185 loc) · 4.28 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
{ config, lib, ... }:
let
get_bufnrs.__raw = ''
function()
local buf_size_limit = 1024 * 1024 -- 1MB size limit
local bufs = vim.api.nvim_list_bufs()
local valid_bufs = {}
for _, buf in ipairs(bufs) do
if vim.api.nvim_buf_is_loaded(buf) and vim.api.nvim_buf_get_offset(buf, vim.api.nvim_buf_line_count(buf)) < buf_size_limit then
table.insert(valid_bufs, buf)
end
end
return valid_bufs
end
'';
in
{
plugins = {
cmp = {
enable = false;
autoEnableSources = true;
settings = {
mapping = {
"<C-d>" = # Lua
"cmp.mapping.scroll_docs(-4)";
"<C-f>" = # Lua
"cmp.mapping.scroll_docs(4)";
"<C-Space>" = # Lua
"cmp.mapping.complete()";
"<C-e>" = # Lua
"cmp.mapping.close()";
"<Tab>" = # Lua
"cmp.mapping(cmp.mapping.select_next_item({behavior = cmp.SelectBehavior.Select}), {'i', 's'})";
"<S-Tab>" = # Lua
"cmp.mapping(cmp.mapping.select_prev_item({behavior = cmp.SelectBehavior.Select}), {'i', 's'})";
"<CR>" = # Lua
"cmp.mapping.confirm({ select = false, behavior = cmp.ConfirmBehavior.Replace })";
};
preselect = # Lua
"cmp.PreselectMode.None";
snippet.expand = # Lua
"function(args) require('luasnip').lsp_expand(args.body) end";
sources = [
{
name = "nvim_lsp";
priority = 1000;
option = {
inherit get_bufnrs;
};
}
{
name = "nvim_lsp_signature_help";
priority = 1000;
option = {
inherit get_bufnrs;
};
}
{
name = "gitlab";
priority = 1000;
option = {
hosts = [ "https://gitlab.dnm.radiofrance.fr" ];
};
}
{
name = "nvim_lsp_document_symbol";
priority = 1000;
option = {
inherit get_bufnrs;
};
}
{
name = "treesitter";
priority = 850;
option = {
inherit get_bufnrs;
};
}
{
name = "luasnip";
priority = 750;
}
{
name = "buffer";
priority = 500;
option = {
inherit get_bufnrs;
};
}
{
name = "copilot";
priority = 400;
}
{
name = "rg";
priority = 300;
}
{
name = "path";
priority = 300;
}
{
name = "cmdline";
priority = 300;
}
{
name = "spell";
priority = 300;
}
{
name = "git";
priority = 250;
}
{
name = "zsh";
priority = 250;
}
{
name = "calc";
priority = 150;
}
{
name = "emoji";
priority = 100;
}
];
};
};
friendly-snippets.enable = true;
luasnip.enable = true;
lspkind = {
enable = true;
cmp = {
enable = true;
menu = {
buffer = "";
calc = "";
cmdline = "";
codeium = "";
emoji = "";
git = "";
luasnip = "";
neorg = "";
nvim_lsp = "";
nvim_lua = "";
path = "";
spell = "";
treesitter = "";
};
};
};
};
keymaps = lib.mkIf config.plugins.cmp.enable [
{
mode = [
"i"
"s"
];
key = "<C-k>";
action.__raw = ''
function()
local ls = require "luasnip"
if ls.expand_or_jumpable() then
ls.expand_or_jump()
end
end
'';
}
{
mode = [
"i"
"s"
];
key = "<C-j>";
action.__raw = ''
function()
local ls = require "luasnip"
if ls.jumpable(-1) then
ls.jump(-1)
end
end
'';
}
];
}