Skip to content

Commit

Permalink
Merge branch 'main' of github.com:CopilotC-Nvim/CopilotChat.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
cjoke committed Feb 16, 2024
2 parents 00cb1a3 + 2d2f860 commit 0c3586e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -44,6 +45,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 +85,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 Expand Up @@ -198,6 +206,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`
Expand Down
24 changes: 19 additions & 5 deletions doc/CopilotChat.txt
Original file line number Diff line number Diff line change
@@ -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*
Expand Down Expand Up @@ -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*
Expand Down Expand Up @@ -63,6 +64,11 @@ LAZY.NVIM ~
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 @@ -98,7 +104,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 Expand Up @@ -226,6 +234,11 @@ IN-PLACE CHAT POPUP ~
<https://gyazo.com/4a5badaa109cd483c1fc23d296325cb0>


TOGGLE VERTICAL SPLIT WITH :COPILOTCHATVSPLITTOGGLE ~

<https://gyazo.com/db5af9e5d88cd2fd09f58968914fa521>


TIPS *CopilotChat-copilot-chat-for-neovim-tips*


Expand Down Expand Up @@ -413,10 +426,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 <https://github.com/kdheepak/panvimdoc>

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 0c3586e

Please sign in to comment.