Skip to content

Commit

Permalink
feat: add toggle command for vertical split in CopilotChat
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Feb 16, 2024
1 parent 20ffb83 commit 48209d6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ return {
keys = {
{ "<leader>cce", "<cmd>CopilotChatExplain<cr>", desc = "CopilotChat - Explain code" },
{ "<leader>cct", "<cmd>CopilotChatTests<cr>", desc = "CopilotChat - Generate tests" },
{
"<leader>ccT",
"<cmd>CopilotChatVsplitToggle<cr>",
desc = "CopilotChat - Toggle Vsplit", -- Toggle vertical split
},
{
"<leader>ccv",
":CopilotChatVisual",
Expand Down Expand Up @@ -79,7 +84,9 @@ For example:
" python3 plugins
call remote#host#RegisterPlugin('python3', '/Users/huynhdung/.local/share/nvim/lazy/CopilotChat.nvim/rplugin/python3/CopilotChat', [
\ {'sync': v:false, 'name': 'CopilotChat', 'type': 'command', 'opts': {'nargs': '1'}},
\ {'sync': v:false, 'name': 'CopilotChatReset', 'type': 'command', 'opts': {}},
\ {'sync': v:false, 'name': 'CopilotChatVisual', 'type': 'command', 'opts': {'nargs': '1', 'range': ''}},
\ {'sync': v:false, 'name': 'CopilotChatVsplitToggle', 'type': 'command', 'opts': {}},
\ {'sync': v:false, 'name': 'CopilotChatInPlace', 'type': 'command', 'opts': {'nargs': '*', 'range': ''}},
\ {'sync': v:false, 'name': 'CopilotChatAutocmd', 'type': 'command', 'opts': {'nargs': '*'}},
\ {'sync': v:false, 'name': 'CopilotChatMapping', 'type': 'command', 'opts': {'nargs': '*'}},
Expand Down
6 changes: 6 additions & 0 deletions rplugin/python3/CopilotChat/copilot_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def init_vsplit_chat_handler(self):
if self.vsplit_chat_handler is None:
self.vsplit_chat_handler = VSplitChatHandler(self.nvim)

@pynvim.command("CopilotChatVsplitToggle")
def copilot_chat_toggle_cmd(self):
self.init_vsplit_chat_handler()
if self.vsplit_chat_handler:
self.vsplit_chat_handler.toggle_vsplit()

@pynvim.command("CopilotChat", nargs="1")
def copilot_agent_cmd(self, args: list[str]):
self.init_vsplit_chat_handler()
Expand Down
13 changes: 13 additions & 0 deletions rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ def vsplit(self):
)
self.nvim.current.window.vars[var_key] = True

def toggle_vsplit(self):
"""Toggle vsplit chat window."""
var_key = "copilot_chat"
for window in self.nvim.windows:
try:
if window.vars[var_key]:
self.nvim.command("close")
return
except Exception:
pass

self.vsplit()

def chat(self, prompt: str, filetype: str, code: str = ""):
self.buffer.option("filetype", "markdown")
super().chat(prompt, filetype, code, self.nvim.current.window.handle)
Expand Down

0 comments on commit 48209d6

Please sign in to comment.