Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎊 Copilot Chat #168

Merged
merged 75 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
a896b09
preliminary work for chat
TerminalFi Jun 18, 2024
8f7c0ae
.
TerminalFi Jun 19, 2024
af67312
WIP Chat
TerminalFi Jun 19, 2024
5b5416f
agents command
TerminalFi Jun 19, 2024
ae23b71
Merge branch 'master' into impl/Chat
jfcherng Jun 19, 2024
c9837da
very hacked together way to talk to copilot
TerminalFi Jun 19, 2024
d13b02a
UI testing
TerminalFi Jun 19, 2024
82301b5
adding ui/chat handler
TerminalFi Jun 20, 2024
30263bb
provide rating command
TerminalFi Jun 20, 2024
6b119fe
additional commands
TerminalFi Jun 20, 2024
887b790
swithc to window from view.
TerminalFi Jun 20, 2024
27d80c8
fix: conversation/context handler
jfcherng Jun 20, 2024
703ccb9
Merge branch 'master' into impl/Chat
jfcherng Jun 20, 2024
cc6ccb7
add CopilotPayloadConversationContext
jfcherng Jun 21, 2024
745cd5f
chore(deps): bump copilot-node-server from 1.36.0 to 1.37.0 in /langu…
dependabot[bot] Jun 21, 2024
8e23fc9
Merge branch 'master' into impl/Chat
jfcherng Jun 21, 2024
f58fcc1
refactor: remove unused imports
jfcherng Jun 21, 2024
ed47500
Maybe take the focused view as a doc and reference
TerminalFi Jun 21, 2024
537eef9
addtl commands
TerminalFi Jun 22, 2024
01d4945
testing chat with custom workdone token to easily identify chats
TerminalFi Jun 25, 2024
752ec9d
intercepting response and adding to the conversation manager
TerminalFi Jun 25, 2024
f4d87f0
Merge branch 'master' into impl/Chat
jfcherng Jun 26, 2024
8fa1776
Merge branch 'master' into impl/Chat
TerminalFi Jun 26, 2024
6b08629
Merge branch 'master' into impl/Chat
TerminalFi Jun 26, 2024
8b7e3be
working towards view for conversation
TerminalFi Jun 26, 2024
e6b81f3
horribly built UI and session management
TerminalFi Jun 26, 2024
0312b7c
remove session from ui
TerminalFi Jun 26, 2024
7eae61a
Only prefix if kind is different
TerminalFi Jun 26, 2024
7db3074
markdown and some logic for inserting next message
TerminalFi Jun 26, 2024
03cadd1
fix append
TerminalFi Jun 26, 2024
24d9f5c
Adding logic for `selections` in command
TerminalFi Jun 27, 2024
762efb7
Close conversation on reload
TerminalFi Jun 27, 2024
5f4c7f9
add destroy conversation
TerminalFi Jun 27, 2024
4d2cb80
Working on minihtml version
TerminalFi Jun 27, 2024
3a0beec
fix some linting
TerminalFi Jun 27, 2024
d8c654e
Merge branch 'master' into impl/Chat
TerminalFi Jun 27, 2024
00d8a97
fix a few minor issues
TerminalFi Jun 27, 2024
e863c8f
first iteration of trying to capture codeblocks
TerminalFi Jun 27, 2024
1f7d3e8
closer to extracted code blocks with index
TerminalFi Jun 28, 2024
ce31bef
fix code block formatting and working towards proper MD format
TerminalFi Jun 28, 2024
37c754f
working md parsing
TerminalFi Jun 29, 2024
b49490c
copy code block
TerminalFi Jul 1, 2024
d576c97
adding close panel
TerminalFi Jul 1, 2024
89da81a
destroy conversation command
TerminalFi Jul 1, 2024
9ea2caa
implement rating command
TerminalFi Jul 1, 2024
3ae09ea
remove is waiting header
TerminalFi Jul 1, 2024
a0a3c74
fix ratings for only system / report replies
TerminalFi Jul 1, 2024
4bf348c
implement insert code.
TerminalFi Jul 1, 2024
2f2ec81
Only delete user turns
TerminalFi Jul 1, 2024
6530883
working on turn deletion. Not fully working yet. User turns are the o…
TerminalFi Jul 1, 2024
0c5c246
turn deletion workaround
TerminalFi Jul 1, 2024
2464e64
use last active view
TerminalFi Jul 1, 2024
378b206
fix some type errors
TerminalFi Jul 1, 2024
a2f1047
more types fix
TerminalFi Jul 1, 2024
e06a5fa
suggested title and follow up
TerminalFi Jul 1, 2024
adb295c
user reply codeblocks,
TerminalFi Jul 2, 2024
932db5c
re arrange items
TerminalFi Jul 2, 2024
69388ac
make CI happy
jfcherng Jul 2, 2024
8b3a464
add username to chat, fix some colors, add github copilot icon
TerminalFi Jul 2, 2024
0eab3d4
Merge branch 'master' into impl/Chat
TerminalFi Jul 2, 2024
2d01729
fix some code blocks missing copy and insert buttons
TerminalFi Jul 2, 2024
83bf835
fix follow up and some UI
TerminalFi Jul 2, 2024
be53d3b
thumbs rating updates
TerminalFi Jul 2, 2024
7431723
swap copy and insert for icons
TerminalFi Jul 2, 2024
a8ebab8
fix code block copy and insert
TerminalFi Jul 2, 2024
53c7652
Icons
TerminalFi Jul 2, 2024
43445fb
On turn deletion, remove follow up
TerminalFi Jul 3, 2024
491b24b
remove unused code
TerminalFi Jul 3, 2024
02835a2
prevent submission of message if waiting on response
TerminalFi Jul 3, 2024
640254e
make as done
TerminalFi Jul 3, 2024
75b2254
Merge branch 'master' into impl/Chat
TerminalFi Jul 3, 2024
996891b
refactor: replace hard-coded base64 image data URL
jfcherng Jul 3, 2024
fcbe5ae
remove second JINJA ENV
TerminalFi Jul 3, 2024
d3ab9e5
chore: update deps
jfcherng Jul 3, 2024
e3c6550
refactor: tidy codes
jfcherng Jul 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Main.sublime-commands
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
[
{
"caption": "Copilot: Chat",
"command": "copilot_conversation_chat"
},
{
"caption": "Copilot: Destroy Conversation",
"command": "copilot_conversation_destroy"
},
{
// Debug Command
"caption": "Copilot: Conversation Agents",
"command": "copilot_conversation_agents",
},
{
// Debug Command
"caption": "Copilot: Conversation Templates",
"command": "copilot_conversation_templates",
},
{
"caption": "Copilot: Check Status",
"command": "copilot_check_status"
Expand Down
26 changes: 26 additions & 0 deletions plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@
CopilotCheckFileStatusCommand,
CopilotCheckStatusCommand,
CopilotClosePanelCompletionCommand,
CopilotConversationAgentsCommand,
CopilotConversationChatCommand,
CopilotConversationChatShimCommand,
CopilotConversationCloseCommand,
CopilotConversationCopyCodeCommand,
CopilotConversationDestroyCommand,
CopilotConversationDestroyShimCommand,
CopilotConversationInsertCodeCommand,
CopilotConversationRatingCommand,
CopilotConversationRatingShimCommand,
CopilotConversationTemplatesCommand,
CopilotConversationTurnDeleteCommand,
CopilotConversationTurnDeleteShimCommand,
CopilotGetPanelCompletionsCommand,
CopilotGetVersionCommand,
CopilotNextCompletionCommand,
Expand Down Expand Up @@ -41,6 +54,19 @@
"CopilotSignInCommand",
"CopilotSignInWithGithubTokenCommand",
"CopilotSignOutCommand",
"CopilotConversationChatShimCommand",
"CopilotConversationChatCommand",
"CopilotConversationCloseCommand",
"CopilotConversationDestroyShimCommand",
"CopilotConversationDestroyCommand",
"CopilotConversationAgentsCommand",
"CopilotConversationTemplatesCommand",
"CopilotConversationTurnDeleteCommand",
"CopilotConversationTurnDeleteShimCommand",
"CopilotConversationRatingShimCommand",
"CopilotConversationRatingCommand",
"CopilotConversationCopyCodeCommand",
"CopilotConversationInsertCodeCommand",
# ST: event listeners
"EventListener",
"ViewEventListener",
Expand Down
Binary file added plugin/assets/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/assets/copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/assets/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/assets/insert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/assets/thumbs_down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/assets/thumbs_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/assets/trash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 50 additions & 7 deletions plugin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import sublime
from LSP.plugin import ClientConfig, DottedDict, Request, Session, WorkspaceFolder
from lsp_utils import ApiWrapperInterface, NpmClientHandler, notification_handler
from lsp_utils import ApiWrapperInterface, NpmClientHandler, notification_handler, request_handler

from .constants import (
NTFY_FEATURE_FLAGS_NOTIFICATION,
Expand All @@ -24,6 +24,7 @@
NTFY_STATUS_NOTIFICATION,
PACKAGE_NAME,
REQ_CHECK_STATUS,
REQ_CONVERSATION_CONTEXT,
REQ_GET_COMPLETIONS,
REQ_GET_COMPLETIONS_CYCLING,
REQ_GET_VERSION,
Expand All @@ -34,6 +35,7 @@
from .types import (
AccountStatus,
CopilotPayloadCompletions,
CopilotPayloadConversationContext,
CopilotPayloadFeatureFlagsNotification,
CopilotPayloadGetVersion,
CopilotPayloadLogMessage,
Expand All @@ -44,10 +46,12 @@
T_Callable,
)
from .ui import ViewCompletionManager, ViewPanelCompletionManager
from .ui.chat import WindowConversationManager
from .utils import (
ActivityIndicator,
CopilotIgnore,
all_views,
all_windows,
debounce,
get_session_setting,
prepare_completion_request,
Expand Down Expand Up @@ -116,6 +120,7 @@ class CopilotPlugin(NpmClientHandler):
_account_status = AccountStatus(
has_signed_in=False,
is_authorized=False,
user="",
)

_activity_indicator: ActivityIndicator | None = None
Expand All @@ -134,6 +139,9 @@ def __init__(self, session: weakref.ref[Session]) -> None:
ViewCompletionManager(view).reset()
ViewPanelCompletionManager(view).reset()

for window in all_windows():
WindowConversationManager(window).reset()

@classmethod
def on_pre_start(
cls,
Expand All @@ -155,6 +163,7 @@ def _on_check_status(result: CopilotPayloadSignInConfirm, failed: bool) -> None:
self.set_account_status(
signed_in=result["status"] in {"NotAuthorized", "OK"},
authorized=result["status"] == "OK",
user=result.get("user", None),
)

def _on_set_editor_info(result: str, failed: bool) -> None:
Expand Down Expand Up @@ -203,7 +212,7 @@ def version() -> str:
def editor_info(cls) -> dict[str, Any]:
return {
"editorInfo": {
"name": "Sublime Text",
"name": "vscode",
"version": sublime.version(),
},
"editorPluginInfo": {
Expand Down Expand Up @@ -231,12 +240,15 @@ def set_account_status(
*,
signed_in: bool | None = None,
authorized: bool | None = None,
user: str | None = None,
quiet: bool = False,
) -> None:
if signed_in is not None:
cls._account_status.has_signed_in = signed_in
if authorized is not None:
cls._account_status.is_authorized = authorized
if user is not None:
cls._account_status.user = user

if not quiet:
if not cls._account_status.has_signed_in:
Expand Down Expand Up @@ -270,6 +282,12 @@ def plugin_session(cls, view: sublime.View) -> tuple[None, None] | tuple[Copilot
plugin = cls.from_view(view)
return (plugin, plugin.weaksession()) if plugin else (None, None)

@classmethod
def should_ignore(cls, view: sublime.View) -> bool:
if not (window := view.window()):
return False
return CopilotIgnore(window).trigger(view)

def is_valid_for_view(self, view: sublime.View) -> bool:
session = self.weaksession()
return bool(session and session.session_view_for_view_async(view))
Expand All @@ -294,11 +312,28 @@ def update_status_bar_text(self, extra_variables: dict[str, Any] | None = None)
log_warning(f'Invalid "status_text" template: {e}')
session.set_config_status_async(rendered_text)

@classmethod
def should_ignore(cls, view: sublime.View) -> bool:
if not (window := view.window()):
return False
return CopilotIgnore(window).trigger(view)
def on_server_notification_async(self, notification) -> None:
if notification.method == "$/progress":
if (token := notification.params["token"]) and token.startswith("copilot_chat://"):
if params := notification.params["value"]:
if not (window := WindowConversationManager.find_window_by_token_id(token)):
return

conversation_manager = WindowConversationManager(window)
if params.get("kind", None) == "end":
conversation_manager.is_waiting = False

if suggest_title := params.get("suggestedTitle", None):
conversation_manager.suggested_title = suggest_title

if params.get("reply", None):
conversation_manager.append_conversation_entry(params)

if followup := params.get("followUp", None):
message = followup.get("message", "")
conversation_manager.follow_up = message

conversation_manager.update()

@notification_handler(NTFY_FEATURE_FLAGS_NOTIFICATION)
def _handle_feature_flags_notification(self, payload: CopilotPayloadFeatureFlagsNotification) -> None:
Expand Down Expand Up @@ -332,6 +367,14 @@ def _handle_panel_solution_done_notification(self, payload) -> None:
def _handle_status_notification_notification(self, payload: CopilotPayloadStatusNotification) -> None:
pass

@request_handler(REQ_CONVERSATION_CONTEXT)
def _handle_conversation_context_request(
self,
payload: CopilotPayloadConversationContext,
respond: Callable[[Any], None],
) -> None:
respond(None) # what?

@_guard_view()
@debounce()
def request_get_completions(self, view: sublime.View) -> None:
Expand Down
Loading