mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor: rewrite clipboard provider healthchecks in Lua
This is required to remove the vimscript checkhealth functions.
This commit is contained in:
parent
5d387c3388
commit
41b7586cbb
@ -122,31 +122,6 @@ function! s:download(url) abort
|
|||||||
\ .'and `python`, cannot make web request'
|
\ .'and `python`, cannot make web request'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Check for clipboard tools.
|
|
||||||
function! s:check_clipboard() abort
|
|
||||||
call health#report_start('Clipboard (optional)')
|
|
||||||
|
|
||||||
if !empty($TMUX) && executable('tmux') && executable('pbpaste') && !s:cmd_ok('pbpaste')
|
|
||||||
let tmux_version = matchstr(system('tmux -V'), '\d\+\.\d\+')
|
|
||||||
call health#report_error('pbcopy does not work with tmux version: '.tmux_version,
|
|
||||||
\ ['Install tmux 2.6+. https://superuser.com/q/231130',
|
|
||||||
\ 'or use tmux with reattach-to-user-namespace. https://superuser.com/a/413233'])
|
|
||||||
endif
|
|
||||||
|
|
||||||
let clipboard_tool = provider#clipboard#Executable()
|
|
||||||
if exists('g:clipboard') && empty(clipboard_tool)
|
|
||||||
call health#report_error(
|
|
||||||
\ provider#clipboard#Error(),
|
|
||||||
\ ["Use the example in :help g:clipboard as a template, or don't set g:clipboard at all."])
|
|
||||||
elseif empty(clipboard_tool)
|
|
||||||
call health#report_warn(
|
|
||||||
\ 'No clipboard tool found. Clipboard registers (`"+` and `"*`) will not work.',
|
|
||||||
\ [':help clipboard'])
|
|
||||||
else
|
|
||||||
call health#report_ok('Clipboard tool found: '. clipboard_tool)
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Get the latest Nvim Python client (pynvim) version from PyPI.
|
" Get the latest Nvim Python client (pynvim) version from PyPI.
|
||||||
function! s:latest_pypi_version() abort
|
function! s:latest_pypi_version() abort
|
||||||
let pypi_version = 'unable to get pypi response'
|
let pypi_version = 'unable to get pypi response'
|
||||||
@ -745,8 +720,7 @@ function! s:check_perl() abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! health#provider#check() abort
|
function! health#provider2#check() abort
|
||||||
call s:check_clipboard()
|
|
||||||
call s:check_python()
|
call s:check_python()
|
||||||
call s:check_virtualenv()
|
call s:check_virtualenv()
|
||||||
call s:check_ruby()
|
call s:check_ruby()
|
55
runtime/lua/provider/health.lua
Normal file
55
runtime/lua/provider/health.lua
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- Returns true if `cmd` exits with success, else false.
|
||||||
|
local function cmd_ok(cmd)
|
||||||
|
vim.fn.system(cmd)
|
||||||
|
return vim.v.shell_error == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local function executable(exe)
|
||||||
|
return vim.fn.executable(exe) == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local function is_blank(s)
|
||||||
|
return s:find('^%s*$') ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local function clipboard()
|
||||||
|
vim.health.report_start('Clipboard (optional)')
|
||||||
|
|
||||||
|
if
|
||||||
|
os.getenv('TMUX')
|
||||||
|
and executable('tmux')
|
||||||
|
and executable('pbpaste')
|
||||||
|
and not cmd_ok('pbpaste')
|
||||||
|
then
|
||||||
|
local tmux_version = string.match(vim.fn.system('tmux -V'), '%d+%.%d+')
|
||||||
|
local advice = {
|
||||||
|
'Install tmux 2.6+. https://superuser.com/q/231130',
|
||||||
|
'or use tmux with reattach-to-user-namespace. https://superuser.com/a/413233',
|
||||||
|
}
|
||||||
|
vim.health.report_error('pbcopy does not work with tmux version: ' .. tmux_version, advice)
|
||||||
|
end
|
||||||
|
|
||||||
|
local clipboard_tool = vim.fn['provider#clipboard#Executable']()
|
||||||
|
if vim.g.clipboard and is_blank(clipboard_tool) then
|
||||||
|
local error_message = vim.fn['provider#clipboard#Error']()
|
||||||
|
vim.health.report_error(
|
||||||
|
error_message,
|
||||||
|
"Use the example in :help g:clipboard as a template, or don't set g:clipboard at all."
|
||||||
|
)
|
||||||
|
elseif is_blank(clipboard_tool) then
|
||||||
|
vim.health.report_warn(
|
||||||
|
'No clipboard tool found. Clipboard registers (`"+` and `"*`) will not work.',
|
||||||
|
':help clipboard'
|
||||||
|
)
|
||||||
|
else
|
||||||
|
vim.health.report_ok('Clipboard tool found: ' .. clipboard_tool)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.check()
|
||||||
|
clipboard()
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
Loading…
Reference in New Issue
Block a user