Ron89 / thesaurus_query.vim

Multi-language Thesaurus Query and Replacement plugin for Vim/NeoVim
http://www.vim.org/scripts/script.php?script_id=5341
Apache License 2.0
220 stars 23 forks source link

NameError with neovim and lua plugin managers #51

Closed Bridouz closed 2 years ago

Bridouz commented 2 years ago

Hello Ron and thanks for your plugin.

I use it a lot when I'm writing prose and it worked very well with neovim up to v0.6.1

I was using both packer and paq-nvim as my plugin managers and from now on, even if the plugin is loaded I have an error buffer saying it can not find tq_interface. (NameError: can't find xxx module)

What is funny is that when I tried to replace those plugin managers with 'vim-plug' (my init.lua was untouched beside this change) thesaurus_query works as expected.

Tested and reproduced on Termux, Alpine and OpenBSD.

I'm around if you need more informations.

Justin

Ron89 commented 2 years ago

Hi @Bridouz , Thanks for raising this issue. The cause for this is that Python could not locate the class defined for this script.

I tested paq-nvim. When installing plugin with it, the plugin is installed to ~/.local/share/nvim/site/pack/paqs/start/thesaurus_query.vim. However, when checking with runtime path (:set runtimepath?), this path in explicit form is not part of the runtimepath. Instead, I see a wildcard ~/.local/share/nvim/site/pack/*/start/*. Now, this may not be a problem for Neovim to iterate internally for all the runtime path. But when it comes to Python, it is not that straightforward.

Since my plugin heavily rely on Python, the first thing it needs to do is to ask the python interpreter in Neovim to load the package. Python has its own path to look for when it comes to package, and wherever this plugin is installed to, it won't automatically be added to Python's sys.path. So we need to add it manually. In my plugin https://github.com/Ron89/thesaurus_query.vim/blob/65e67a2dc3290d1fbed59db2a3f58944a73e7251/autoload/thesaurus_query.vim#L204-L210, you see that it iterate through all the runtimepath, and see if directory autoload/thesaurus_query is in it. If it is, then this is considered the right path where the python package is, then its path is added to Python's sys.path for loading.

However, since this package manager used wildcard for runtime path, the logic I used for checking is no longer valid. Hence Python could not locate the package, and throw error ModuleNotFound.

I think to fix it, I need to replace the path finding logic from exact match finding to glob finding. Will make some change today and see if it helps.

Ron89 commented 2 years ago

huh, so when resolve is in the commit, the ticket is auto closed... Anyway, I have tested it on my device. If it still doesn't work for me, please re-open and let me know.