feat(nvim): copilot chat

chore: remove old alias
This commit is contained in:
2024-02-03 13:15:25 +02:00
parent 12a8b93311
commit 4f55d43e7e
5 changed files with 116 additions and 42 deletions

View File

@@ -1,26 +0,0 @@
return {
"zbirenbaum/copilot.lua",
dependencies = {
"zbirenbaum/copilot-cmp",
},
config = function()
-- See https://github.com/zbirenbaum/copilot.lua
require("copilot_cmp").setup({
filetypes = {
yaml = true,
markdown = true,
help = false,
gitcommit = true,
gitrebase = false,
hgcommit = false,
svn = false,
cvs = false,
["."] = false,
},
})
require("copilot").setup({
suggestion = { enabled = false },
panel = { enabled = false },
})
end,
}

View File

@@ -1,4 +1,105 @@
local keymap = {
['<leader>cc'] = {
name = "CopilotChat",
c = {
function()
local input = vim.fn.input("Ask Copilot: ")
if input ~= "" then
vim.cmd("CopilotChat " .. input)
end
end,
"Chat",
mode = { "x" },
},
e = { "<cmd>CopilotChatInPlace<CR>", "Edit with instruction", mode = { "n", "v" } },
t = { "<cmd>CopilotChatTests<CR>", "Generate tests", mode = { "n", "v" } },
v = { "<cmd>CopilotChatVisual<CR>", "Open in vertical split", mode = "x" },
a = { "<cmd>CopilotChatAutocmd<CR>", "Autocmd", mode = { "n", "v" } },
m = { "<cmd>CopilotChatMapping<CR>", "Map", mode = { "n", "v" } },
x = { "<cmd>CopilotChatExplain<CR>", "Explain code", mode = { "n", "v" } },
r = { "<cmd>CopilotChatReview<CR>", "Review", mode = { "n", "v" } },
f = { "<cmd>CopilotChatRefactor<CR>", "Refactor", mode = { "n", "v" } },
}
}
local keys = {}
for key, tbl in pairs(keymap["<leader>cc"]) do
if type(tbl) == "table" and key ~= 'c' then
local cmd = tbl[1]
local desc = tbl[2]
local mode = tbl.mode
local out = {
"<leader>cc" .. key,
cmd,
desc = '[CopilotChat] ' .. desc,
mode = mode,
}
-- print(key, vim.inspect(out))
table.insert(keys, out)
end
end
return {
{
"zbirenbaum/copilot.lua",
dependencies = {
"zbirenbaum/copilot-cmp",
},
config = function()
-- See https://github.com/zbirenbaum/copilot.lua
require("copilot_cmp").setup({
filetypes = {
yaml = true,
markdown = true,
help = false,
gitcommit = true,
gitrebase = false,
hgcommit = false,
svn = false,
cvs = false,
["."] = false,
},
})
require("copilot").setup({
suggestion = { enabled = false },
panel = { enabled = false },
})
end,
},
-- NOTE:
-- on new machine, run:
-- pip3 install python-dotenv requests pynvim==0.5.0 prompt-toolkit tiktoken
{
"jellydn/CopilotChat.nvim",
dependencies = { "zbirenbaum/copilot.lua" }, -- Or { "github/copilot.vim" }
opts = {
show_help = "yes", -- Show help text for CopilotChatInPlace, default: yes
debug = true, -- Enable or disable debug mode, the log file will be in ~/.local/state/nvim/CopilotChat.nvim.log
prompts = {
Explain = "Explain how it works.",
Review = "Review the following code and provide concise suggestions.",
Tests = "Briefly explain how the selected code works, then generate unit tests.",
Refactor = "Refactor the code to improve clarity and readability.",
},
},
build = function()
vim.notify("Please update the remote plugins by running ':UpdateRemotePlugins', then restart Neovim.")
end,
config = function()
require('CopilotChat').setup({
show_help = "yes", -- Show help text for CopilotChatInPlace, default: yes
debug = false, -- Enable or disable debug mode, the log file will be in ~/.local/state/nvim/CopilotChat.nvim.log
prompts = {
Explain = "Explain how the selected code works, provide any documetation references or links.",
Review = "Review the following code and provide concise suggestions.",
Tests = "Briefly explain how the selected code works, then generate unit tests.",
Refactor = "Refactor the code to improve clarity and readability.",
},
})
require('which-key').register(keymap)
end,
event = "VeryLazy",
keys = keys,
},
{
"Exafunction/codeium.nvim",
dependencies = {
@@ -17,9 +118,9 @@ return {
api_key_cmd = os.getenv("OPENAI_API_KEY"),
})
require('which-key').register {
['<leader>c'] = {
['<leader>cC'] = {
name = "ChatGPT",
c = { "<cmd>ChatGPT<CR>", "ChatGPT" },
c = { "<cmd>ChatGPT<CR>", "Chat" },
e = { "<cmd>ChatGPTEditWithInstruction<CR>", "Edit with instruction", mode = { "n", "v" } },
g = { "<cmd>ChatGPTRun grammar_correction<CR>", "Grammar Correction", mode = { "n", "v" } },
t = { "<cmd>ChatGPTRun translate<CR>", "Translate", mode = { "n", "v" } },

View File

@@ -102,7 +102,6 @@ alias hlog="home git log"
alias hiv="hi; vim ."
alias hv="pushd \$(wd path df); vi .; popd"
alias spider="ssh root@spider.casraf.dev"
alias spider-new="ssh root@spider-new.casraf.dev"
# docker
alias de="docker-exec"

View File

@@ -21,9 +21,9 @@
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^20.11.11",
"@types/node": "^20.11.16",
"cosmiconfig": "^9.0.0",
"massarg": "2.0.0-pre.13",
"massarg": "2.0.0",
"prettier": "^3.2.4",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"

22
utils/pnpm-lock.yaml generated
View File

@@ -6,20 +6,20 @@ settings:
dependencies:
'@types/node':
specifier: ^20.11.11
version: 20.11.11
specifier: ^20.11.16
version: 20.11.16
cosmiconfig:
specifier: ^9.0.0
version: 9.0.0(typescript@5.3.3)
massarg:
specifier: 2.0.0-pre.13
version: 2.0.0-pre.13
specifier: 2.0.0
version: 2.0.0
prettier:
specifier: ^3.2.4
version: 3.2.4
ts-node:
specifier: ^10.9.2
version: 10.9.2(@types/node@20.11.11)(typescript@5.3.3)
version: 10.9.2(@types/node@20.11.16)(typescript@5.3.3)
typescript:
specifier: ^5.3.3
version: 5.3.3
@@ -87,8 +87,8 @@ packages:
resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==}
dev: false
/@types/node@20.11.11:
resolution: {integrity: sha512-PlJCXfb57Jrman0H1BxO2+Q7qwih2Mwk7T6Gvixj+SK4mqs4RWOGMMoP6p/LFa3UrP2CZOO6ai6otd7J/TB6Ug==}
/@types/node@20.11.16:
resolution: {integrity: sha512-gKb0enTmRCzXSSUJDq6/sPcqrfCv2mkkG6Jt/clpn5eiCbKTY+SgZUxo+p8ZKMof5dCp9vHQUAB7wOUTod22wQ==}
dependencies:
undici-types: 5.26.5
dev: false
@@ -224,8 +224,8 @@ packages:
resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==}
dev: false
/massarg@2.0.0-pre.13:
resolution: {integrity: sha512-FxMll+PROyVLR12eKCq+Gh4ym1deqVc32+yrHJqeC+04m3WcP5gz8Y+APe8sDtq83oYXUdkR2Fgk6uGl7QElhA==}
/massarg@2.0.0:
resolution: {integrity: sha512-oeB1dT/e4K3GBCPmUPwPXybeZbjrAnjsoMWSqshlfs4ndkeNdyxEHr6UAf0bkZMu3pqxT/QqembAM4nrUcPrAQ==}
dependencies:
zod: 3.22.4
dev: false
@@ -265,7 +265,7 @@ packages:
has-flag: 3.0.0
dev: false
/ts-node@10.9.2(@types/node@20.11.11)(typescript@5.3.3):
/ts-node@10.9.2(@types/node@20.11.16)(typescript@5.3.3):
resolution: {integrity: sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==}
hasBin: true
peerDependencies:
@@ -284,7 +284,7 @@ packages:
'@tsconfig/node12': 1.0.11
'@tsconfig/node14': 1.0.3
'@tsconfig/node16': 1.0.4
'@types/node': 20.11.11
'@types/node': 20.11.16
acorn: 8.11.3
acorn-walk: 8.3.2
arg: 4.1.3