Skip to content

anihm136/importmagic.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

importmagic.nvim

A neovim plugin to automatically import unresolved symbols in python, using importmagic. Highly WIP, expect lots of issues and breaking changes

Installation

For now, it's simple -

  1. Install the importmagic package - pip install importmagic
  2. Install the plugin however you install other plugins
  3. 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'}
  1. Profit

Usage

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

Issues

  1. 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
  2. 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)
  3. 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
  4. Importmagic must be installed in the same environment that is used by neovim i.e, the environment which contains pynvim

TODO

  • 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

About

A neovim wrapper for importmagic

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published