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

Cody Context: Better usage of editor selection and UI update #53742

Merged
merged 7 commits into from
Jun 20, 2023

Conversation

umpox
Copy link
Contributor

@umpox umpox commented Jun 20, 2023

Description

This PR improves how Cody uses the current editor selection and displays it is part of the UI.

UI Changes:

We now display the selected lines against the file in the context footer. I went with start.line-end.line but happy to tweak if others feel a better UI would work.

Alternatives I considered:

  • start.line:start.character-end.line:end.character (feels too noisy/verbose)
  • L(start.line)-L(end.line)

image

Prompt changes:

We have always included the editor selection if present, but now we include it as the last piece of context. Cody uses it a lot more consistently now. I think this makes sense: broad context (embeddings) -> file context (editor contents) -> selection context (selection contents).

Example improvement:

BEFORE AFTER
image image

Test plan

Tested various prompts with different editor selections.

@cla-bot cla-bot bot added the cla-signed label Jun 20, 2023
@github-actions github-actions bot added the team/code-exploration Issues owned by the Code Exploration team label Jun 20, 2023
@umpox umpox marked this pull request as ready for review June 20, 2023 10:43
@umpox umpox requested review from toolmantim and a team June 20, 2023 10:50
Copy link
Contributor

@toolmantim toolmantim left a comment

Choose a reason for hiding this comment

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

Love it!! Great work on making it feel so responsive too.

Looks like you might have an off-by-one error on the line number though:

Screen.Recording.2023-06-20.at.8.57.58.pm.mov

@umpox
Copy link
Contributor Author

umpox commented Jun 20, 2023

@toolmantim Thanks for testing, have just fixed that now! (think we caught it at the same time :D)

Copy link
Contributor

@toolmantim toolmantim left a comment

Choose a reason for hiding this comment

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

Working well for me! 👍🏼 from the UI & design side of things.

I do have a question though…

What's the difference between having my cursor on a line:

Screenshot 2023-06-20 at 9 08 07 pm

and selecting the line:

Screenshot 2023-06-20 at 9 08 21 pm

I would have naively assumed it would be the same thing. But do they affect the results you get?

If this design makes sense though, I'm pondering if a tooltip on the context item could help them master using Cody… something like, "The whole of ${file}" and "Lines ${a}-${b} of ${file}" (or "Lines ${a}-${b} of ${file}, and some surrounding lines" if that's the case)

@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented Jun 20, 2023

📖 Storybook live preview

Copy link
Contributor

@philipp-spiess philipp-spiess left a comment

Choose a reason for hiding this comment

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

NICE

@umpox
Copy link
Contributor Author

umpox commented Jun 20, 2023

@toolmantim Good question!

Right now, we only provide Cody context when a user has explicitly selected some text. Having your cursor on a line, or over a variable doesn't have any effect right now.

We could extend this to always use the current cursor position but I think that might be a bit too much. The cursor is almost always going to be somewhere, so we might over index on using that as useful context. I think the correct approach will be to use code intelligence to include the cursor position when it is on a useful symbol (e.g. a variable). This should be possible in the future, I believe #team-cody-context is working on improving this, but will check

@umpox umpox merged commit 9794790 into main Jun 20, 2023
28 checks passed
@umpox umpox deleted the tr/cody-line-context branch June 20, 2023 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed team/code-exploration Issues owned by the Code Exploration team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants