Mainly configuration and RPC infrastructure can be considered "done". Specific requests and their callbacks will be improved later (and also served by plugins). There are also some TODO:s for the client itself, like incremental updates.
Co-authored by at-tjdevries and at-h-michael, with many review/suggestion contributions.
Problem: If spellfile is missing, then "set spell" in modeline/sandbox
fails with a non-obvious error.
Solution: Check for sandbox early and give a meaningful error.
Fixes#11359
Test case:
# test.latex has `% vim: set spelllang=hu:`
# no spell file for `hu` yet!
nvim -u NORC --cmd 'autocmd FileType tex setlocal spell' --cmd 'set modeline' test.latex
Before:
No spell file for "hu" in utf-8
Download it?
Downloading hu.utf-8.spl...
Error detected while processing /usr/local/share/nvim/runtime/autoload/netrw.vim:
line 583:
E12: Command not allowed from exrc/vimrc in current dir or tag search: au WinEnter *^Iif &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Error detected while processing function spellfile#LoadFile[60]..spellfile#Nread[13]..netrw#NetRead[4]..<SNR>67_NetrwOptionsSave:
line 66:
E171: Missing :endif
Error detected while processing function spellfile#LoadFile[60]..spellfile#Nread:
line 13:
E171: Missing :endif
Error detected while processing function spellfile#LoadFile:
line 60:
E171: Missing :endif
Error detected while processing modelines:
line 1:
E12: Command not allowed from exrc/vimrc in current dir or tag search
After:
Error detected while processing function spellfile#LoadFile:
line 5:
E605: Exception not caught: Cannot download spellfile in sandbox/modeline. Try ":set spell" from the cmdline.
Error detected while processing modelines:
line 1:
E12: Command not allowed from exrc/vimrc in current dir or tag search
sys.path.remove("") raises ValueError if the item is missing.
https://docs.python.org/3/library/functions.html#filter:
> filter(function, iterable) is equivalent to the generator expression (item
> for item in iterable if function(item))
fixes#11293
In order to find if there was already an open man page, the :Man command
would cycle through each window to see if &ft=='man'. This triggers
autocmds, e.g. BufEnter, unnecessarily and can have unexpected
side-effects.
Change the logic to check each window's ft without switching to it
unless it is actually a man window.
Signed-off-by: Joshua Rubin <me@jawa.dev>
The Python provider was special (via [1]), and would continue to do
checks with `0` being set explicitly even.
This was fixed in #11044 (45447e3b6), ref: #11040.
This extends it to use the same method with all providers.
1: https://github.com/neovim/neovim/pull/8047
This reverts part of ade88fe4c [1].
This is required for `let g:python3_host_prog = 'python'` etc, where it
should get picked up from PATH.
Without this it would show:
```
- INFO: pyenv: Path: /home/user/.pyenv/libexec/pyenv
- INFO: pyenv: Root: /home/user/.pyenv
- INFO: Using: g:python3_host_prog = "python"
- ERROR: "python" was not found.
- INFO: Executable: Not found
- ERROR: Detected pip upgrade failure: Python executable can import "pynvim" but not "neovim": python
- ADVICE:
- Use that Python version to reinstall "pynvim" and optionally "neovim".
pip3 uninstall pynvim neovim
pip3 install pynvim
pip3 install neovim # only if needed by third-party software
```
Note that it additionally causes a weird error
("Detected pip upgrade failure"), due to `s:check_bin` emptying
`python_exe` (because the non-absolute file not being readable), and
`provider#pythonx#DetectByModule('pynvim', a:version)` from 75593e6fce
then just getting the value from the host var again (without actual
checks).
This is implicitly fixed via this patch now (because it is skipped), but
could need some improvement in this regard probably.
With this patch it resolves it (for a virtualenv where pynvim is not
made available intentionally):
```
- INFO: pyenv: Path: /home/daniel/.pyenv/libexec/pyenv
- INFO: pyenv: Root: /home/daniel/.pyenv
- INFO: Using: g:python3_host_prog = "python"
- WARNING: $VIRTUAL_ENV exists but appears to be inactive. This could lead to unexpected results.
- ADVICE:
- If you are using Zsh, see: http://vi.stackexchange.com/a/7654
- INFO: Executable: /home/daniel/.pyenv/shims/tmp-system-deoplete.nvim-f205aF/python
- ERROR: Command error (job=11, exit code 1): `'/home/daniel/.pyenv/shims/tmp-system-deoplete.nvim-f205aF/python' -c 'import sys; sys.path.remove(""); import neovim; print(neovim.__file__)'` (in '/home/daniel/.dotfiles/vim/plugged/deoplete.nvim')
Output: Traceback (most recent call last): File "<string>", line 1, in <module>ModuleNotFoundError: No module named 'neovim'
Stderr: Traceback (most recent call last): File "<string>", line 1, in <module>ModuleNotFoundError: No module named 'neovim'
- INFO: Python version: 3.7.4
- INFO: pynvim version: unable to load neovim Python module
- ERROR: pynvim is not installed.
Error: unable to load neovim Python module
- ADVICE:
- Run in shell: pip3 install pynvim
```
Note: this appears to display the error twice via "Output:" and
"Stderr:".
1: https://github.com/neovim/neovim/pull/8784
Instead of deciding provider status in eval_has_provider, move the
decision to the provider Vim scripts.
Previously, provider loading worked as follows:
1. eval_has_provider() verified provider availability by searching for
the provider#providername#Call function and cached this verificaion as a static
variable for some providers
2. providers short-circuited on loading to prevent the definition of the
Call function (with the exception of the node provider that did not)
This commit changes the expected interface between nvim and its
providers to facilitate provider reloading, by splitting the
verification of the provider from the availability of the Call function.
eval_has_provider() now checks for a provider#providername#enabled
variable. It is up to the provider script to set this to 0 or 1
accordingly. eval_call_provider() remains unchanged.
All providers hosting a Call function were updated to respect this.
The clipboard provider now has a Reload function to reload the
provider.
`wl-copy` by default tries to determine the mime type of a copied bit of
text. From the [readme](https://github.com/bugaevc/wl-clipboard):
> wl-copy automatically infers the type of the copied content by running
> xdg-mime(1) on it.
So copying a Ruby script from Nvim may store it in the Wayland clipboard
as mime-type `application/x-ruby`.
This is a small reproduction without Nvim:
$ cat test.rb
#!/usr/bin/env ruby
puts 'hello world'
$ cat test.rb | wl-copy
$ wl-paste --list-types
application/x-ruby
This commit fixes that by telling wl-copy that all text copied from
Nvim has the mime type `text/plain`.
$ cat test.rb | wl-copy --type text/plain
$ wl-paste --list-types
text/plain;charset=utf-8
The neovim module is available for backwards compatibility. We should
not yet force the use of the pynvim module, since there's no other major
reason to bump the minimum supported Python client module.
Closes#9426
Before this commit, if user does this:
let g:node_host_prog = '~/.nvm/versions/node/v11.3.0/bin/neovim-node-host'
the "~/" is not expanded to user's home directory.
`:help g:ruby_host_prog` suggests a path with "~/" so technically we
already claimed to support this.
closes https://github.com/neovim/node-client/issues/102
PR #9304 added support for functions in clipboard providers. As part of
the PR I meant to move two checks in the provider code out of an if
statement into separate statements and adding additional checks for
g:clipboard attributes - as it turns out the code is wrong and it does
not implement additional checks while it adds two conditions that make
very little sense
type(g:clipboard['copy']) #isnot# v:t_func
what would make sense would be something along the lines of
type(g:clipboard['copy']['+']) #isnot# v:t_func
but might not be what we want either, so I'm reverting this.
Up to now g:clipboard["copy"] only supported string values invoked as
system commands.
This commit enables the use of VimL functions instead. The function
signatures are the same as in provider/clipboard.vim. A clipboard
provider is expected to store and return a list of lines (i.e. the text)
and a register type (as seen in setreg()).
cache_enabled is ignored if "copy" is provided by a VimL function.
The order was swapped in #4150 to prefer `xsel` but there wasn't a clear
explanation. Meanwhile, `xsel` has been neglected upstream.
Let's trying preferring `xclip` again, we've had a few reports of
problems with `xsel`.
closes#7237
ref #5853
ref #7449
Update runtime files.
fc65cabb15
---
vim-patch:8.0.1279: initializing menus can be slow
Problem: Initializing menus can be slow, especially when there are many
keymaps, color schemes, etc.
Solution: Do the globbing for runtime files lazlily. (Ken Takata)
man#init_pager() guesses the ref by the heading, which is usually
uppercase, so we don't know the correct casing. But lowercase is more
common, so use that for the buffer name instead of uppercase.
ref #9156
Before this commit, man#init_pager() always tries to scrape the manpage
name and set the buffer name. That's much less important than avoiding
duplicate buffers and E95. And it doesn't seem to be necessary, usually.
Steps to reproduce:
$ export MANPAGER="nvim -c 'set ft=man' -"
$ man sleep
:Man sleep
Error detected while processing function man#init_pager:
line 15:
E95: Buffer with this name already exists
:ls!
1 h- "man://SLEEP(1)" line 4
2 %a- "man://sleep(1)" line 1
For each package manager,
1. Check if they are executable before starting a job.
2. Check if the job opts are set before checking the job status
TODO: Validate the job id.
Prioritize npm because it's faster than yarn.
Reindent the code to 2-space indent.
When nroff justifies a line, it fills the line with whitespace to meet
$MANWIDTH. With $MANWIDTH=9999, that of course results in nonsense (and
behaves poorly with 'cursorline' option).
To work around that, instead of trying to hard-justify the lines, just
replace the mega-whitespace with a fixed size of 10 spaces.
Perhaps N/Vim needs a "soft justify" feature?
When rbenv is used for managing Ruby installations, just checking for an
executable called "neovim-ruby-host" is not enough. It has to be run as well.
If it does not return 0, then neovim-ruby-host is merely a shim for another Ruby
installation.
$ rbenv versions
2.5.0
* 2.5.1 (set by /Users/mhi/.rbenv/version)
$ rbenv whence neovim-ruby-host
2.5.0
$ which neovim-ruby-host
/Users/mhi/.rbenv/shims/neovim-ruby-host
$ neovim-ruby-host
rbenv: neovim-ruby-host: command not found
The `neovim-ruby-host' command exists in these Ruby versions:
2.5.0
$ echo $?
127
Additionally, the detection logic was moved from provider#ruby#Detect() to
s:detect(), because the former is run in the sandbox which forbids calling
system().
This would need to get `expand`ed to not become empty, and is being
handled by s:check_bin already.
`s:check_bin` will also complain about e.g.
"~/.pyenv/versions/3.6.6/bin/python" not being executable, but that
reflects that the host will fail to start with it.
Fixes#8778
Compare `$VIRTUAL_ENV` to `python_bin`.
This is necessary when `g:python_host_prog` is set to an absolute path,
and looking up `pyname` in `$PATH` yields another result.
OpenBSD's man returns all candidates when searching with -w instead of
the first one it finds. So this patch takes the first one if multiple
entries are found.
closes#8372closes#8341
Remove "" from sys.path (typically the first entry), which could cause
e.g. "logging" to be added from the current directory.
This gets done already for loading the host in
runtime/autoload/provider/pythonx.vim.
Problem: Loading file type detection slows down startup.
Solution: Move functions to an autoload script.
851ee6c3da
---
vim-patch:8.0.0635
Problem: When 'ignorecase' is set script detection is inaccurate.
Solution: Enforce matching case for text. (closes#1753)
I have `g:python3_host_prog` set to the system Python, where a package
is also installed to provide the "neovim" module.
`:checkhealth provider` however displays a warning for this:
> Your virtualenv is not set up optimally.
This is because /usr/bin/python is not in /home/user/.pyenv.
I think this warning should not get displayed if host_prog_var exists.
It goes back to the initial commit (20447ba09), and is maybe only
missing the `!` there as with the previous commit.
Full output:
```
- INFO: pyenv: /home/user/.pyenv/libexec/pyenv
- INFO: pyenv root: /home/user/.pyenv
- INFO: Using: g:python3_host_prog = "/usr/bin/python"
- WARNING: Your virtualenv is not set up optimally (/usr/bin/python is not in /home/user/.pyenv).
- ADVICE:
- Create a virtualenv specifically for Neovim and use `g:python3_host_prog`. This will avoid the need to install Neovim's Python module in each virtualenv.
- WARNING: $VIRTUAL_ENV exists but appears to be inactive. This could lead to unexpected results.
- ADVICE:
- If you are using Zsh, see: http://vi.stackexchange.com/a/7654
- INFO: Executable: /usr/bin/python
- INFO: Python3 version: 3.6.4
- INFO: python-neovim version: 0.2.1
- OK: Latest python-neovim is installed: 0.2.1
```
`g:loaded_python3_provider` gets set when the autoload file is sourced,
but this might error out, e.g. with deoplete:
[deoplete] Failed to load python3 host. You can try to see what happened by starting nvim with $NVIM_PYTHON_LOG_FILE set and opening the generated log file. Also, the host stderr is available in messages.
[deoplete] function remote#define#FunctionBootstrap[1]..remote#host#Require[10]..provider#pythonx#Require[13]..provider#Poll, line 14
[deoplete] deoplete requires Python3 support("+python3").
[deoplete] deoplete failed to load. Try the :UpdateRemotePlugins command and restart Neovim. See also :checkhealth.
It refers to `:checkhealth` from there explicitly, which would then
(without this patch) say that Python 3 is disabled.
This patch changes the reported info to include that it might have been
disabled due to some error, and keeps on going.
If `jobstart()` fails, then the subsequent `rpcrequest()` will throw due
to an invalid channel id. This causes `job.stderr` not to exist, so we
throw another exception when trying to dump the job's stderr.
Error detected while processing function remote#define#AutocmdBootstrap[1]..remote#host#Require[10]..provider#pythonx#Require:
line 22:
E716: Key not present in Dictionary: stderr
This obfuscates the actual problem.
On some versions of macOS, pbcopy doesn't work in tmux <2.6
https://superuser.com/q/231130
Fallback to tmux in that case.
Add a healthcheck for this scenario.
The argument expansion for :Man depends on the number of arguments given to it
starting at the command itself. But user completion functions always provide the
entire command-line which can include modifier commands like :tab, :vert, etc.
leading to a wrong number of arguments.
Prune all arguments up to :Man.
Fixes#7872.
For back-compat, :CheckHealth runs :checkhealth. But don't define
:CheckHealth explicitly, it adds noise to wildmenu completion.
Completion of healthchecks doesn't yet work with :checkhealth, this is
a regression but it needs to be implemented for :checkhealth rather than
keeping :CheckHealth around.
vim-patch:8.0.1206: no autocmd for entering or leaving the command line
(commit a4f6cec7a3)
NA patches:
vim-patch:8.0.0320: warning for unused variable with small build
ci: install nodejs 8 in Appveyor, Travis
provider: check node version for debug support
Resolve https://github.com/neovim/neovim/pull/7577#issuecomment-350590592 for Unix.
provider: test if nodejs in ci supports --inspect-brk
nodejs host for neovim requires nodejs 6+ to work properly.
nodejs 6.12+ or 7.6+ is required for debug support via `node --inspect-brk`.
provider: run cli.js of nodejs host directly
npm shims are useless because the user cannot set node to debug mode via
--inspect-brk. This is problematic on Windows which use batchfiles and
shell scripts to compensate for not supporting shebang.
The patch uses `npm root -g` to get the absolute path of the global npm
modules. If that fails, then the user did not install neovim npm package
globally. Use that absolute path to find `neovim/bin/cli.js`, which is
what the npm shim actually runs with node. glob() is for a simple file
check in case bin/ is removed because the npm shims are ignored now.
ruby uses batchfiles with 'cmd' extension.
gem creates batchfiles with 'bat' extension.
`gem install rails` does the following in Windows (not Cygwin):
1. Run `gem.cmd install rails` on cmd.exe
2. gem.cmd runs `ruby.exe -x gem install rails`
3. `rails` gem is installed.
`rails.bat` is created in the same directory
where ruby.exe and gem.cmd reside.
neovim-ruby-host is a ruby script.
neovim-node-host is a shell script.
Both don't work in cmd.exe so gem and npm provide batchfile shims.
Return the full path of these shims, cmd.exe knows better what to do with these files.
Fix bug that checked for npm AND yarn, where we wanted npm OR yarn.
But since we call `npm` exclusively, and it's highly unlikely you have
yarn installed without npm, let's just remove the yarn check altogether.
Addresses https://github.com/neovim/node-client/issues/41
:checkhealth reports that remote plugins are unregistered
after running :UpdateRemotePlugins because of the backslashes in filepath.
Normalize them to forward slashes because the paths in rplugin.vim are normalized in autoload/remote/host.vim.