nvim.vim 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. let s:suggest_faq = 'https://github.com/neovim/neovim/wiki/FAQ'
  2. function! s:check_config() abort
  3. let ok = v:true
  4. call health#report_start('Configuration')
  5. let vimrc = empty($MYVIMRC) ? stdpath('config').'/init.vim' : $MYVIMRC
  6. if !filereadable(vimrc)
  7. let ok = v:false
  8. let has_vim = filereadable(expand('~/.vimrc'))
  9. call health#report_warn((-1 == getfsize(vimrc) ? 'Missing' : 'Unreadable').' user config file: '.vimrc,
  10. \[ has_vim ? ':help nvim-from-vim' : ':help init.vim' ])
  11. endif
  12. " If $VIM is empty we don't care. Else make sure it is valid.
  13. if !empty($VIM) && !filereadable($VIM.'/runtime/doc/nvim.txt')
  14. let ok = v:false
  15. call health#report_error('$VIM is invalid: '.$VIM)
  16. endif
  17. if exists('$NVIM_TUI_ENABLE_CURSOR_SHAPE')
  18. let ok = v:false
  19. call health#report_warn('$NVIM_TUI_ENABLE_CURSOR_SHAPE is ignored in Nvim 0.2+',
  20. \ [ "Use the 'guicursor' option to configure cursor shape. :help 'guicursor'",
  21. \ 'https://github.com/neovim/neovim/wiki/Following-HEAD#20170402' ])
  22. endif
  23. if v:ctype ==# 'C'
  24. let ok = v:false
  25. call health#report_error('Locale does not support UTF-8. Unicode characters may not display correctly.'
  26. \ .printf("\n$LANG=%s $LC_ALL=%s $LC_CTYPE=%s", $LANG, $LC_ALL, $LC_CTYPE),
  27. \ [ 'If using tmux, try the -u option.',
  28. \ 'Ensure that your terminal/shell/tmux/etc inherits the environment, or set $LANG explicitly.' ,
  29. \ 'Configure your system locale.' ])
  30. endif
  31. if &paste
  32. let ok = v:false
  33. call health#report_error("'paste' is enabled. This option is only for pasting text.\nIt should not be set in your config.",
  34. \ [ 'Remove `set paste` from your init.vim, if applicable.',
  35. \ 'Check `:verbose set paste?` to see if a plugin or script set the option.', ])
  36. endif
  37. let shadafile = (empty(&shadafile) || &shadafile ==# 'NONE') ? stdpath('data').'/shada/main.shada' : &shadafile
  38. if !empty(shadafile) && (!filereadable(shadafile) || !filewritable(shadafile))
  39. let ok = v:false
  40. call health#report_error('shada file is not '.(filereadable(shadafile) ? 'writeable' : 'readable').":\n".shadafile)
  41. endif
  42. if ok
  43. call health#report_ok('no issues found')
  44. endif
  45. endfunction
  46. " Load the remote plugin manifest file and check for unregistered plugins
  47. function! s:check_rplugin_manifest() abort
  48. call health#report_start('Remote Plugins')
  49. let existing_rplugins = {}
  50. for item in remote#host#PluginsForHost('python')
  51. let existing_rplugins[item.path] = 'python'
  52. endfor
  53. for item in remote#host#PluginsForHost('python3')
  54. let existing_rplugins[item.path] = 'python3'
  55. endfor
  56. let require_update = 0
  57. for path in map(split(&runtimepath, ','), 'resolve(v:val)')
  58. let python_glob = glob(path.'/rplugin/python*', 1, 1)
  59. if empty(python_glob)
  60. continue
  61. endif
  62. let python_dir = python_glob[0]
  63. let python_version = fnamemodify(python_dir, ':t')
  64. for script in glob(python_dir.'/*.py', 1, 1)
  65. \ + glob(python_dir.'/*/__init__.py', 1, 1)
  66. let contents = join(readfile(script))
  67. if contents =~# '\<\%(from\|import\)\s\+neovim\>'
  68. if script =~# '[\/]__init__\.py$'
  69. let script = tr(fnamemodify(script, ':h'), '\', '/')
  70. endif
  71. if !has_key(existing_rplugins, script)
  72. let msg = printf('"%s" is not registered.', fnamemodify(path, ':t'))
  73. if python_version ==# 'pythonx'
  74. if !has('python2') && !has('python3')
  75. let msg .= ' (python2 and python3 not available)'
  76. endif
  77. elseif !has(python_version)
  78. let msg .= printf(' (%s not available)', python_version)
  79. else
  80. let require_update = 1
  81. endif
  82. call health#report_warn(msg)
  83. endif
  84. break
  85. endif
  86. endfor
  87. endfor
  88. if require_update
  89. call health#report_warn('Out of date', ['Run `:UpdateRemotePlugins`'])
  90. else
  91. call health#report_ok('Up to date')
  92. endif
  93. endfunction
  94. function! s:check_performance() abort
  95. call health#report_start('Performance')
  96. " check buildtype
  97. let buildtype = matchstr(execute('version'), '\v\cbuild type:?\s*[^\n\r\t ]+')
  98. if empty(buildtype)
  99. call health#report_error('failed to get build type from :version')
  100. elseif buildtype =~# '\v(MinSizeRel|Release|RelWithDebInfo)'
  101. call health#report_ok(buildtype)
  102. else
  103. call health#report_info(buildtype)
  104. call health#report_warn(
  105. \ 'Non-optimized '.(has('debug')?'(DEBUG) ':'').'build. Nvim will be slower.',
  106. \ ['Install a different Nvim package, or rebuild with `CMAKE_BUILD_TYPE=RelWithDebInfo`.',
  107. \ s:suggest_faq])
  108. endif
  109. endfunction
  110. function! s:check_tmux() abort
  111. if empty($TMUX) || !executable('tmux')
  112. return
  113. endif
  114. call health#report_start('tmux')
  115. " check escape-time
  116. let suggestions = ["Set escape-time in ~/.tmux.conf:\nset-option -sg escape-time 10",
  117. \ s:suggest_faq]
  118. let cmd = 'tmux show-option -qvgs escape-time'
  119. let out = system(cmd)
  120. let tmux_esc_time = substitute(out, '\v(\s|\r|\n)', '', 'g')
  121. if v:shell_error
  122. call health#report_error('command failed: '.cmd."\n".out)
  123. elseif empty(tmux_esc_time)
  124. call health#report_error('escape-time is not set', suggestions)
  125. elseif tmux_esc_time > 300
  126. call health#report_error(
  127. \ 'escape-time ('.tmux_esc_time.') is higher than 300ms', suggestions)
  128. else
  129. call health#report_ok('escape-time: '.tmux_esc_time.'ms')
  130. endif
  131. " check default-terminal and $TERM
  132. call health#report_info('$TERM: '.$TERM)
  133. let cmd = 'tmux show-option -qvg default-terminal'
  134. let out = system(cmd)
  135. let tmux_default_term = substitute(out, '\v(\s|\r|\n)', '', 'g')
  136. if empty(tmux_default_term)
  137. let cmd = 'tmux show-option -qvgs default-terminal'
  138. let out = system(cmd)
  139. let tmux_default_term = substitute(out, '\v(\s|\r|\n)', '', 'g')
  140. endif
  141. if v:shell_error
  142. call health#report_error('command failed: '.cmd."\n".out)
  143. elseif tmux_default_term !=# $TERM
  144. call health#report_info('default-terminal: '.tmux_default_term)
  145. call health#report_error(
  146. \ '$TERM differs from the tmux `default-terminal` setting. Colors might look wrong.',
  147. \ ['$TERM may have been set by some rc (.bashrc, .zshrc, ...).'])
  148. elseif $TERM !~# '\v(tmux-256color|screen-256color)'
  149. call health#report_error(
  150. \ '$TERM should be "screen-256color" or "tmux-256color" in tmux. Colors might look wrong.',
  151. \ ["Set default-terminal in ~/.tmux.conf:\nset-option -g default-terminal \"screen-256color\"",
  152. \ s:suggest_faq])
  153. endif
  154. " check for RGB capabilities
  155. let info = system('tmux server-info')
  156. let has_tc = stridx(info, " Tc: (flag) true") != -1
  157. let has_rgb = stridx(info, " RGB: (flag) true") != -1
  158. if !has_tc && !has_rgb
  159. call health#report_warn(
  160. \ "Neither Tc nor RGB capability set. True colors are disabled. |'termguicolors'| won't work properly.",
  161. \ ["Put this in your ~/.tmux.conf and replace XXX by your $TERM outside of tmux:\nset-option -sa terminal-overrides ',XXX:RGB'",
  162. \ "For older tmux versions use this instead:\nset-option -ga terminal-overrides ',XXX:Tc'"])
  163. endif
  164. endfunction
  165. function! s:check_terminal() abort
  166. if !executable('infocmp')
  167. return
  168. endif
  169. call health#report_start('terminal')
  170. let cmd = 'infocmp -L'
  171. let out = system(cmd)
  172. let kbs_entry = matchstr(out, 'key_backspace=[^,[:space:]]*')
  173. let kdch1_entry = matchstr(out, 'key_dc=[^,[:space:]]*')
  174. if v:shell_error
  175. call health#report_error('command failed: '.cmd."\n".out)
  176. else
  177. call health#report_info('key_backspace (kbs) terminfo entry: '
  178. \ .(empty(kbs_entry) ? '? (not found)' : kbs_entry))
  179. call health#report_info('key_dc (kdch1) terminfo entry: '
  180. \ .(empty(kbs_entry) ? '? (not found)' : kdch1_entry))
  181. endif
  182. for env_var in ['XTERM_VERSION', 'VTE_VERSION', 'TERM_PROGRAM', 'COLORTERM', 'SSH_TTY']
  183. if exists('$'.env_var)
  184. call health#report_info(printf("$%s='%s'", env_var, eval('$'.env_var)))
  185. endif
  186. endfor
  187. endfunction
  188. function! health#nvim#check() abort
  189. call s:check_config()
  190. call s:check_performance()
  191. call s:check_rplugin_manifest()
  192. call s:check_terminal()
  193. call s:check_tmux()
  194. endfunction