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

Edit: Advanced Input #2884

Merged
merged 44 commits into from
Jan 31, 2024
Merged

Edit: Advanced Input #2884

merged 44 commits into from
Jan 31, 2024

Conversation

umpox
Copy link
Contributor

@umpox umpox commented Jan 24, 2024

Description

This PR adds an advanced Edit input that:

  • Allows users to manually adjust the selection of the Edit
  • Allows users to manually change the LLM that is used for an Edit (currently only Claude 2 and Claude Instant are supported)
  • Allow users to easily trigger the Document command, and select a relevant symbol to document
  • Allow users to easily trigger the Test command, and select a relevant symbol to document

Videos

Changing range and model:

EditAdvancedRangeModel.mov

Document & Test

EditAdvancedDocumentTest.mov

Test plan

Create edits:

  • From no selection (generate code)
    • Modify range to switch to expanded selection (edit code)
  • From a selection (edit code)
    • Modify range to switch to cursor (generate code)

Modify the range of an edit:

  • To a symbol in the document
  • To the expanded selection
  • Back to a previous selection after changing it

Trigger the document command:

  • From a symbol in the document
  • From the selection

Trigger the unit test command:

  • From a symbol in the document
  • From the selection

@umpox umpox changed the title Edit: Experiment with context aware sub-commands Edit: Advanced Input Jan 24, 2024
Copy link
Contributor

@abeatrix abeatrix left a comment

Choose a reason for hiding this comment

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

I like the UI that shows me what will be edited by Cody, kind of reassuring 😃

I've left some comments in line, but the only issue i run into when trying this out is when using "cody.experimental.foldingRanges": "indentation-based", the expanded selection selected the whole class instead of the method itself:

Screen.Recording.2024-01-26.at.6.41.15.PM.mov

it's not related to this PR though, and other than that, I haven't run into other issues 👍
Can't wait to try it out when it's ready!

import type { GetItemsResult } from '../quick-pick'

export const MODEL_ITEMS: Record<EditSupportedModels, vscode.QuickPickItem> = {
'anthropic/claude-2.1': {
Copy link
Contributor

Choose a reason for hiding this comment

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

this won't be supported by enterprise users on older instances i believe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do we handle this right now? I see we default to 2.0? Do you know why that is

Copy link
Contributor

Choose a reason for hiding this comment

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

Iirc 2.1 is currently in preview, and I've seen some formatting issue with 2.1 response too.

I think 2.0 also does not work for all enterprise users though because some instances have other llm provider set up, so maybe it'd be better to use the ChatModelProvider to get the default model name of their instance unless they are on dotcom?

description: 'by Anthropic',
alwaysShow: true,
},
'anthropic/claude-instant-1.2': {
Copy link
Contributor

Choose a reason for hiding this comment

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

are these the only models we want to support for edit? or do we want to provide the same options the users have available in chat? if it's the later one, we can get the available model on user's instance via ChatModelProvider. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

here is the list of the default models available if that's helpful: https://sourcegraph.com/github.com/sourcegraph/cody/-/blob/lib/shared/src/chat-models/index.ts?L5-48

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmmm OK I'm looking at this now... might ping you if I have questions

vscode/src/edit/input/get-items/edit.ts Outdated Show resolved Hide resolved
@umpox umpox marked this pull request as ready for review January 30, 2024 14:48
@umpox
Copy link
Contributor Author

umpox commented Jan 30, 2024

@toolmantim @abeatrix I think this is ready for review now...

I am adding some integration tests to cover the different scenarios that the quick pick can end up in.

I am adding support for the "Model" selector in: #2951 After chatting with @abeatrix, we will need some extra work to ensure this works well with Enterprise and also shows the correct models.

@umpox
Copy link
Contributor Author

umpox commented Jan 30, 2024

Some additional screenshots for reference:

Main input:
image

Document:
image

Test:
image

Range:
image

Copy link
Contributor

@abeatrix abeatrix left a comment

Choose a reason for hiding this comment

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

Love the new quick pick area, super slick! I've left some inline comments with some additional questions:

  1. when trying to edit code at cursor position, it would add an empty line after the generated code, but i think the line should be added above the newly added code?

image

image

  1. Follow up from 1., adding an empty line above / below the current cursor won't work for edits that happened between existing code on the same line though 🤔 (don't think it should block this PR though)

image

image

  1. smart selection no longer work on /doc and /test command when invoking from context menu or sidebar, is that intended?

image

image

vscode/src/edit/input/get-items/edit.ts Show resolved Hide resolved
@umpox
Copy link
Contributor Author

umpox commented Jan 31, 2024

@abeatrix Thanks for catching these bugs!

when trying to edit code at cursor position, it would add an empty line after the generated code, but i think the line should be added above the newly added code?

I think this is because I was incorrectly calculating the cursor position - just using the end of the selection. I've updated it so it actually uses selection.active now.

Follow up from 1., adding an empty line above / below the current cursor won't work for edits that happened between existing code on the same line though 🤔 (don't think it should block this PR though)

Yeah I think we might need to follow up on some more fine tuning for generate... The formatting can also be weird if you are within some existing code, I think maybe we need to use the full line in that case. That might help here too?

smart selection no longer work on /doc and /test command when invoking from context menu or sidebar, is that intended?

Nope, should be fixed now though!

@umpox umpox self-assigned this Jan 31, 2024
Copy link
Contributor

@abeatrix abeatrix left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fixes!

  1. Confirm smart selection works for Doc and Test:

image

image

  1. Doc and Test no longer show up when input is not empty

image

small nit/idea: Hard to see with Cody at the end of a long file name in the quick input menu title. Maybe something like Edit with Cody @path/to/file

@umpox umpox merged commit 2e2c41e into main Jan 31, 2024
16 checks passed
@umpox umpox deleted the tr/edit-advanced-input branch January 31, 2024 14:52
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.

None yet

2 participants