fisadev / vim-isort

Vim plugin to sort python imports using https://github.com/timothycrosley/isort
MIT License
219 stars 32 forks source link

Isort clean the jump list of the buffer if some action has been performed #40

Closed vds2212 closed 12 months ago

vds2212 commented 12 months ago

If I use the command Isort and that Isort change the files the jump positions of the current buffer are gone.

To reproduce it you can:

  1. open a python buffer
  2. visit the end of the buffer (G)
  3. visit the beginning of the buffer (gg)
  4. run Isort (:Isort)
  5. the Ctrl+o is not going to the end of the buffer

If you use the :jumps command you'll see that they are gone.

I don't have the same behavior with the :Format command that comes with coc.nvim

fisadev commented 12 months ago

Thanks for the report and the info on how to reproduce this issue!

The source seems to be the fact that the plugin is rewriting the whole file using isort's output, and that basically erases any jumps, marks, etc that vim has for each line, as they're all new lines after the sorting.

The solution is to try to override only the lines doing imports, and only if they changed. But there isn't an easy way of doing that, I'll have to either identify the changed lines with some kind of "diff" logic, or to identify import lines to send only those to isort and replace only those on the way back. I'll try those approaches and post any updates here.

fisadev commented 12 months ago

I've just pushed a new version! Let's hope the issues are fixed.

vds2212 commented 12 months ago

Thanks for looking at the issue. I'll test your new version and let you know :-)

Thanks for your suppor!

vds2212 commented 12 months ago

It works like a charm!

Thanks for being so reactive. And thanks you for Isort :-)