Skip to content

Commit 80bc15f

Browse files
authored
refactor(cmp): streamline copilot integration (#1499)
Signed-off-by: Jint-lzxy <[email protected]>
1 parent 5e9d2ff commit 80bc15f

File tree

2 files changed

+29
-46
lines changed

2 files changed

+29
-46
lines changed

lua/modules/configs/completion/cmp.lua

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,23 @@ return function()
2929
return (diff < 0)
3030
end
3131

32-
local use_copilot = require("core.settings").use_copilot
33-
local comparators = use_copilot == true
34-
and {
35-
require("copilot_cmp.comparators").prioritize,
36-
require("copilot_cmp.comparators").score,
37-
compare.offset, -- Items closer to cursor will have lower priority
38-
compare.exact,
39-
-- compare.scopes,
40-
compare.lsp_scores,
41-
compare.sort_text,
42-
compare.score,
43-
compare.recently_used,
44-
-- compare.locality, -- Items closer to cursor will have higher priority, conflicts with `offset`
45-
require("cmp-under-comparator").under,
46-
compare.kind,
47-
compare.length,
48-
compare.order,
49-
}
50-
or {
51-
compare.offset, -- Items closer to cursor will have lower priority
52-
compare.exact,
53-
-- compare.scopes,
54-
compare.lsp_scores,
55-
compare.sort_text,
56-
compare.score,
57-
compare.recently_used,
58-
-- compare.locality, -- Items closer to cursor will have higher priority, conflicts with `offset`
59-
require("cmp-under-comparator").under,
60-
compare.kind,
61-
compare.length,
62-
compare.order,
63-
}
32+
local comparators = vim.list_extend(require("core.settings").use_copilot and {
33+
require("copilot_cmp.comparators").prioritize,
34+
require("copilot_cmp.comparators").score,
35+
} or {}, {
36+
compare.offset, -- Items closer to cursor will have lower priority
37+
compare.exact,
38+
-- compare.scopes,
39+
compare.lsp_scores,
40+
compare.sort_text,
41+
compare.score,
42+
compare.recently_used,
43+
-- compare.locality, -- Items closer to cursor will have higher priority, conflicts with `offset`
44+
require("cmp-under-comparator").under,
45+
compare.kind,
46+
compare.length,
47+
compare.order,
48+
})
6449

6550
local cmp = require("cmp")
6651
require("modules.utils").load_plugin("cmp", {

lua/modules/plugins/completion.lua

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
local completion = {}
2-
local use_copilot = require("core.settings").use_copilot
32

43
completion["neovim/nvim-lspconfig"] = {
54
lazy = true,
@@ -64,19 +63,18 @@ completion["hrsh7th/nvim-cmp"] = {
6463
{ "kdheepak/cmp-latex-symbols" },
6564
},
6665
}
67-
if use_copilot then
68-
completion["zbirenbaum/copilot.lua"] = {
69-
lazy = true,
70-
cmd = "Copilot",
71-
event = "InsertEnter",
72-
config = require("completion.copilot"),
73-
dependencies = {
74-
{
75-
"zbirenbaum/copilot-cmp",
76-
config = require("completion.copilot-cmp"),
77-
},
66+
completion["zbirenbaum/copilot.lua"] = {
67+
lazy = true,
68+
cond = require("core.settings").use_copilot,
69+
cmd = "Copilot",
70+
event = "InsertEnter",
71+
config = require("completion.copilot"),
72+
dependencies = {
73+
{
74+
"zbirenbaum/copilot-cmp",
75+
config = require("completion.copilot-cmp"),
7876
},
79-
}
80-
end
77+
},
78+
}
8179

8280
return completion

0 commit comments

Comments
 (0)