@@ -2,24 +2,58 @@ return {
2
2
" hrsh7th/nvim-cmp" ,
3
3
event = " InsertEnter" ,
4
4
dependencies = {
5
- " hrsh7th/cmp-buffer" , -- source for text in buffer
6
- " hrsh7th/cmp-path" , -- source for file system paths
7
- " L3MON4D3/LuaSnip" , -- snippet engine
8
- " saadparwaiz1/cmp_luasnip" , -- for autocompletion
9
- " rafamadriz/friendly-snippets" , -- useful snippets
10
- " onsails/lspkind.nvim" , -- vs-code like pictograms
11
- " zbirenbaum/copilot.lua" , -- copilot
12
- " zbirenbaum/copilot-cmp" ,
5
+ " hrsh7th/cmp-buffer" ,
6
+ " hrsh7th/cmp-path" ,
7
+ " hrsh7th/cmp-cmdline" ,
13
8
" petertriho/cmp-git" ,
9
+ " onsails/lspkind.nvim" ,
10
+ {
11
+ " saadparwaiz1/cmp_luasnip" ,
12
+ dependencies = {
13
+ {
14
+ " L3MON4D3/LuaSnip" ,
15
+ build = " make install_jsregexp" ,
16
+ dependencies = { " rafamadriz/friendly-snippets" },
17
+ },
18
+ }
19
+ },
20
+ {
21
+ " zbirenbaum/copilot-cmp" ,
22
+ dependencies = { " zbirenbaum/copilot.lua" }
23
+ },
14
24
},
15
25
config = function ()
16
26
local cmp = require (" cmp" )
17
27
local luasnip = require (" luasnip" )
18
28
local lspkind = require (" lspkind" )
19
- require (" copilot_cmp" ).setup ()
20
29
require (" cmp_git" ).setup ()
21
30
require (" luasnip.loaders.from_vscode" ).lazy_load ()
22
31
32
+ require (' copilot' ).setup ({
33
+ suggestion = { enabled = false },
34
+ panel = { enabled = false },
35
+ filetypes = {
36
+ [" " ] = false ,
37
+ commit = false ,
38
+ cvs = false ,
39
+ git = false ,
40
+ gitcommit = false ,
41
+ gitrebase = false ,
42
+ gitsendmail = false ,
43
+ help = false ,
44
+ hgcommit = false ,
45
+ man = false ,
46
+ markdown = false ,
47
+ md = false ,
48
+ mkd = false ,
49
+ svn = false ,
50
+ tex = false ,
51
+ text = false ,
52
+ yaml = false ,
53
+ },
54
+ })
55
+
56
+ require (" copilot_cmp" ).setup ()
23
57
-- Setup copilot icon in lspkind
24
58
lspkind .init ({
25
59
symbol_map = {
@@ -46,34 +80,44 @@ return {
46
80
[" <C-e>" ] = cmp .mapping .abort (), -- close completion window
47
81
[" <CR>" ] = cmp .mapping .confirm ({ select = false }),
48
82
}),
49
- -- sources for autocompletion
50
83
sources = cmp .config .sources ({
51
84
{ name = " copilot" , group_index = 2 , max_item_count = 3 },
52
85
{ name = " nvim_lsp" , group_index = 2 },
53
86
{ name = " luasnip" }, -- snippets
54
- { name = " buffer" }, -- text within current buffer
55
87
{ name = " path" }, -- file system paths
88
+ {
89
+ name = ' buffer' ,
90
+ option = {
91
+ get_bufnrs = function ()
92
+ local bufs = {}
93
+ for _ , win in ipairs (vim .api .nvim_list_wins ()) do
94
+ bufs [vim .api .nvim_win_get_buf (win )] = true
95
+ end
96
+ return vim .tbl_keys (bufs )
97
+ end
98
+ }
99
+ }
56
100
}),
57
101
-- configure lspkind for vs-code like pictograms in completion menu
58
102
formatting = {
59
103
format = lspkind .cmp_format ({
60
- maxwidth = 50 ,
104
+ maxwidth = 80 ,
61
105
ellipsis_char = " ..." ,
62
106
}),
63
107
},
64
108
sorting = {
65
109
priority_weight = 2 ,
66
110
comparators = {
67
111
require (" copilot_cmp.comparators" ).prioritize ,
68
- cmp .config .compare .offset ,
69
- cmp .config .compare .exact ,
70
- cmp .config .compare .sort_text ,
71
- cmp .config .compare .score ,
72
- cmp .config .compare .recently_used ,
73
- cmp .config .compare .locality ,
74
- cmp .config .compare .kind ,
75
- cmp .config .compare .length ,
76
- cmp .config .compare .order ,
112
+ cmp .config .compare .offset ,
113
+ cmp .config .compare .exact ,
114
+ cmp .config .compare .sort_text ,
115
+ cmp .config .compare .score ,
116
+ cmp .config .compare .recently_used ,
117
+ cmp .config .compare .locality ,
118
+ cmp .config .compare .kind ,
119
+ cmp .config .compare .length ,
120
+ cmp .config .compare .order ,
77
121
},
78
122
},
79
123
window = {
@@ -85,23 +129,53 @@ return {
85
129
cmp .setup .filetype (' gitcommit' , {
86
130
sources = cmp .config .sources ({
87
131
{ name = ' git' },
88
- }, {
89
132
{ name = ' buffer' },
90
133
})
91
134
})
135
+
136
+ -- This doesn't work while using the cmd window. See below
137
+ --[[
92
138
cmp.setup.cmdline({ '/', '?' }, {
93
139
mapping = cmp.mapping.preset.cmdline(),
94
- sources = {
140
+ sources = cmp.config.sources( {
95
141
{ name = 'buffer' }
96
- }
142
+ })
97
143
})
144
+
98
145
cmp.setup.cmdline(':', {
99
146
mapping = cmp.mapping.preset.cmdline(),
100
147
sources = cmp.config.sources({
101
- { name = ' path' }
102
- }, {
148
+ { name = 'path' },
103
149
{ name = 'cmdline' }
104
150
})
105
151
})
152
+ ]] --
153
+
154
+ -- Hack to get cmp to work in command window https://github.com/hrsh7th/cmp-cmdline/pull/61#issuecomment-1243380455
155
+ vim .api .nvim_create_augroup (' CMP' , { clear = true })
156
+ vim .api .nvim_create_autocmd (' CmdwinEnter' , {
157
+ group = ' CMP' ,
158
+ pattern = ' *' ,
159
+ callback = function ()
160
+ cmp .setup .buffer ({
161
+ sources = cmp .config .sources ({
162
+ { name = ' cmdline' },
163
+ { name = ' path' },
164
+ {
165
+ name = ' buffer' ,
166
+ option = {
167
+ get_bufnrs = function ()
168
+ local bufs = {}
169
+ for _ , win in ipairs (vim .api .nvim_list_wins ()) do
170
+ bufs [vim .api .nvim_win_get_buf (win )] = true
171
+ end
172
+ return vim .tbl_keys (bufs )
173
+ end
174
+ }
175
+ },
176
+ })
177
+ })
178
+ end
179
+ })
106
180
end
107
181
}
0 commit comments