wip: copilot.lua
This commit is contained in:
@@ -1,29 +1,79 @@
|
|||||||
local now_if_args = vim.fn.argc(-1) > 0 and MiniDeps.now or MiniDeps.later
|
MiniDeps.later(function()
|
||||||
|
MiniDeps.add("zbirenbaum/copilot.lua")
|
||||||
|
-- TODO:(@janezicmatej) setup lsp nes
|
||||||
|
-- MiniDeps.add("copilotlsp-nvim/copilot-lsp")
|
||||||
|
|
||||||
now_if_args(function()
|
local function no_attach_for_env()
|
||||||
MiniDeps.add("github/copilot.vim")
|
if string.match(vim.fs.basename(vim.api.nvim_buf_get_name(0)), "^%.env.*") then
|
||||||
|
return false
|
||||||
vim.g.copilot_filetypes = {
|
end
|
||||||
-- disable all and only allow specific filetyps
|
return true
|
||||||
["*"] = false,
|
|
||||||
--
|
|
||||||
c = true,
|
|
||||||
cpp = true,
|
|
||||||
dockerfile = true,
|
|
||||||
go = true,
|
|
||||||
javascript = true,
|
|
||||||
lua = true,
|
|
||||||
nix = true,
|
|
||||||
python = true,
|
|
||||||
rust = true,
|
|
||||||
sh = true,
|
|
||||||
typescript = true,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- remap default <M-\> to first close pumenu if open
|
|
||||||
local function suggest()
|
|
||||||
if vim.fn.pumvisible() == 1 then vim.fn.complete(vim.fn.col("."), {}) end
|
|
||||||
return vim.fn["copilot#Suggest"]()
|
|
||||||
end
|
end
|
||||||
vim.keymap.set("i", "<M-\\>", suggest)
|
|
||||||
|
local opts = {
|
||||||
|
panel = {
|
||||||
|
keymap = {
|
||||||
|
jump_prev = false,
|
||||||
|
jump_next = false,
|
||||||
|
accept = false,
|
||||||
|
refresh = false,
|
||||||
|
open = false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
suggestion = {
|
||||||
|
-- auto_trigger = true,
|
||||||
|
keymap = {
|
||||||
|
accept = false,
|
||||||
|
accept_word = false,
|
||||||
|
accept_line = false,
|
||||||
|
next = false,
|
||||||
|
prev = false,
|
||||||
|
dismiss = false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
filetypes = {
|
||||||
|
-- disable all and only allow specific filetyps
|
||||||
|
["*"] = false,
|
||||||
|
--
|
||||||
|
c = true,
|
||||||
|
cpp = true,
|
||||||
|
dockerfile = true,
|
||||||
|
go = true,
|
||||||
|
javascript = true,
|
||||||
|
lua = true,
|
||||||
|
nix = true,
|
||||||
|
python = true,
|
||||||
|
rust = true,
|
||||||
|
sh = no_attach_for_env,
|
||||||
|
bash = no_attach_for_env,
|
||||||
|
typescript = true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
require("copilot").setup(opts)
|
||||||
|
|
||||||
|
local suggestion = require("copilot.suggestion")
|
||||||
|
|
||||||
|
local function accept_if_visible()
|
||||||
|
vim.notify("is visible " .. (suggestion.is_visible() or "nil"))
|
||||||
|
if suggestion.is_visible() ~= nil then
|
||||||
|
suggestion.accept()
|
||||||
|
else
|
||||||
|
return "<Tab>"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function close_pum_if_open(func)
|
||||||
|
return function()
|
||||||
|
if vim.fn.pumvisible() == 1 then vim.fn.complete(vim.fn.col("."), {}) end
|
||||||
|
return func()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- stylua: ignore start
|
||||||
|
vim.keymap.set({ "i" }, "<Tab>", accept_if_visible, { desc = "copilot: accept suggestion", expr = true })
|
||||||
|
vim.keymap.set({ "n", "i" }, "<M-j>", suggestion.accept_line, { desc = "copilot: accept line" })
|
||||||
|
|
||||||
|
vim.keymap.set({ "n", "i" }, "<M-l>", close_pum_if_open(suggestion.next), { desc = "copilot: next suggestion" })
|
||||||
|
vim.keymap.set({ "n", "i" }, "<M-h>", close_pum_if_open(suggestion.prev), { desc = "copilot: previous suggestion" })
|
||||||
|
-- stylua: ignore start
|
||||||
end)
|
end)
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
return {
|
return {
|
||||||
["copilot.vim"] = "da369d90cfd6c396b1d0ec259836a1c7222fb2ea",
|
["copilot.lua"] = "3123983d00ae6859f8bc987d14ebb524bb41b618",
|
||||||
["fzf-lua"] = "db3ccffe79480543d8e0f7b0cac0d9b220f9486e",
|
["fzf-lua"] = "db3ccffe79480543d8e0f7b0cac0d9b220f9486e",
|
||||||
["gitlinker.nvim"] = "cc59f732f3d043b626c8702cb725c82e54d35c25",
|
["gitlinker.nvim"] = "cc59f732f3d043b626c8702cb725c82e54d35c25",
|
||||||
["gitsigns.nvim"] = "1ee5c1fd068c81f9dd06483e639c2aa4587dc197",
|
["gitsigns.nvim"] = "1ee5c1fd068c81f9dd06483e639c2aa4587dc197",
|
||||||
|
Reference in New Issue
Block a user