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

Hitesh/autoedits improvements #5956

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

hitesh-1997
Copy link
Contributor

@hitesh-1997 hitesh-1997 commented Oct 21, 2024

Context

Improving the auto-edits UI with the decorations. For the auto-edits suggestions without the new lines additions, the current implementation, adds decoration. In the current editor, displays red color over the text we want to deleted and a green line decoration for the text which will replace the line.
image

Scope of improvements

  1. For the lines containing the additions, the current implementation has a buggy where which all the lines are offset by the number of new lines added. For example, in the example below:
    top: '10px'
    left: '10px'
    were the new lines, which we new lines that we need to add, but they overlap with the lines which we will preserve.
image

For now, this should be okay since it gives us a way to iterate on the model quality, while we think about the UI in parallel.

Ideas for improvements

  1. Insert the current line in the editor itself, similar to the inline-edits but this introduces additional complexity to manager the undo buffers and making sure, the line additions are deleted when user do any action such as moving the cursor, switching file, ctrl+z etc. One sample implementation to add blank line is done by @olafurpg here: WIP #5963

  2. We can display a floating window to indicate the text insertion.

Test plan

Manual Examples and usability examples:
https://www.loom.com/share/c22ff1670a0a4ffb8210cae9f7e56846

Copy link

‼️ Hey @sourcegraph/cody-security, please review this PR carefully as it introduces the usage of an unsafe_ function or abuses PromptString.

@aramaraju aramaraju self-requested a review October 22, 2024 20:06
@hitesh-1997 hitesh-1997 marked this pull request as ready for review October 22, 2024 20:58
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.

Some feedback inline.

@@ -56,9 +57,10 @@ export class AutoeditsProvider implements vscode.Disposable {
this.provider = new OpenAIPromptProvider()
} else if (provider === 'deepseek') {
this.provider = new DeepSeekPromptProvider()
} else {
logDebug('AutoEdits', `provider ${provider} not supported`)
} else if (provider === 'fireworks') {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good candidate for a switch statement.

Note, the method name is misspelled: initialize

@@ -184,7 +184,7 @@ export function getCurrentFilePromptComponents(
const codeToReplace = {
codeToRewrite: codeToRewrite,
startLine: completePrefixLines - prefixContext.codeToRewriteStartLines,
endLine: completePrefixLines + suffixContext.codeToRewriteEndLines,
endLine: completePrefixLines + suffixContext.codeToRewriteEndLines - 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Note, above you can just write codeToRewrite instead of codeToRewrite: codeToRewrite

How is endLine used? Can we get some unit test coverage of this?

},
]
return {
codeToReplace: codeToReplace,
Copy link
Contributor

Choose a reason for hiding this comment

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

When the property name and the variable name are the same, you can just write it once as a shorthand.

Suggested change
codeToReplace: codeToReplace,
codeToReplace,

})

const suggesterType = vscode.window.createTextEditorDecorationType({
before: { color: GHOST_TEXT_COLOR },
after: { color: GHOST_TEXT_COLOR },
})

function combineRanges(ranges: vscode.Range[], n: number): vscode.Range[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Give n a more descriptive name, and consider documenting what the function does.

if (
currentRange.end.line === nextRange.start.line &&
(nextRange.start.character - currentRange.end.character <= n ||
currentRange.intersection(nextRange))
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the constraints on the input ranges? Why not handle intersections in general where nextRange intersects with currentRange but doesn't happen to start on the line that the other one ends on?

) {
currentRange = new vscode.Range(
currentRange.start,
nextRange.end.character > currentRange.end.character ? nextRange.end : currentRange.end
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a danger here that if someone makes a change to the currentRange.end.line === nextRange.start.line constraint above then this result is going to be garbage. Consider something semantic, like:

currentRange.end.isAfter(nextRange.end) ? currentRange.end : nextRange.end

predictedText = predictedText.replace(/\n$/, '')

if (this.activeProposedChange) {
await this.dismissProposedChange()
Copy link
Contributor

Choose a reason for hiding this comment

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

The following method is pretty long, and you rely on there being no await after this point and before you set decorations, otherwise you might render two different ones at once.

Could you introduce some helper methods and a comment to point that out and reduce the reading gap between when the old changes are dismissed and the new ones are rendered?

@valerybugakov valerybugakov self-requested a review October 25, 2024 00:21
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.

2 participants