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

Con 991: Diff Manager Improvements #1137

Closed
wants to merge 10 commits into from

Conversation

justinmilner1
Copy link
Contributor

@justinmilner1 justinmilner1 commented Apr 16, 2024

This work has been continued in #1198

Description

This MR fixes two main issues:

  1. Edits to a file while a vertical diff was open would not be acknowledged by diff manager, and so the accept/reject would be applied at the wrong location.
  2. Diff closure was not handled properly when new diffs were created in same file, so new diffs would generate at old diff location

Also, a bug was discovered: Reject/Accept all does not work when there are multiple blocks - instead only the first block receives the apply (I plan on fixing this soon (this weekend))
Update: 4/18 - added accept/reject all blocks on 'accept/reject all'

Resolves:

#991

const diffHandler = this.createVerticalPerLineDiffHandler(
filepath,
existingHandler?.range.start.line ?? startLine,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure why flexibility to reuse the existing handler was enabled - was the intention at some point to support multiple diffs per file?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is used for cmd+I to "add further instructions". https://github.com/continuedev/continue/blob/preview/extensions/vscode/src/commands.ts#L238

This might actually complicate this PR a bit. If there is a currently opened diff, then using cmd+I again should prompt the user to add further instructions, which looks like ", ".

One way of moving forward is to remove the previous diff (as you've implemented here) if there is any text selected, or "re-prompt" if the cursor selection is empty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I passed the 'previousInput' variable from commands into streamEdit as an optional parameter and used it as a flag.
This variable will have a value if it comes from cmd+I, or will be undefined otherwise.

await new Promise((resolve) => {
setTimeout(resolve, 200);
});

const startLine = editor.selection.start.line;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

determine start/end after the old block has been deleted

@justinmilner1
Copy link
Contributor Author

Last commits makes these changes compatible with cmd+I as well as actually reject/accept all blocks in the given file when the user clicks the 'reject/accept all' code lens.

@@ -4,6 +4,7 @@ import { getMarkdownLanguageTagForFile } from "core/util";
import { streamDiffLines } from "core/util/verticalEdit";
import * as vscode from "vscode";
import { VerticalPerLineDiffHandler } from "./handler";
import { start } from "repl";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this just leftover?

Copy link
Contributor

Choose a reason for hiding this comment

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

@justinmilner1 this is last thing, assuming it's safe to delete I can go ahead and do that while I merge

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sestinj whoops yeah that's not supposed to be in there

toHandle = blocks
}

for (const block of toHandle) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@justinmilner1 cd extensions/vscode && npx tsc raises an error here, and it looks like toHandle could be either a list or single value from blocks. I assume the intended logic is to loop through the list if it's a list, otherwise handler.acceptRejectBlock for just blocks[index]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sestinj Sorry that was sloppy.

Pushed up a fix. Tested more thoroughly.

@sestinj
Copy link
Contributor

sestinj commented Apr 24, 2024

@justinmilner1 I'm doing some tests now locally. First thing that comes up is accept/reject (not all, but the buttons to do it for each block individually) seems like it's regressed a bit. The first thing I saw is that if I were to "Accept" the top block, then the full "Accept All / Reject All / Accept / Reject" codelens would remain in the same position. Whereas in current versions of the extension, you can see it move down to the new top block.

I'm not certain which part of the PR this is coming from, but my guess is that whatever attempts to solve the new problem you found are the cause?

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