tweekmonster / impsort.vim

Sort and highlight Python imports in Vim
MIT License
37 stars 6 forks source link

Why are some import lines deleted? #1

Closed petobens closed 8 years ago

petobens commented 8 years ago

Hi, thanks for writing this plugin, I find it really useful. One quick question, why is that if I write:

from appscript import k
import xlwings as xw

and run :ImpSort then I get:

import xlwings as xw

I don't understand why the appscript import line gets deleted. Is this a feature? Thanks in advance

tweekmonster commented 8 years ago

This is a known problem. I didn't post this plugin anywhere, so I didn't think it needed my attention right away. 😅

The issue is because a 1 character module name becomes lost in the module parsing. I'll take a look at this as soon as I can!

petobens commented 8 years ago

Awesome. Thank you!

tweekmonster commented 8 years ago

@petobens This should be fixed now!

petobens commented 8 years ago

Hi @tweekmonster , thanks for the previous fix. I found another case where import lines are deleted. If I write

from pyhive import presto
from pyhive.exc import DatabaseError

and then run :ImpSort I get:

from pyhive.exc import DatabaseError

Can this be fixed? Thanks

tweekmonster commented 8 years ago

@petobens I fixed this today in the latest commit. Make sure you're up to date. The problem was with the sorting function.

petobens commented 8 years ago

@tweekmonster I believe I'm using the latest version however I still see the behaviour. Can you reproduce it? Again thanks for the help

tweekmonster commented 8 years ago

@petobens I think I found the issue. Are the imports the only thing that's in the file? Try adding any non-import after them. If that's the issue you're having, I'll look into fixing it.

petobens commented 8 years ago

@tweekmonster , adding non-import lines indeed fixes the issue.

tweekmonster commented 8 years ago

Thanks! I narrowed down the issue. A fix will be inbound shortly.

tweekmonster commented 8 years ago

@petobens Should be fixed now. Thanks for finding these issues!

petobens commented 8 years ago

Thank you for fixing them so quickly! :)