2024-06-12 19:36:30 +00:00
|
|
|
local utils = require("utils")
|
|
|
|
local M = {}
|
|
|
|
|
2024-11-13 18:09:16 +00:00
|
|
|
-- Accept copilot suggestion
|
2024-06-12 19:36:30 +00:00
|
|
|
function M.copilot_accept()
|
|
|
|
local suggest = vim.fn["copilot#GetDisplayedSuggestion"]()
|
|
|
|
if next(suggest.item) ~= nil then
|
|
|
|
return vim.fn["copilot#Accept"]("\\<CR>")
|
|
|
|
else
|
|
|
|
return utils.t("<Right>")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-11-13 18:09:16 +00:00
|
|
|
function M.setup()
|
|
|
|
-- Replace keymap for copilot to accept with <C-F> and <Right>, similar to fish shell
|
2024-06-12 19:36:30 +00:00
|
|
|
vim.g.copilot_no_tab_map = false
|
|
|
|
utils.keymap_set("i", "<C-F>", M.copilot_accept, { expr = true, replace_keycodes = false, noremap = true })
|
|
|
|
utils.keymap_set("i", "<Right>", M.copilot_accept, { expr = true, replace_keycodes = false, noremap = true })
|
2024-11-13 18:09:16 +00:00
|
|
|
|
|
|
|
-- Create autocmd to disable copilot for certain filetypes that may contain sensitive information
|
|
|
|
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
|
|
|
|
pattern = { ".env*", "*secret*", "*API_KEY*", "*TOKEN*" },
|
|
|
|
command = "let b:copilot_enabled = 0",
|
|
|
|
group = vim.api.nvim_create_augroup("CopilotDisable", {
|
|
|
|
clear = true,
|
|
|
|
}),
|
|
|
|
})
|
2024-06-12 19:36:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
M.setup()
|
|
|
|
|
|
|
|
return M
|