A neovim plugin to automatically import unresolved symbols in python, using importmagic. Highly WIP, expect lots of issues and breaking changes
For now, it's simple -
- Install the importmagic package -
pip install importmagic
- Install the plugin however you install other plugins
- Run
:UpdateRemotePlugins
to register the plugin
Note: Some plugin managers do this for you. If you have trouble just run it once and it should work fine
For example, if you are using vim-plug, you can add this to your plugin section -
Plug "anihm136/importmagic.nvim", {'do': ':UpdateRemotePlugins'}
- Profit
Currently the plugin exposes a single command - :UpdateImports
, which searches the file for unresolved symbols and unused imports. It then replaces these with a new import block, containing the best matches for where these symbols are defined
tl;dr: Run :UpdateImports
in your python file to fix imports
- The version of importmagic on PyPi does not recognise type hints as references. To fix this, install from source -
pip install git+https://github.com/alecthomas/importmagic
- If the package containing the symbols is not installed, importmagic may find the symbol in a wrong package (rarely, most of the time it does nothing)
- Running
:UpdateImports
for the first time may be slow. The package needs to create an index of all packages in the environment, which happens in the background. However, if the function is called before indexing is finished, it blocks until the indexing is done and then performs the imports. Will be fixed
Note: This should be fixed, not rigorously tested yet - Importmagic must be installed in the same environment that is used by neovim i.e, the environment which contains pynvim
- Prevent blocking on running
:UpdateImports
when indexing is running - Provide functionality to choose among available import targets when multiple are available
- Find a way to save generated indexes
- May require dabbling in the importmagic package itself
- Note: The package currently does not support incremental indexing
- Find a better way to get
sys.path
of the editor