nvim.vim 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 writeable = v:true
  38. let shadafile = empty(&shada) ? &shada : substitute(matchstr(
  39. \ split(&shada, ',')[-1], '^n.\+'), '^n', '', '')
  40. let shadafile = empty(&shadafile) ? empty(shadafile) ?
  41. \ stdpath('state').'/shada/main.shada' : expand(shadafile)
  42. \ : &shadafile ==# 'NONE' ? '' : &shadafile
  43. if !empty(shadafile) && empty(glob(shadafile))
  44. " Since this may be the first time neovim has been run, we will try to
  45. " create a shada file
  46. try
  47. wshada
  48. catch /.*/
  49. let writeable = v:false
  50. endtry
  51. endif
  52. if !writeable || (!empty(shadafile) &&
  53. \ (!filereadable(shadafile) || !filewritable(shadafile)))
  54. let ok = v:false
  55. call health#report_error('shada file is not '.
  56. \ ((!writeable || filereadable(shadafile)) ?
  57. \ 'writeable' : 'readable').":\n".shadafile)
  58. endif
  59. if ok
  60. call health#report_ok('no issues found')
  61. endif
  62. endfunction
  63. " Load the remote plugin manifest file and check for unregistered plugins
  64. function! s:check_rplugin_manifest() abort
  65. call health#report_start('Remote Plugins')
  66. let existing_rplugins = {}
  67. for item in remote#host#PluginsForHost('python')
  68. let existing_rplugins[item.path] = 'python'
  69. endfor
  70. for item in remote#host#PluginsForHost('python3')
  71. let existing_rplugins[item.path] = 'python3'
  72. endfor
  73. let require_update = 0
  74. for path in map(split(&runtimepath, ','), 'resolve(v:val)')
  75. let python_glob = glob(path.'/rplugin/python*', 1, 1)
  76. if empty(python_glob)
  77. continue
  78. endif
  79. let python_dir = python_glob[0]
  80. let python_version = fnamemodify(python_dir, ':t')
  81. for script in glob(python_dir.'/*.py', 1, 1)
  82. \ + glob(python_dir.'/*/__init__.py', 1, 1)
  83. let contents = join(readfile(script))
  84. if contents =~# '\<\%(from\|import\)\s\+neovim\>'
  85. if script =~# '[\/]__init__\.py$'
  86. let script = tr(fnamemodify(script, ':h'), '\', '/')
  87. endif
  88. if !has_key(existing_rplugins, script)
  89. let msg = printf('"%s" is not registered.', fnamemodify(path, ':t'))
  90. if python_version ==# 'pythonx'
  91. if !has('python3')
  92. let msg .= ' (python3 not available)'
  93. endif
  94. elseif !has(python_version)
  95. let msg .= printf(' (%s not available)', python_version)
  96. else
  97. let require_update = 1
  98. endif
  99. call health#report_warn(msg)
  100. endif
  101. break
  102. endif
  103. endfor
  104. endfor
  105. if require_update
  106. call health#report_warn('Out of date', ['Run `:UpdateRemotePlugins`'])
  107. else
  108. call health#report_ok('Up to date')
  109. endif
  110. endfunction
  111. function! s:check_performance() abort
  112. call health#report_start('Performance')
  113. " check buildtype
  114. let buildtype = matchstr(execute('version'), '\v\cbuild type:?\s*[^\n\r\t ]+')
  115. if empty(buildtype)
  116. call health#report_error('failed to get build type from :version')
  117. elseif buildtype =~# '\v(MinSizeRel|Release|RelWithDebInfo)'
  118. call health#report_ok(buildtype)
  119. else
  120. call health#report_info(buildtype)
  121. call health#report_warn(
  122. \ 'Non-optimized '.(has('debug')?'(DEBUG) ':'').'build. Nvim will be slower.',
  123. \ ['Install a different Nvim package, or rebuild with `CMAKE_BUILD_TYPE=RelWithDebInfo`.',
  124. \ s:suggest_faq])
  125. endif
  126. " check for slow shell invocation
  127. let slow_cmd_time = 1.5
  128. let start_time = reltime()
  129. call system('echo')
  130. let elapsed_time = reltimefloat(reltime(start_time))
  131. if elapsed_time > slow_cmd_time
  132. call health#report_warn(
  133. \ 'Slow shell invocation (took '.printf('%.2f', elapsed_time).' seconds).')
  134. endif
  135. endfunction
  136. function! s:get_tmux_option(option) abort
  137. let cmd = 'tmux show-option -qvg '.a:option " try global scope
  138. let out = system(split(cmd))
  139. let val = substitute(out, '\v(\s|\r|\n)', '', 'g')
  140. if v:shell_error
  141. call health#report_error('command failed: '.cmd."\n".out)
  142. return 'error'
  143. elseif empty(val)
  144. let cmd = 'tmux show-option -qvgs '.a:option " try session scope
  145. let out = system(split(cmd))
  146. let val = substitute(out, '\v(\s|\r|\n)', '', 'g')
  147. if v:shell_error
  148. call health#report_error('command failed: '.cmd."\n".out)
  149. return 'error'
  150. endif
  151. endif
  152. return val
  153. endfunction
  154. function! s:check_tmux() abort
  155. if empty($TMUX) || !executable('tmux')
  156. return
  157. endif
  158. call health#report_start('tmux')
  159. " check escape-time
  160. let suggestions = ["set escape-time in ~/.tmux.conf:\nset-option -sg escape-time 10",
  161. \ s:suggest_faq]
  162. let tmux_esc_time = s:get_tmux_option('escape-time')
  163. if tmux_esc_time !=# 'error'
  164. if empty(tmux_esc_time)
  165. call health#report_error('`escape-time` is not set', suggestions)
  166. elseif tmux_esc_time > 300
  167. call health#report_error(
  168. \ '`escape-time` ('.tmux_esc_time.') is higher than 300ms', suggestions)
  169. else
  170. call health#report_ok('escape-time: '.tmux_esc_time)
  171. endif
  172. endif
  173. " check focus-events
  174. let suggestions = ["(tmux 1.9+ only) Set `focus-events` in ~/.tmux.conf:\nset-option -g focus-events on"]
  175. let tmux_focus_events = s:get_tmux_option('focus-events')
  176. call health#report_info('Checking stuff')
  177. if tmux_focus_events !=# 'error'
  178. if empty(tmux_focus_events) || tmux_focus_events !=# 'on'
  179. call health#report_warn(
  180. \ "`focus-events` is not enabled. |'autoread'| may not work.", suggestions)
  181. else
  182. call health#report_ok('focus-events: '.tmux_focus_events)
  183. endif
  184. endif
  185. " check default-terminal and $TERM
  186. call health#report_info('$TERM: '.$TERM)
  187. let cmd = 'tmux show-option -qvg default-terminal'
  188. let out = system(split(cmd))
  189. let tmux_default_term = substitute(out, '\v(\s|\r|\n)', '', 'g')
  190. if empty(tmux_default_term)
  191. let cmd = 'tmux show-option -qvgs default-terminal'
  192. let out = system(split(cmd))
  193. let tmux_default_term = substitute(out, '\v(\s|\r|\n)', '', 'g')
  194. endif
  195. if v:shell_error
  196. call health#report_error('command failed: '.cmd."\n".out)
  197. elseif tmux_default_term !=# $TERM
  198. call health#report_info('default-terminal: '.tmux_default_term)
  199. call health#report_error(
  200. \ '$TERM differs from the tmux `default-terminal` setting. Colors might look wrong.',
  201. \ ['$TERM may have been set by some rc (.bashrc, .zshrc, ...).'])
  202. elseif $TERM !~# '\v(tmux-256color|screen-256color)'
  203. call health#report_error(
  204. \ '$TERM should be "screen-256color" or "tmux-256color" in tmux. Colors might look wrong.',
  205. \ ["Set default-terminal in ~/.tmux.conf:\nset-option -g default-terminal \"screen-256color\"",
  206. \ s:suggest_faq])
  207. endif
  208. " check for RGB capabilities
  209. let info = system(['tmux', 'show-messages', '-JT'])
  210. let has_tc = stridx(info, " Tc: (flag) true") != -1
  211. let has_rgb = stridx(info, " RGB: (flag) true") != -1
  212. if !has_tc && !has_rgb
  213. call health#report_warn(
  214. \ "Neither Tc nor RGB capability set. True colors are disabled. |'termguicolors'| won't work properly.",
  215. \ ["Put this in your ~/.tmux.conf and replace XXX by your $TERM outside of tmux:\nset-option -sa terminal-overrides ',XXX:RGB'",
  216. \ "For older tmux versions use this instead:\nset-option -ga terminal-overrides ',XXX:Tc'"])
  217. endif
  218. endfunction
  219. function! s:check_terminal() abort
  220. if !executable('infocmp')
  221. return
  222. endif
  223. call health#report_start('terminal')
  224. let cmd = 'infocmp -L'
  225. let out = system(split(cmd))
  226. let kbs_entry = matchstr(out, 'key_backspace=[^,[:space:]]*')
  227. let kdch1_entry = matchstr(out, 'key_dc=[^,[:space:]]*')
  228. if v:shell_error
  229. \ && (!has('win32')
  230. \ || empty(matchstr(out,
  231. \ 'infocmp: couldn''t open terminfo file .\+'
  232. \ ..'\%(conemu\|vtpcon\|win32con\)')))
  233. call health#report_error('command failed: '.cmd."\n".out)
  234. else
  235. call health#report_info('key_backspace (kbs) terminfo entry: '
  236. \ .(empty(kbs_entry) ? '? (not found)' : kbs_entry))
  237. call health#report_info('key_dc (kdch1) terminfo entry: '
  238. \ .(empty(kbs_entry) ? '? (not found)' : kdch1_entry))
  239. endif
  240. for env_var in ['XTERM_VERSION', 'VTE_VERSION', 'TERM_PROGRAM', 'COLORTERM', 'SSH_TTY']
  241. if exists('$'.env_var)
  242. call health#report_info(printf("$%s='%s'", env_var, eval('$'.env_var)))
  243. endif
  244. endfor
  245. endfunction
  246. function! health#nvim#check() abort
  247. call s:check_config()
  248. call s:check_performance()
  249. call s:check_rplugin_manifest()
  250. call s:check_terminal()
  251. call s:check_tmux()
  252. endfunction