radian-software / apheleia

🌷 Run code formatter on buffer contents without moving point, using RCS patches and dynamic programming.
MIT License
558 stars 75 forks source link

Point jumps unexpectedly in python when code above point is "stretched" #149

Closed Fuco1 closed 6 months ago

Fuco1 commented 1 year ago

I have some code snippet from work (I will mail it to you, can you give me your email? - don't want to put it publicly), where after the formatting point appears to end up several lines over from where it started. It is on the same point, that is (point) before and after returns the same, but it is in completely different context. Or am I misunderstanding and it only tries to preserve (point)? Because in typescript, it works as expected, the cursor stays in the same context even when text above is reformatted.

I think the alignment algorithm gets confused, because both before and after the cursor ends up in the token sku_row[5], only they are several lines apart.

The sample is about 50 lines long.

raxod502 commented 1 year ago

Sure, feel free to send it over at contact+apheleia@radian.codes. It's somewhat known to me that sometimes the alignment algorithm doesn't work great, see https://github.com/radian-software/apheleia/issues/2 for example (but I've since seen worse). It's something I'd like to fix in the future, although at the moment I am focusing new development on a different project.

raxod502 commented 6 months ago

I don't think I ever got an email with this code sample... did you send it? I'm trying to see if I can fix the issue and add tests in https://github.com/radian-software/apheleia/pull/290.

Fuco1 commented 6 months ago

I don't think I did, sorry :cry: I found the file and even the referenced line, but can't reproduce it now, it grew a bit so there is now about 200 lines of code.

raxod502 commented 6 months ago

Cool, we can close this for now then and hopefully it will be solved for good with the change I linked above.