Replace existing code with suggesed
Is your feature request related to a problem? Please describe.
Models can produce suggestions, affecting already existing code
Currently suggestion can only be inserted at cursor position.
Describe the solution you'd like
It would be great if suggestion could also change existing code (like in cursor IDE).
Something like checking suggested lines for similarity to existing ones and if result is above threshold then treat it as replacement, if not - insertion.
For replacement, show suggested code changes near the code being changed.
Describe alternatives you've considered
Additional context
Tested on zed-industries/zeta quants
Sample code
void do_some_work(int);
struct Foo {
int bar;
};
int foo(Foo first, Foo second) {
int firstBar =
if (first.bar == second.bar)
return false;
if (first.bar > second.bar)
do_some_work(first.bar);
else
do_some_work(second.bar);
return true;
}
So, looks you are using FIM here via llama.cpp? If you will run like Instruct model for code completion in QodeAssist you can fix this just with correct system prompt, I made some by default. Indeed I don't see now any sense to use clear FIM model. To much problem need to fix by manual
Yes, it's llama.cpp. But there is not error in the suggestion. It's simply doesn't not add new code, but does some refactoring. In the example it suggests to assign class members to separate variables and replace their following usages. That's what I intended to do in a similar case. But if I simply press tab to apply it, there will still be an old version of changed code, which I had to remove manually. The idea of the issue is to add support of refactoring suggestions, i.e. replacing existing code with the one provided by LLM, without manually deleting the old code.
I meant not about error, but about how FIM models works. You will have bigger output answer and pay for that bigger counting of tokens. In case with instruct models in code completion, you can fix it by system prompt and count output of output tokens will be small. I just try to help spent less. Anyway I will add merge-things for code completion suggestions, it is not problem.
Okay, merging code with suggest and show is not simple in QtC like I thought. So now I don't have idea for that
Sad to hear. Maybe show it as usual, but insert or merge when user starts applying, depending on the suggestion and the existing code similarity? Maybe also add separate button/shortcut for this mode (like apply with merge)?
I improved code suggestion and merging with existing code in 0.5.10. Please try, should be better. It is not absolutely what did you want. Maybe need new algorithm for that. PR welcome
I couldn't get it to override existing code. It always inserts the new one. I'll make a PR if I get any results
For example
I've made a PR. Have no issues so far, but I'm still testing.
Btw, looks like single word apply was was affected by changes made for this issue. It drops suggestion after first apply.
Changing if (!subText.contains('\n')) { to if (!subText.contains('\n') && part == Line) { here fixed it for me
I'm used to the current behavior, so there's no issue anymore. Closing the PR too