neovim / pynvim

Python client and plugin host for Nvim
http://pynvim.readthedocs.io/en/latest/
Apache License 2.0
1.48k stars 118 forks source link

Cannot get vimscript variables via command_output #433

Closed Kotaro7750 closed 4 years ago

Kotaro7750 commented 4 years ago

I am developing custom denite source and I want to get vimscript variable like below.

def gather_candidates(self,context):
      snippet_path = self.vim.command_output('echo python3_host_prog')

When I execute Denite command, below error was printed

[denite] Traceback (most recent call last):
[denite]   File "/home/denjo/.cache/dein/.cache/init.vim/.dein/rplugin/python3/denite/rplugin.py", line 28, in start
[denite]     return ui.start(args[0], context)
[denite]   File "/home/denjo/.cache/dein/.cache/init.vim/.dein/rplugin/python3/denite/ui/default.py", line 65, in start
[denite]     self._start_sources_queue(context)
[denite]   File "/home/denjo/.cache/dein/.cache/init.vim/.dein/rplugin/python3/denite/ui/default.py", line 155, in _start_sources_queue
[denite]     self._start(context['sources_queue'][0], context)
[denite]   File "/home/denjo/.cache/dein/.cache/init.vim/.dein/rplugin/python3/denite/ui/default.py", line 203, in _start
[denite]     self._gather_candidates()
[denite]   File "/home/denjo/.cache/dein/.cache/init.vim/.dein/rplugin/python3/denite/ui/default.py", line 764, in _gather_candidates
[denite]     self._denite.gather_candidates(self._context)
[denite]   File "/home/denjo/.cache/dein/.cache/init.vim/.dein/rplugin/python3/denite/parent.py", line 47, in gather_candidates
[denite]     self._put('gather_candidates', [context])
[denite]   File "/home/denjo/.cache/dein/.cache/init.vim/.dein/rplugin/python3/denite/parent.py", line 80, in _put
[denite]     return self._child.main(name, args, queue_id=None)  # type: ignore
[denite]   File "/home/denjo/.cache/dein/.cache/init.vim/.dein/rplugin/python3/denite/child.py", line 73, in main
[denite]     self.gather_candidates(args[0])
[denite]   File "/home/denjo/.cache/dein/.cache/init.vim/.dein/rplugin/python3/denite/child.py", line 125, in gather_candidates
[denite]     candidates = self._gather_source_candidates(
[denite]   File "/home/denjo/.cache/dein/.cache/init.vim/.dein/rplugin/python3/denite/child.py", line 384, in _gather_source_candidates
[denite]     candidates = source.gather_candidates(context)
[denite]   File "/home/denjo/Develope/denite-clipy/rplugin/python3/denite/source/clipy.py", line 16, in gather_candidates
[denite]     snippet_path = self.vim.command_output('echo python3_host_prog')
[denite]   File "/home/denjo/nvim-python3/lib/python3.8/site-packages/pynvim/api/nvim.py", line 291, in command_output
[denite]     return self.request('nvim_command_output', string)
[denite]   File "/home/denjo/nvim-python3/lib/python3.8/site-packages/pynvim/api/nvim.py", line 182, in request
[denite]     res = self._session.request(name, *args, **kwargs)
[denite]   File "/home/denjo/nvim-python3/lib/python3.8/site-packages/pynvim/msgpack_rpc/session.py", line 104, in request
[denite]     raise self.error_wrapper(err)
[denite] pynvim.api.common.NvimError: Vim(echo):E121: Undefined variable: python3_host_prog

But I can execute with no errors via neovim command pallet like below.

:echo python3_host_prog

OUTPUT
/home/denjo/nvim-python3/bin/python3

Is there a way to get vimscript variables via pynvim? Or is this just a bug?

version 0.4.1

bfredl commented 4 years ago

you need g:python3_host_prog inside functions (including python functions). But vim.vars['python3_host_prog'] is better anyway.