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

feat: add context file via @ in chat input #1631

Merged
merged 21 commits into from
Nov 10, 2023
Merged

Conversation

abeatrix
Copy link
Contributor

@abeatrix abeatrix commented Nov 3, 2023

Continue from #1549
Close #1523

demo_at_file.mov

This adds PR support for passing context files to recipe from chat input. The context files are extracted from the codebase and passed to the recipe context.

  • Create context messages from context files
  • Generate display text including context file names
  • Add getTextEditorContentForContextFile method in editor to get content for context files
  • Update editor interface to support getting content for context files
  • Add ContextFile type to represent context files
  • Add userInputContextFiles property to RecipeContext for passing context files
  • Update RecipeContext to accept ContextFile[]
  • Generate context messages from ContextFile[]
  • Update chat question recipe to support getContextFilesContext
  • Pass editor context as ContextFile[] to custom prompt and chat question handler

This PR focuses on implementing the feature that allows users to add local workspace file via @ command via chat box.

Next

Test plan

  • In the input box inside the new Chat view, add files from the current workspace using the @ command
    • Typing @ will display a pop up where you can select files in the current workspace
    • Typing @ without additional character will show a list of currently opened files for you to choose
    • Typing @ follow by additional character will update the file list and display results that matches the file path and symbol names when available
    • Allow you to attach multiple files via @
    • Ask a question with a file attached using the @ command
      • Cody should have context about the file or symbol you attached using the @ command
      • The @-file is a link that's clickable in user's display text

image

@abeatrix
Copy link
Contributor Author

abeatrix commented Nov 4, 2023

@toolmantim this is ready for test 👍

@abeatrix abeatrix changed the title wip: feat: add context file via input support feat: add context file via @ in chat input Nov 6, 2023
@abeatrix abeatrix marked this pull request as ready for review November 6, 2023 17:54
@abeatrix abeatrix requested a review from a team November 7, 2023 03:13
Copy link
Contributor

@umpox umpox left a comment

Choose a reason for hiding this comment

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

Left some comments, have to drop off but will get back to this! Really cool to play around with and feels super powerful

Should the selector box show as soon as I start typing "@"? It feels like something isn't working because it doesn't show until I've typed a lot - an immediate indication that it is searching would be useful!

lib/shared/src/chat/prompts/get-display-text.ts Outdated Show resolved Hide resolved
lib/shared/src/editor/index.ts Outdated Show resolved Hide resolved
agent/src/editor.ts Outdated Show resolved Hide resolved
lib/shared/src/chat/recipes/custom-prompt.ts Outdated Show resolved Hide resolved
lib/shared/src/codebase-context/messages.ts Outdated Show resolved Hide resolved
vscode/src/editor/utils/editor-context.ts Show resolved Hide resolved
vscode/src/chat/MessageProvider.ts Outdated Show resolved Hide resolved
vscode/src/editor/utils/editor-context.ts Show resolved Hide resolved
vscode/src/editor/utils/editor-context.ts Show resolved Hide resolved
Comment on lines +31 to +35
// NOTE: Symbol search is resources extensive, so only search if query is long enough
// Five is an arbitrary minimum length
if (!query.trim() || query.trim().length < 5) {
return []
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we considered using symf as an option for this? This would give us a more advanced way of finding symbols, which might be awesome when trying this out.

Might also be faster? @beyang

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea we can always add additional context here. For v1 the main goal was to support @ file but once we have other sources of context that are more reliable we can always update this!

@abeatrix abeatrix requested review from umpox and a team November 8, 2023 17:21
@abeatrix
Copy link
Contributor Author

@umpox @valerybugakov can i get your review if you've got a chance, please? 🙇‍♀️

@umpox
Copy link
Contributor

umpox commented Nov 10, 2023

@abeatrix Looking now, thanks for making those changes!

AtCommand1252.mov

I noticed some unexpected behavior when trying it out 🤔 :

  1. The selection seems to get stuck between the bottom two items and ignores the top two at the start of the video. Unsure why this happens, we should either not show irrelevant items or make sure we can still select them.
  2. When I select getRerankW it doesn't seem to input the fill symbol into the chat.
    • Edit: seems this only happens on keypress, not mouse click? Might help with debugging
  3. I tried to select the same getRerankWithLog symbol again, and it shows the very first time (when I type @g but then it disappears and I can't seem to get it back)

Copy link
Contributor

@umpox umpox left a comment

Choose a reason for hiding this comment

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

Noticed some unexpected behavior and left a few comments, feels really great aside from that! Approving given this is behind a flag and don't want to block you!

vscode/src/chat/MessageProvider.ts Show resolved Hide resolved
vscode/src/editor/utils/editor-context.ts Show resolved Hide resolved
Comment on lines +41 to +43
(symbol.kind === vscode.SymbolKind.Function ||
symbol.kind === vscode.SymbolKind.Method ||
symbol.kind === vscode.SymbolKind.Class) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly if we support a way like prefixing the query with # we would want to remove this filter so a user could still use a symbol like a TS interface or w/e

@abeatrix
Copy link
Contributor Author

abeatrix commented Nov 10, 2023

@umpox Thanks for testing it so throughly, really appreciate your help and feedback here 🙇‍♀️ Will make sure the issue is fixed before i merge anything, thank you!

update

The issue is now fixed

Screen.Recording.2023-11-10.at.2.19.00.PM.mov

@abeatrix abeatrix merged commit 0e0574f into main Nov 10, 2023
13 checks passed
@abeatrix abeatrix deleted the bee/user-input-context branch November 10, 2023 23:02
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.

VSCE: New Chat - @ file context via chat input
2 participants