Skip to content

Commit

Permalink
replace ChatGPT with CopilotChat in Neovim
Browse files Browse the repository at this point in the history
  • Loading branch information
sfuruya0612 committed May 31, 2024
1 parent 87d4983 commit d0ed10f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 14 deletions.
3 changes: 0 additions & 3 deletions roles/shell/templates/config.fish.j2
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ set -x FZF_DEFAULT_OPTS '--no-sort --exact --cycle --exit-0 --select-1 --multi -
# Set tmux
set -x TMUX_TMPDIR "$HOME/.tmux/tmp/"

# Set OPENAI API_KEY
set -x OPENAI_API_KEY {{ OPENAI_API_KEY }}

# Alias
# exa command
if type -q exa
Expand Down
89 changes: 89 additions & 0 deletions roles/vim/files/copilot_chat_config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
local select = require('CopilotChat.select')
local actions = require("CopilotChat.actions")
-- local prompts = require("CopilotChat.prompts")


require("CopilotChat").setup {
debug = true, -- Enable debugging

model = 'gpt-4', -- GPT model to use, 'gpt-3.5-turbo' or 'gpt-4'
temperature = 0.1, -- GPT temperature

prompts = {
Explain = {
prompt = '/COPILOT_EXPLAIN カーソル上のコードの説明を段落をつけて書いてください。',
},
Tests = {
prompt = '/COPILOT_TESTS カーソル上のコードの詳細な単体テスト関数を書いてください。',
},
Fix = {
prompt = '/COPILOT_FIX このコードには問題があります。バグを修正したコードに書き換えてください。',
},
Optimize = {
prompt = '/COPILOT_REFACTOR 選択したコードを最適化し、パフォーマンスと可読性を向上させてください。',
},
Docs = {
prompt = '/COPILOT_REFACTOR 選択したコードのドキュメントを書いてください。ドキュメントをコメントとして追加した元のコードを含むコードブロックで回答してください。使用するプログラミング言語に最も適したドキュメントスタイルを使用してください(例:JavaScriptのJSDoc、Pythonのdocstringsなど)',
},
FixDiagnostic = {
prompt = 'ファイル内の次のような診断上の問題を解決してください:',
selection = select.diagnostics,
}
},

-- default window options
window = {
layout = 'vertical', -- 'vertical', 'horizontal', 'float', 'replace'
width = 0.3, -- fractional width of parent, or absolute width in columns when > 1
height = 0.3, -- fractional height of parent, or absolute height in rows when > 1
-- Options below only apply to floating windows
relative = 'editor', -- 'editor', 'win', 'cursor', 'mouse'
border = 'single', -- 'none', single', 'double', 'rounded', 'solid', 'shadow'
row = nil, -- row position of the window, default is centered
col = nil, -- column position of the window, default is centered
title = 'Copilot Chat', -- title of chat window
footer = nil, -- footer of chat window
zindex = 1, -- determines if window is on top or below other floating windows
},

-- default mappings
mappings = {
complete = {
detail = 'Use @<Tab> or /<Tab> for options.',
insert = '<Tab>',
},
close = {
normal = 'q',
insert = '<C-c>'
},
reset = {
normal = '<C-l>',
insert = '<C-l>'
},
submit_prompt = {
normal = '<CR>',
insert = '<C-m>'
},
accept_diff = {
normal = '<C-y>',
insert = '<C-y>'
},
yank_diff = {
normal = 'gy',
},
show_diff = {
normal = 'gd'
},
show_system_prompt = {
normal = 'gp'
},
show_user_selection = {
normal = 'gs'
},
},

}

function ShowCopilotChatActionPrompt()
require("CopilotChat.integrations.telescope").pick(actions.prompt_actions())
end
22 changes: 11 additions & 11 deletions roles/vim/files/dein.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ hook_add = '''
\ }
'''

# Use CopilotChat
[[plugins]]
repo = 'CopilotC-Nvim/CopilotChat.nvim'
branch = 'canary'
depends = ['github/copilot.vim', 'nvim-lua/plenary.nvim']
hook_add = '''
lua <<EOF
require('copilot_chat_config.init')
EOF
'''

# telescope optional dependencies
[[plugins]]
repo = 'nvim-treesitter/nvim-treesitter'
Expand Down Expand Up @@ -229,16 +240,6 @@ require('telescope').setup{
EOF
'''

# Use ChatGPT
[[plugins]]
repo = 'jackMort/ChatGPT.nvim'
depends = ['nui.nvim', 'plenary.nvim', 'telescope.nvim']
hook_add = '''
lua <<EOF
require('chatgpt').setup()
EOF
'''

[[plugins]]
repo = 'akinsho/toggleterm.nvim'
hook_add = '''
Expand All @@ -257,4 +258,3 @@ require("toggleterm").setup{
}
EOF
'''

4 changes: 4 additions & 0 deletions roles/vim/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
state: directory
loop:
- "{{ ansible_env.HOME }}/.config/nvim"
- "{{ ansible_env.HOME }}/.config/nvim/lua"
- "{{ ansible_env.HOME }}/.config/nvim/lua/copilot_chat_config"

- name: Install neovim from pip3
ansible.builtin.pip:
Expand Down Expand Up @@ -54,3 +56,5 @@
dest: "{{ ansible_env.HOME }}/.config/nvim/dein.toml"
- src: "{{ ansible_env.HOME }}/dotfiles/roles/vim/files/dein_lazy.toml"
dest: "{{ ansible_env.HOME }}/.config/nvim/dein_lazy.toml"
- src: "{{ ansible_env.HOME }}/dotfiles/roles/vim/files/copilot_chat_config.lua"
dest: "{{ ansible_env.HOME }}/.config/nvim/lua/copilot_chat_config/init.lua"

0 comments on commit d0ed10f

Please sign in to comment.