Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add setting for copilot enable or not. #930

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ settings["format_on_save"] = true
---@type boolean
settings["format_notify"] = true

-- Set it to false if you don't use copilot
---@type boolean
settings["use_copilot"] = true

-- Set it to false if diagnostics virtual text is annoying.
-- If disabled, you may browse lsp diagnostics using trouble.nvim (press `gt` to toggle it).
---@type boolean
Expand Down
53 changes: 36 additions & 17 deletions lua/modules/configs/completion/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,9 @@ return function()
return (diff < 0)
end

local cmp = require("cmp")
cmp.setup({
preselect = cmp.PreselectMode.Item,
window = {
completion = {
border = border("PmenuBorder"),
winhighlight = "Normal:Pmenu,CursorLine:PmenuSel,Search:PmenuSel",
scrollbar = false,
},
documentation = {
border = border("CmpDocBorder"),
winhighlight = "Normal:CmpDoc",
},
},
sorting = {
priority_weight = 2,
comparators = {
local use_copilot = require("core.settings").use_copilot
local comparators = use_copilot == true
and {
require("copilot_cmp.comparators").prioritize,
require("copilot_cmp.comparators").score,
-- require("cmp_tabnine.compare"),
Expand All @@ -64,8 +50,41 @@ return function()
compare.kind,
compare.length,
compare.order,
}
or {
-- require("cmp_tabnine.compare"),
compare.offset, -- Items closer to cursor will have lower priority
compare.exact,
-- compare.scopes,
compare.lsp_scores,
compare.sort_text,
compare.score,
compare.recently_used,
-- compare.locality, -- Items closer to cursor will have higher priority, conflicts with `offset`
require("cmp-under-comparator").under,
compare.kind,
compare.length,
compare.order,
}

local cmp = require("cmp")
cmp.setup({
preselect = cmp.PreselectMode.Item,
window = {
completion = {
border = border("PmenuBorder"),
winhighlight = "Normal:Pmenu,CursorLine:PmenuSel,Search:PmenuSel",
scrollbar = false,
},
documentation = {
border = border("CmpDocBorder"),
winhighlight = "Normal:CmpDoc",
},
},
sorting = {
priority_weight = 2,
comparators = comparators,
},
formatting = {
fields = { "abbr", "kind", "menu" },
format = function(entry, vim_item)
Expand Down
25 changes: 14 additions & 11 deletions lua/modules/plugins/completion.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local completion = {}
local use_copilot = require("core.settings").use_copilot

completion["neovim/nvim-lspconfig"] = {
lazy = true,
Expand Down Expand Up @@ -64,17 +65,19 @@ completion["hrsh7th/nvim-cmp"] = {
-- },
},
}
completion["zbirenbaum/copilot.lua"] = {
lazy = true,
cmd = "Copilot",
event = "InsertEnter",
config = require("completion.copilot"),
dependencies = {
{
"zbirenbaum/copilot-cmp",
config = require("completion.copilot-cmp"),
if use_copilot then
completion["zbirenbaum/copilot.lua"] = {
lazy = true,
cmd = "Copilot",
event = "InsertEnter",
config = require("completion.copilot"),
dependencies = {
{
"zbirenbaum/copilot-cmp",
config = require("completion.copilot-cmp"),
},
},
},
}
}
end

return completion