From 48209d6b98cb50c9dae59da70ebda351282cf8f7 Mon Sep 17 00:00:00 2001 From: Huynh Duc Dung Date: Fri, 16 Feb 2024 16:23:09 +0800 Subject: [PATCH 1/6] feat: add toggle command for vertical split in CopilotChat --- README.md | 7 +++++++ rplugin/python3/CopilotChat/copilot_plugin.py | 6 ++++++ .../CopilotChat/handlers/vsplit_chat_handler.py | 13 +++++++++++++ 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 6bfef972..7292cbcd 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,11 @@ return { keys = { { "cce", "CopilotChatExplain", desc = "CopilotChat - Explain code" }, { "cct", "CopilotChatTests", desc = "CopilotChat - Generate tests" }, + { + "ccT", + "CopilotChatVsplitToggle", + desc = "CopilotChat - Toggle Vsplit", -- Toggle vertical split + }, { "ccv", ":CopilotChatVisual", @@ -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': '*'}}, diff --git a/rplugin/python3/CopilotChat/copilot_plugin.py b/rplugin/python3/CopilotChat/copilot_plugin.py index 5e2708fc..c3b48cce 100644 --- a/rplugin/python3/CopilotChat/copilot_plugin.py +++ b/rplugin/python3/CopilotChat/copilot_plugin.py @@ -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() diff --git a/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py b/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py index 6f306cdd..70284b61 100644 --- a/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py @@ -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) From 00d448c4fb337c2993ca826ff881dfd9d9ce9c74 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 16 Feb 2024 08:23:33 +0000 Subject: [PATCH 2/6] chore(doc): auto generate docs --- doc/CopilotChat.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/CopilotChat.txt b/doc/CopilotChat.txt index 04b403ab..0b78f9dc 100644 --- a/doc/CopilotChat.txt +++ b/doc/CopilotChat.txt @@ -1,4 +1,4 @@ -*CopilotChat.txt* For NVIM v0.8.0 Last change: 2024 February 15 +*CopilotChat.txt* For NVIM v0.8.0 Last change: 2024 February 16 ============================================================================== Table of Contents *CopilotChat-table-of-contents* @@ -63,6 +63,11 @@ LAZY.NVIM ~ keys = { { "cce", "CopilotChatExplain", desc = "CopilotChat - Explain code" }, { "cct", "CopilotChatTests", desc = "CopilotChat - Generate tests" }, + { + "ccT", + "CopilotChatVsplitToggle", + desc = "CopilotChat - Toggle Vsplit", -- Toggle vertical split + }, { "ccv", ":CopilotChatVisual", @@ -98,7 +103,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': '*'}}, From 9a1569a35f7b1e90df3fde05e427999db835991c Mon Sep 17 00:00:00 2001 From: Huynh Duc Dung Date: Fri, 16 Feb 2024 16:30:07 +0800 Subject: [PATCH 3/6] docs: add vsplit toggle demo --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 7292cbcd..c24baca1 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,10 @@ For further reference, you can view @jellydn's [configuration](https://github.co [![In-place Demo](https://i.gyazo.com/4a5badaa109cd483c1fc23d296325cb0.gif)](https://gyazo.com/4a5badaa109cd483c1fc23d296325cb0) +### Toggle Vertical Split with `:CopilotChatVsplitToggle` + +[![Toggle](https://i.gyazo.com/db5af9e5d88cd2fd09f58968914fa521.gif)](https://gyazo.com/db5af9e5d88cd2fd09f58968914fa521) + ## Tips ### Integration with `edgy.nvim` From 72bec6a9e5ba8d3147ef965dc7d3c89ad6900790 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 16 Feb 2024 08:30:32 +0000 Subject: [PATCH 4/6] chore(doc): auto generate docs --- doc/CopilotChat.txt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/CopilotChat.txt b/doc/CopilotChat.txt index 0b78f9dc..3c778d72 100644 --- a/doc/CopilotChat.txt +++ b/doc/CopilotChat.txt @@ -233,6 +233,11 @@ IN-PLACE CHAT POPUP ~ +TOGGLE VERTICAL SPLIT WITH :COPILOTCHATVSPLITTOGGLE ~ + + + + TIPS *CopilotChat-copilot-chat-for-neovim-tips* @@ -420,10 +425,11 @@ STARGAZERS OVER TIME ~ 6. *Fix diagnostic*: https://i.gyazo.com/4aff3fdbc5c3eee59cb68939546fa2be.gif 7. *Fold Demo*: https://i.gyazo.com/766fb3b6ffeb697e650fc839882822a8.gif 8. *In-place Demo*: https://i.gyazo.com/4a5badaa109cd483c1fc23d296325cb0.gif -9. *Layout*: https://i.gyazo.com/550daf6cbb729027ca9bd703c21af53e.png -10. *Debug Info*: https://i.gyazo.com/bf00e700bcee1b77bcbf7b516b552521.gif -11. *@ecosse3*: -12. *Stargazers over time*: https://starchart.cc/CopilotC-Nvim/CopilotChat.nvim.svg +9. *Toggle*: https://i.gyazo.com/db5af9e5d88cd2fd09f58968914fa521.gif +10. *Layout*: https://i.gyazo.com/550daf6cbb729027ca9bd703c21af53e.png +11. *Debug Info*: https://i.gyazo.com/bf00e700bcee1b77bcbf7b516b552521.gif +12. *@ecosse3*: +13. *Stargazers over time*: https://starchart.cc/CopilotC-Nvim/CopilotChat.nvim.svg Generated by panvimdoc From 6c7626709c4decec38f236d0ed94f69c82cd0aa7 Mon Sep 17 00:00:00 2001 From: Huynh Duc Dung Date: Fri, 16 Feb 2024 16:49:05 +0800 Subject: [PATCH 5/6] docs: add instruction to enable python3 provider in Neovim --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c24baca1..48fd1ddb 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Ensure you have the following installed: - Python 3.10 or later +- Enable `python3 provider` in Neovim. Testing by run `:echo has('python3')` in Neovim. If it returns `1`, then `python3 provider` is enabled. ## Authentication From 2d2f860f48786c7ac1fa376e047c6d3e39a33504 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 16 Feb 2024 08:49:27 +0000 Subject: [PATCH 6/6] chore(doc): auto generate docs --- doc/CopilotChat.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/CopilotChat.txt b/doc/CopilotChat.txt index 3c778d72..2146cc10 100644 --- a/doc/CopilotChat.txt +++ b/doc/CopilotChat.txt @@ -29,6 +29,7 @@ PREREQUISITES *CopilotChat-copilot-chat-for-neovim-prerequisites* Ensure you have the following installed: - Python 3.10 or later +- Enable `python3 provider` in Neovim. Testing by run `:echo has('python3')` in Neovim. If it returns `1`, then `python3 provider` is enabled. AUTHENTICATION *CopilotChat-copilot-chat-for-neovim-authentication*