-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
copilot.py
74 lines (64 loc) · 2.2 KB
/
copilot.py
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
64
65
66
67
68
69
70
71
72
73
74
from talon import Context, Module, actions
mod = Module()
ctx = Context()
ctx.matches = r"""
app: vscode
"""
mod.list(
"copilot_slash_command", "Slash commands that can be used with copilot, e.g. /test"
)
ctx.lists["user.copilot_slash_command"] = {
"test": "tests",
"dock": "doc",
"fix": "fix",
"explain": "explain",
"change": "",
}
mod.list("makeshift_destination", "Cursorless makeshift destination")
ctx.lists["user.makeshift_destination"] = {
"to": "clearAndSetSelection",
"after": "editNewLineAfter",
"before": "editNewLineBefore",
}
mod.tag("codeium", desc="Enable codeium for copilot integration")
@mod.action_class
class Actions:
def copilot_inline_chat(copilot_slash_command: str = "", prose: str = ""):
"""Initiate copilot inline chat session"""
actions.user.run_rpc_command(
"editor.action.codeAction",
{
"kind": "refactor.rewrite",
},
)
has_content = copilot_slash_command or prose
if has_content:
actions.sleep("50ms")
if copilot_slash_command:
actions.insert(f"/{copilot_slash_command} ")
if prose:
actions.insert(prose)
if has_content:
actions.key("enter")
def copilot_chat(prose: str):
"""Initiate copilot chat session"""
actions.user.vscode("workbench.panel.chat.view.copilot.focus")
if prose:
actions.sleep("50ms")
actions.insert(prose)
actions.key("enter")
def copilot_focus_code_block(index: int):
"""Bring a copilot chat suggestion to the cursor"""
actions.user.vscode("workbench.panel.chat.view.copilot.focus")
action = (
"workbench.action.chat.previousCodeBlock"
if index < 0
else "workbench.action.chat.nextCodeBlock"
)
count = index + 1 if index >= 0 else abs(index)
for _ in range(count):
actions.user.vscode(action)
def copilot_bring_code_block(index: int) -> None:
"""Bring a copilot chat suggestion to the cursor"""
actions.user.copilot_focus_code_block(index)
actions.user.vscode("workbench.action.chat.insertCodeBlock")