-
Notifications
You must be signed in to change notification settings - Fork 298
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
[WIP] Expanding Fixup Ranges by doing intelligent selection #1083
Conversation
@abeatrix i could add your latest changes into this to make a large range fix up selection(including cases where two functions are selected etc). Happy to spin up a pr for it. Would you like that? |
@arafatkatze Sorry about the wait! Yea that'd be great since it's now merged to main, so I'll be happy to review your change once it's merged with the latest update, thank you! |
Original PR -> #1083 (Closed because @abeatrix added some really amazing folding range functions to get the resize the selection range) Related Issues -> #585 and #223 ## Problem Summary Currently the selection made by users is not always fully inclusive of the entire range where changes might need to be made by Cody to satisfy the request of fixup by the user. Because we're limiting the changes to only the region that was selected by the user, that creates quite a few problems: 1. Empty Selections don't work( shown by @sqs ) <img width="814" alt="image" src="https://github.com/sourcegraph/cody/assets/11155207/115da45a-b142-4d40-94f5-baf91f2c8a64"> 2. Variable renaming within a function would miss some parts of the function with the original variable name that wasn't selected 4. Bad selection boundaries cause issues with indentation with the changes are applied coz the diffs function doesn't work perfectly in some edge cases 5. Refactors -> If you only selected the return value then any refactor would miss other parts of the function where changes need to be applied 6. Imperfect selection boundaries sometimes lead to repetition of code outside the selection range and sometimes it doesn't generate outputs 7. Hard mode Problem: Its hard to do a mega refactor where change request is on a small selection but that edits multiple files and other places in the codebase to make it all work together in synergy. ## Original solution Originally i leveraged an LLM call to decide the folding range and that was a cool algorithm but it had the latency of an extra LLM call. Now that @abeatrix added some really cool folding range functions I can just leverage them to get a better range for the selection. ## Video ### Before https://github.com/sourcegraph/cody/assets/11155207/53d63ee7-8650-4c03-b935-dfcb64d38c01 https://github.com/sourcegraph/cody/assets/11155207/5ab30335-6c2d-4142-849d-47234d6f4100 ## After https://drive.google.com/file/d/1RVShpNGiWK4wHJW6N_tHEGOdkzSwxM6d/view?usp=sharing ## Test plan <!-- Required. See https://docs.sourcegraph.com/dev/background-information/testing_principles. --> Tested in my local machine a few times. Works perfectly on edge cases too. --------- Co-authored-by: Dominic Cooney <dominic.cooney@gmail.com>
Related Issues -> #585 and #223
Problem Summary
Currently the selection made by users is not always fully inclusive of the entire range where changes might need to be made by Cody to satisfy the request of fixup by the user. Because we're limiting the changes to only the region that was selected by the user, that creates quite a few problems:
My solution
I wanted to solve this problem and explore quite a few different ways to be able to solve it.
If we were to not use LLMs then there's three options.
If we were to use LLms:
The simplest solution was the expand the text selection with prefix suffix and then find all the line numbers of starting/ending of all the functions etc(We can expand this to other cases too like classes interface etc) but for now I wanted to just focus on finding a function within the +-50 lines range. That’s the algorithm I did right now
I am attempting to solve problems 1-5 shown above in the best way that I can by doing an LLM based selection of the closest approximation to a full function for any selection. Sometimes the llm results aren't perfect and in that case this automatically falls back to the original selection without any issues. This is a good first step to solve the problem of automatic range selection.
Single Variable Selection
Before
Original.Jaccard.mp4
After
JaccardMatch.mp4
Partial Selection of Two functions
Before
original.partial.selection.mp4
After
MapSelect.mp4
NOTE: Some code in this is quite hacky and I am not fully happy about it but I wanted to get something out to show something to people first and then I am happy to cleanup the whole thing to make a proper PR(with feature flags too) if people are okay with my approach.
Potential Improvements
Thanks to @abeatrix @jdorfman I was able to focus on an interesting problem for me to work on.
Test plan
Just try this locally and try some ideas that I mentioned in the PR description.