forked from CopilotC-Nvim/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvsplit_chat_handler.py
More file actions
63 lines (54 loc) · 1.93 KB
/
vsplit_chat_handler.py
File metadata and controls
63 lines (54 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from CopilotChat.copilot import Copilot
from CopilotChat.handlers.chat_handler import ChatHandler
from CopilotChat.mypynvim.core.buffer import MyBuffer
from CopilotChat.mypynvim.core.nvim import MyNvim
class VSplitChatHandler(ChatHandler):
def __init__(self, nvim: MyNvim):
self.nvim: MyNvim = nvim
self.copilot: Copilot = None
self.buffer: MyBuffer = MyBuffer.new(
self.nvim,
{
"filetype": "copilot-chat",
},
)
self.language = self.nvim.eval("g:copilot_chat_language")
def vsplit(self):
self.buffer.option("filetype", "copilot-chat")
var_key = "copilot_chat"
for window in self.nvim.windows:
try:
if window.vars[var_key]:
self.nvim.current.window = window
return
except Exception:
pass
self.buffer.vsplit(
{
"wrap": True,
"linebreak": True,
"conceallevel": 2,
"concealcursor": "n",
}
)
self.nvim.current.window.vars[var_key] = True
""" Disable vim diagnostics on the chat buffer """
self.nvim.command(":lua vim.diagnostic.disable()")
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()
self.buffer.option("filetype", "markdown")
def chat(self, prompt: str, filetype: str, code: str = ""):
self.buffer.option("filetype", "markdown")
super().chat(prompt, filetype, code, self.nvim.current.window.handle)
def reset_buffer(self):
"""Reset the chat buffer."""
self.buffer.clear()