Skip to content

Commit 23414f0

Browse files
authored
Merge pull request #191 from TerminalFi/fixups
2 parents 9e32141 + 7d382b3 commit 23414f0

File tree

5 files changed

+71
-11
lines changed

5 files changed

+71
-11
lines changed

Main.sublime-commands

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,55 @@
33
"caption": "Copilot: Chat",
44
"command": "copilot_conversation_chat"
55
},
6+
{
7+
"caption": "Copilot: Explain",
8+
"command": "copilot_conversation_chat",
9+
"args": {
10+
"message": "/explain {{ sel[0] }}"
11+
}
12+
},
13+
{
14+
"caption": "Copilot: Generate Tests",
15+
"command": "copilot_conversation_chat",
16+
"args": {
17+
"message": "/tests {{ sel[0] }}"
18+
}
19+
},
20+
{
21+
"caption": "Copilot: Generate Docs",
22+
"command": "copilot_conversation_chat",
23+
"args": {
24+
"message": "/doc {{ sel[0] }}"
25+
}
26+
},
27+
{
28+
"caption": "Copilot: Fix This",
29+
"command": "copilot_conversation_chat",
30+
"args": {
31+
"message": "/fix {{ sel[0] }}"
32+
}
33+
},
34+
{
35+
"caption": "Copilot: Simplify This",
36+
"command": "copilot_conversation_chat",
37+
"args": {
38+
"message": "/simplify {{ sel[0] }}"
39+
}
40+
},
41+
{
42+
"caption": "Copilot: Feedback",
43+
"command": "copilot_conversation_chat",
44+
"args": {
45+
"message": "/feedback"
46+
}
47+
},
48+
{
49+
"caption": "Copilot: Help",
50+
"command": "copilot_conversation_chat",
51+
"args": {
52+
"message": "/help"
53+
}
54+
},
655
{
756
"caption": "Copilot: Destroy Conversation",
857
"command": "copilot_conversation_destroy"

plugin/commands.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,33 +199,35 @@ def run(self, view_id: int | None = None) -> None:
199199

200200

201201
class CopilotConversationChatShimCommand(LspWindowCommand):
202-
def run(self, window_id: int, follow_up: str = "") -> None:
202+
def run(self, window_id: int, message: str = "") -> None:
203203
if not (window := find_window_by_id(window_id)):
204204
return
205205

206206
conversation_manager = WindowConversationManager(window)
207207
if not (view := find_view_by_id(conversation_manager.last_active_view_id)):
208208
return
209209

210-
view.run_command("copilot_conversation_chat", {"follow_up": follow_up})
210+
view.run_command("copilot_conversation_chat", {"message": message})
211211

212212

213213
class CopilotConversationChatCommand(LspTextCommand):
214214
@_provide_plugin_session()
215-
def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit, follow_up: str = "") -> None:
215+
def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit, message: str = "") -> None:
216216
if not (window := self.view.window()):
217217
return
218+
218219
manager = WindowConversationManager(window)
219220
if manager.conversation_id:
220221
manager.open()
221-
manager.prompt(callback=lambda x: self._on_prompt(plugin, session, x), initial_text=follow_up)
222+
manager.prompt(callback=lambda msg: self._on_prompt(plugin, session, msg), initial_text=message)
222223
return
224+
223225
session.send_request(
224226
Request(
225227
REQ_CONVERSATION_PRECONDITIONS,
226228
{},
227229
),
228-
lambda x: self._on_result_conversation_preconditions(plugin, session, x),
230+
lambda msg: self._on_result_conversation_preconditions(plugin, session, msg),
229231
)
230232

231233
def _on_result_conversation_preconditions(self, plugin: CopilotPlugin, session: Session, payload) -> None:
@@ -248,7 +250,7 @@ def _on_result_conversation_preconditions(self, plugin: CopilotPlugin, session:
248250
# "workspaceFolder": Ji.Type.Optional(Ji.Type.String()),
249251
},
250252
),
251-
lambda x: self._on_result_conversation_create(plugin, session, x),
253+
lambda msg: self._on_result_conversation_create(plugin, session, msg),
252254
)
253255

254256
def _on_result_conversation_create(self, plugin: CopilotPlugin, session: Session, payload) -> None:
@@ -272,6 +274,14 @@ def _on_prompt(self, plugin: CopilotPlugin, session: Session, msg: str):
272274
manager.prompt(callback=lambda x: self._on_prompt(plugin, session, x), initial_text=msg)
273275
return
274276

277+
if msg in (
278+
"/fix",
279+
"/tests",
280+
"/doc",
281+
"/explain",
282+
"/simplify",
283+
):
284+
msg = msg + "\n\n{{ sel[0] }}"
275285
template = load_string_template(msg)
276286
sel = []
277287
if not (view := find_view_by_id(manager.last_active_view_id)):
@@ -505,7 +515,7 @@ def _on_result_coversation_agents(self, payload: list[CopilotRequestCoversationA
505515
window = self.view.window()
506516
if not window:
507517
return
508-
window.show_quick_panel([(item["id"], item["description"]) for item in payload], lambda _: None)
518+
window.show_quick_panel([[item["slug"], item["description"]] for item in payload], lambda _: None)
509519

510520

511521
class CopilotConversationTemplatesCommand(LspTextCommand):

plugin/templates/chat_panel.md.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@
3939
{% endfor %}
4040

4141
{% if follow_up %}
42-
Follow up: <a class="icon-link" href='{{ follow_up_url }}'>{{ follow_up }}</a>
42+
Follow up: <a class="icon-link follow-up" href='{{ follow_up_url }}'>{{ follow_up }}</a>
4343
{% endif %}

plugin/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ class CopilotPayloadConversationTemplate(TypedDict, total=True):
170170

171171

172172
class CopilotRequestCoversationAgent(TypedDict, total=True):
173-
id: str
173+
slug: str
174+
name: str
174175
description: str
175176

176177

plugin/ui/chat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def last_active_view_id(self) -> int:
3434
)
3535

3636
@last_active_view_id.setter
37-
def last_active_view_id(self, value: str) -> None:
37+
def last_active_view_id(self, value: int) -> None:
3838
set_copilot_setting(self.window, COPILOT_WINDOW_CONVERSATION_SETTINGS_PREFIX, "view_last_active_view_id", value)
3939

4040
@property
@@ -179,7 +179,7 @@ def completion_content(self) -> str:
179179
follow_up=self.conversation_manager.follow_up,
180180
follow_up_url=sublime.command_url(
181181
"copilot_conversation_chat_shim",
182-
{"window_id": self.conversation_manager.window.id(), "follow_up": self.conversation_manager.follow_up},
182+
{"window_id": self.conversation_manager.window.id(), "message": self.conversation_manager.follow_up},
183183
),
184184
close_url=sublime.command_url(
185185
"copilot_conversation_close",

0 commit comments

Comments
 (0)