Skip to content

Commit

Permalink
Fix codeblock insertion and fix the following commands
Browse files Browse the repository at this point in the history
- Delete Turn
- Rating
- Delete Conversation
- Insert Code
  • Loading branch information
TerminalFi committed Aug 2, 2024
1 parent 6f209db commit a2f435d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 14 additions & 5 deletions plugin/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,15 @@ def _on_result_conversation_rating(self, payload: Literal["OK"]) -> None:
# Returns OK
pass

def is_enabled(self, event: dict[Any, Any] | None = None, point: int | None = None) -> bool:
return True


class CopilotConversationDestroyShimCommand(CopilotWindowCommand):
def run(self, conversation_id: str) -> None:
wcm = WindowConversationManager(self.window)
if not (view := find_view_by_id(wcm.last_active_view_id)):
status_message("Failed to find last active view.")
return
view.run_command("copilot_conversation_destroy", {"conversation_id": conversation_id})

Expand All @@ -382,6 +386,7 @@ def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit, conversa
and (wcm := WindowConversationManager(window))
and wcm.conversation_id == conversation_id
):
status_message("Failed to find window or conversation.")
return

session.send_request(
Expand All @@ -397,6 +402,7 @@ def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit, conversa

def _on_result_conversation_destroy(self, payload: str) -> None:
if not (window := self.view.window()):
status_message("Failed to find window")
return
if payload != "OK":
status_message("Failed to destroy conversation.")
Expand All @@ -410,10 +416,7 @@ def _on_result_conversation_destroy(self, payload: str) -> None:
def is_enabled(self, event: dict[Any, Any] | None = None, point: int | None = None) -> bool: # type: ignore
if not (window := self.view.window()):
return False
return bool(
super().is_enabled() # type: ignore
and WindowConversationManager(window).conversation_id
)
return bool(WindowConversationManager(window).conversation_id)


class CopilotConversationTurnDeleteShimCommand(CopilotWindowCommand):
Expand Down Expand Up @@ -488,6 +491,9 @@ def _on_result_conversation_turn_delete(
wcm.conversation = conversation
wcm.update()

def is_enabled(self, event: dict[Any, Any] | None = None, point: int | None = None) -> bool:
return True


class CopilotConversationCopyCodeCommand(CopilotWindowCommand):
def run(self, window_id: int, code_block_index: int) -> None:
Expand All @@ -504,19 +510,22 @@ def run(self, window_id: int, code_block_index: int) -> None:
class CopilotConversationInsertCodeShimCommand(CopilotWindowCommand):
def run(self, window_id: int, code_block_index: int) -> None:
if not (window := find_window_by_id(window_id)):
status_message(f"Failed to find window based on ID. ({window_id})")
return

wcm = WindowConversationManager(window)
if not (view := find_view_by_id(wcm.last_active_view_id)):
status_message("Window has no active view")
return

if not (code := wcm.code_block_index.get(str(code_block_index), None)):
status_message(f"Failed to find code based on index. {code_block_index}")
return

view.run_command("copilot_conversation_insert_code", {"characters": code})


class CopilotConversationInsertCodeCommand(CopilotTextCommand):
class CopilotConversationInsertCodeCommand(sublime_plugin.TextCommand):
def run(self, edit: sublime.Edit, characters: str) -> None:
if len(self.view.sel()) > 1:
return
Expand Down
2 changes: 0 additions & 2 deletions plugin/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ def preprocess_chat_message(
if user_template:
is_template = True
message += "\n\n{{ user_prompt }}\n\n{{ code }}"
else:
return False, message

region = view.sel()[0]
lang = get_view_language_id(view, region.begin())
Expand Down

0 comments on commit a2f435d

Please sign in to comment.