coc.vim 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. scriptencoding utf-8
  2. let s:root = expand('<sfile>:h:h:h')
  3. function! s:checkVim(test, name, patchlevel) abort
  4. if a:test
  5. if !has(a:patchlevel)
  6. call health#report_error(a:name . ' version not satisfied, ' . a:patchlevel . ' and above required')
  7. return 0
  8. else
  9. call health#report_ok(a:name . ' version satisfied')
  10. return 1
  11. endif
  12. endif
  13. return 0
  14. endfunction
  15. function! s:checkEnvironment() abort
  16. let valid
  17. \ = s:checkVim(has('nvim'), 'nvim', 'nvim-0.4.0')
  18. \ + s:checkVim(!has('nvim'), 'vim', 'patch-8.1.1719')
  19. let node = get(g:, 'coc_node_path', $COC_NODE_PATH == '' ? 'node' : $COC_NODE_PATH)
  20. if !executable(node)
  21. let valid = 0
  22. call health#report_error('Executable node.js not found, install node.js from http://nodejs.org/')
  23. endif
  24. let output = system(node . ' --version')
  25. if v:shell_error && output !=# ""
  26. let valid = 0
  27. call health#report_error(output)
  28. endif
  29. let ms = matchlist(output, 'v\(\d\+\).\(\d\+\).\(\d\+\)')
  30. if empty(ms)
  31. let valid = 0
  32. call health#report_error('Unable to detect version of node, make sure your node executable is http://nodejs.org/')
  33. elseif str2nr(ms[1]) < 12 || (str2nr(ms[1]) == 12 && str2nr(ms[2]) < 12)
  34. let valid = 0
  35. call health#report_warn('Node.js version '.trim(output).' < 12.12.0, please upgrade node.js')
  36. endif
  37. if valid
  38. call health#report_ok('Environment check passed')
  39. endif
  40. if has('pythonx')
  41. try
  42. silent pyx print("")
  43. catch /.*/
  44. call health#report_warn('pyx command not work, some extensions may fail to work, checkout ":h pythonx"')
  45. if has('nvim')
  46. call health#report_warn('Install pynvim by command: pip install pynvim --upgrade')
  47. endif
  48. endtry
  49. endif
  50. return valid
  51. endfunction
  52. function! s:checkCommand()
  53. let file = s:root.'/build/index.js'
  54. if filereadable(file)
  55. call health#report_ok('Javascript bundle build/index.js found')
  56. else
  57. call health#report_error('Javascript entry not found, please compile coc.nvim by esbuild.')
  58. endif
  59. endfunction
  60. function! s:checkAutocmd()
  61. let cmds = ['CursorHold', 'CursorHoldI', 'CursorMovedI', 'InsertCharPre', 'TextChangedI']
  62. for cmd in cmds
  63. let lines = split(execute('verbose autocmd '.cmd), '\n')
  64. let n = 0
  65. for line in lines
  66. if line =~# 'CocAction(' && n < len(lines) - 1
  67. let next = lines[n + 1]
  68. let ms = matchlist(next, 'Last set from \(.*\)')
  69. if !empty(ms)
  70. call health#report_warn('Use CocActionAsync to replace CocAction for better performance on '.cmd)
  71. call health#report_warn('Checkout the file '.ms[1])
  72. endif
  73. endif
  74. let n = n + 1
  75. endfor
  76. endfor
  77. endfunction
  78. function! s:checkInitialize() abort
  79. if coc#client#is_running('coc')
  80. call health#report_ok('Service started')
  81. return 1
  82. endif
  83. call health#report_error('service could not be initialized', [
  84. \ 'Use command ":messages" to get error messages.',
  85. \ 'Open a issue at https://github.com/neoclide/coc.nvim/issues for feedback.'
  86. \])
  87. return 0
  88. endfunction
  89. function! health#coc#check() abort
  90. call s:checkEnvironment()
  91. call s:checkCommand()
  92. call s:checkInitialize()
  93. call s:checkAutocmd()
  94. endfunction