davidhalter / jedi-vim

Using the jedi autocompletion library for VIM.
MIT License
5.29k stars 372 forks source link

Add autoimport and maybe organize imports feature #736

Closed purpleP closed 3 years ago

purpleP commented 7 years ago

Automatic import handling

I have a feature request, we're all busy, so take it or leave it. But it would be nice if jedi could add missing import statements and organize imports. This could be integrated nicely via InsertLeave event. Just check if some unknown identifier have appeared and show a menu where use could choose or type manually what to import.

Another thing I would like to have is to have an api for getting syntax tree of the current buffer. This would allow things like making new end of current syntax element motion which then could be used to delete or surround it with parenthesis and stuff like that.

Unfortunately I wouldn't be able to implement this myself, because right now I'm investigating the possibility of using http://bnfc.digitalgrammars.com/ and Happy to make a service (in the same way jedi is a service) that would complement editor with smart features like autocompletion, refactorings and other stuff. Basically do what jedi does and more but for any language for which someone already wrote BNF (it's done already for the most of the languages). I really think reimplementing parsers for each language is big waste of human potential.

davidhalter commented 7 years ago

Import handling is still kind of far away in Jedi. That takes probably 2-3 more years. I'm pretty certain that it's coming, but I just don't have the time right now.

For parsers I can just say that I'm on the verge of releasing https://github.com/davidhalter/parso. The remining issues there mostly revolve around documentation. However that currently doesn't include support for other languages (it might one day, but not at the moment).

The problem with the BNF implementation is that it doesn't support error recovery. Error recovery is crucial if you want to make it usable for most users. Parso does have error recovery BTW.

zhukovgreen commented 5 years ago

Just as a workaround I am using the following line in the vim config:

nmap <F3> :w<CR>:!autoflake -i --remove-all-unused-imports --remove-duplicate-keys --remove-unused-variables %<CR>:!black %<CR><CR>:e!<CR>

Note: you have to pip install autoflake before

davidhalter commented 3 years ago

Jedi does not support autoimport nor will it in the near future. I'm therefore closing.