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

Chat: add support to send terminal text to Cody chat #5543

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

abeatrix
Copy link
Contributor

CLOSE https://linear.app/sourcegraph/issue/CODY-3703/add-terminal-output-as-chat-context

The cody.mention.selection command now handles selection argument that enables users to send selected text from terminal to Cody chat.

  • Update cody.mention.selection command to send terminal text to Cody chat
  • Update mention selection command to handle text selection
  • Update package.json to enable terminal text mention command

Note: Keybinding doesn't seem to work when terminal is focused?

Test plan

Select some text in your terminal and right click > Add Selection to Cody Chat:

Screen.Recording.2024-09-10.at.3.53.37.PM.mov

Changelog

Chat: add support to send selected text from terminal to Cody chat

The `cody.mention.selection` command now handles `selection` argument that enables users to send selected text from terminal to Cody chat.

- Update  `cody.mention.selection` command to send terminal text to Cody chat
- Update mention selection command to handle text selection
- Update package.json to enable terminal text mention command

Note: Keybinding doesn't seem to work when terminal is focused?
@abeatrix abeatrix requested a review from a team September 10, 2024 23:12
Copy link
Contributor

@jamesmcnamara jamesmcnamara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's cool!

Copy link
Contributor

@dominiccooney dominiccooney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's design the types to be easier to use.

Let's add a test.

Does this change the way sending context from files to chat works? Will that have args.selection set or is that a totally different code path? (If so... why?)

I think the context could be richer that this is coming from a terminal. Like, why not treat that as a first class thing, maybe we want to pull in surrounding context later, etc.

It is worth keeping in mind that when doesn't filter explicit invocations of commands so you should be defensive... This may not always be called with a terminal selection.

Please also do JetBrains, CC @taylorsperry

@@ -243,18 +243,27 @@ export class ChatsController implements vscode.Disposable {
await vscode.commands.executeCommand('cody.chat.focus')
}

private async sendEditorContextToChat(uri?: URI): Promise<void> {
telemetryRecorder.recordEvent('cody.addChatContext', 'clicked', {
private async sendEditorContextToChat(payload?: URI | string): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API makes me nervous because we have been so burned by slinging URIs and file paths as URIs or strings etc.

Let's make this an object with properties like payload: { editorUri: URI } | { selection: string }

Why do we just want the string without a filename for context? Like @foo.ts:1-10 or whatever (we'd need to support character offsets...)

await provider.handleGetUserEditorContext(uri)

if (isText) {
await provider.handleTextToUserInput(payload as string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the object as suggested above you can avoid the as here.

@kalanchan
Copy link
Contributor

@beyang @chenkc805 could you also take a quick look if this is the right implementation for https://linear.app/sourcegraph/issue/CODY-3703/add-terminal-output-as-chat-context?

@abeatrix would it be possible to add a top level shortcut instead of going into the Cody dropdown when you right click? I feel like that would make it easier to use

@abeatrix
Copy link
Contributor Author

abeatrix commented Sep 11, 2024

would it be possible to add a top level shortcut

@kalanchan just found a hacky way to do it. will continue tmr after bug bash.

@abeatrix abeatrix marked this pull request as draft September 11, 2024 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants