robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local nvim_on =require ( 'vim._core.util' ). nvim_on 2 3local M ={} 4local async =require ( 'vim.async' ) --- @type vim.async._core 5local health =require ( 'vim.health' ) 6 7---@async 8---@param cmd string[] 9---@param opts? vim.SystemOpts 10---@return vim.SystemCompleted 11local function run_system ( cmd , opts ) 12--- @diagnostic disable-next-line: assign-type-mismatch 13local result =async . await ( 3 , vim . system , cmd , opts ) --- @type vim.SystemCompleted 14async . await ( vim . schedule ) 15return result 16end 17 18---Run a system command and return ok and its stdout and stderr combined. 19---@async 20---@param cmd string[] 21---@param timeout? integer Timeout in ms (default: no timeout). 22---@return boolean 23---@return string 24local function system ( cmd , timeout ) 25local result =run_system ( cmd , { text =true , timeout =timeout } ) 26if not result then -- Workaround https://github.com/neovim/neovim/issues/37922 27return false , 'command failed' 28end 29return result . code == 0 , vim . trim (( '%s\n%s' ): format ( result . stdout , result . stderr )) 30end 31 32local suggest_faq ='https://neovim.io/doc/build/#building' 33 34local function check_runtime () 35health . start ( 'Runtime' ) 36-- Files from an old installation. 37local bad_files ={ 38[ 'autoload/health/nvim.vim' ] =false , 39[ 'autoload/health/provider.vim' ] =false , 40[ 'autoload/man.vim' ] =false , 41[ 'lua/provider/node/health.lua' ] =false , 42[ 'lua/provider/perl/health.lua' ] =false , 43[ 'lua/provider/python/health.lua' ] =false , 44[ 'lua/provider/ruby/health.lua' ] =false , 45[ 'lua/vim/_defaults.lua' ] =false , 46[ 'lua/vim/_editor.lua' ] =false , 47[ 'lua/vim/_extui.lua' ] =false , 48[ 'lua/vim/_extui/cmdline.lua' ] =false , 49[ 'lua/vim/_extui/messages.lua' ] =false , 50[ 'lua/vim/_extui/shared.lua' ] =false , 51[ 'lua/vim/_options.lua' ] =false , 52[ 'lua/vim/_stringbuffer.lua' ] =false , 53[ 'lua/vim/_system.lua' ] =false , 54[ 'lua/vim/shared.lua' ] =false , 55[ 'plugin/health.vim' ] =false , 56[ 'plugin/man.vim' ] =false , 57[ 'plugin/nvim/net.lua' ] =false , 58[ 'plugin/nvim/spellfile.lua' ] =false , 59[ 'queries/help/highlights.scm' ] =false , 60[ 'queries/help/injections.scm' ] =false , 61[ 'scripts.vim' ] =false , 62[ 'syntax/syncolor.vim' ] =false , 63} 64local bad_files_msg ='' 65for k , _ in pairs ( bad_files ) do 66local path =( '%s/%s' ): format ( vim . env . VIMRUNTIME , k ) 67if vim . uv . fs_stat ( path ) then 68bad_files [ k ] =true 69bad_files_msg =( '%s%s\n' ): format ( bad_files_msg , path ) 70end 71end 72 73local ok =( bad_files_msg == '' ) 74local info =ok and health . ok or health . info 75info ( string . format ( '$VIMRUNTIME: %s' , vim . env . VIMRUNTIME )) 76if not ok then 77health . error ( 78string . format ( 79'Found old files in $VIMRUNTIME (this can cause weird behavior):\n%s' , 80bad_files_msg 81), 82{ 'Delete the $VIMRUNTIME directory, then reinstall Nvim.' } 83) 84end 85end 86 87local function check_config () 88health . start ( 'Configuration' ) 89local ok =true 90 91local init_lua =vim . fn . stdpath ( 'config' ) .. '/init.lua' 92local init_vim =vim . fn . stdpath ( 'config' ) .. '/init.vim' 93local vimrc =vim . env . MYVIMRC and vim . fs . normalize ( vim . env . MYVIMRC ) or init_lua 94 95if vim . fn . filereadable ( vimrc ) == 0 and vim . fn . filereadable ( init_vim ) == 0 then 96ok =false 97local has_vim =vim . fn . filereadable ( vim . fs . normalize ( '~/.vimrc' )) == 1 98health . warn ( 99( '%s user config file: %s' ): format ( 100- 1 == vim . fn . getfsize ( vimrc ) and 'Missing' or 'Unreadable' , 101vimrc 102), 103{ has_vim and ':help nvim-from-vim' or ':help config' } 104) 105end 106 107-- If $VIM is empty we don't care. Else make sure it is valid. 108if vim . env . VIM and vim . fn . filereadable ( vim . env . VIM .. '/runtime/doc/nvim.txt' ) == 0 then 109ok =false 110health . error ( '$VIM is invalid: ' .. vim . env . VIM ) 111end 112 113if vim . env . NVIM_TUI_ENABLE_CURSOR_SHAPE then 114ok =false 115health . warn ( '$NVIM_TUI_ENABLE_CURSOR_SHAPE is ignored in Nvim 0.2+' , { 116"Use the 'guicursor' option to configure cursor shape. :help 'guicursor'" , 117'https://github.com/neovim/neovim/wiki/Following-HEAD#20170402' , 118} ) 119end 120 121if vim . v . ctype == 'C' then 122ok =false 123health . error ( 124'Locale does not support UTF-8. Unicode characters may not display correctly.' 125.. ( '\n$LANG=%s $LC_ALL=%s $LC_CTYPE=%s' ): format ( 126vim . env . LANG or '' , 127vim . env . LC_ALL or '' , 128vim . env . LC_CTYPE or '' 129), 130{ 131'If using tmux, try the -u option.' , 132'Ensure that your terminal/shell/tmux/etc inherits the environment, or set $LANG explicitly.' , 133'Configure your system locale.' , 134} 135) 136end 137 138if vim . o . paste == 1 then 139ok =false 140health . error ( 141"'paste' is enabled. This option is only for pasting text.\nIt should not be set in your config." , 142{ 143'Remove `set paste` from your init.vim, if applicable.' , 144'Check `:verbose set paste?` to see if a plugin or script set the option.' , 145} 146) 147end 148 149local writeable =true 150local shadaopt =vim . fn . split ( vim . o . shada , ',' ) 151local shadafile =( 152vim . o . shada == '' and vim . o . shada 153or vim . fn . substitute ( vim . fn . matchstr ( shadaopt [ # shadaopt ], '^n.\\+' ), '^n' , '' , '' ) 154) 155shadafile =( 156vim . o . shadafile == '' 157and ( shadafile == '' and vim . fn . stdpath ( 'state' ) .. '/shada/main.shada' or vim . fs . normalize ( 158shadafile 159)) 160or ( vim . o . shadafile == 'NONE' and '' or vim . o . shadafile ) 161) 162if shadafile ~= '' and vim . fn . glob ( shadafile ) == '' then 163-- Since this may be the first time Nvim has been run, try to create a shada file. 164if not pcall ( vim . cmd . wshada ) then 165writeable =false 166end 167end 168if 169not writeable 170or ( 171shadafile ~= '' 172and ( vim . fn . filereadable ( shadafile ) == 0 or vim . fn . filewritable ( shadafile ) ~= 1 ) 173) 174then 175ok =false 176health . error ( 177'shada file is not ' 178.. (( not writeable or vim . fn . filereadable ( shadafile ) == 1 ) and 'writeable' or 'readable' ) 179.. ':\n' 180.. shadafile 181) 182end 183 184if ok then 185health . ok ( 'no issues found' ) 186end 187end 188 189-- Note: this is part of check_performance(). 190local function check_watchers () 191local a =vim . _watch . active () 192local total =a . watch + a . watchdirs + a . inotify 193health . info ( 194( 'Filewatchers (vim._watch): %d (watch=%d, watchdirs=%d, inotify=%d)' ): format ( 195total , 196a . watch , 197a . watchdirs , 198a . inotify 199) 200) 201 202-- Walk libuv for an independent view. These counts include handles created outside `vim._watch` 203-- (e.g. plugins calling `vim.uv.new_fs_event()` directly). 204local libuv ={ fs_event =0 , fs_poll =0 , process =0 , timer =0 } 205vim . uv . walk ( function ( handle ) 206if handle : is_closing () then 207return 208end 209local t =handle : get_type () 210if libuv [ t ] ~= nil then 211libuv [ t ] =libuv [ t ] + 1 212end 213end ) 214health . info ( 215( 'libuv handles: fs_event=%d, fs_poll=%d, process=%d, timer=%d' ): format ( 216libuv . fs_event , 217libuv . fs_poll , 218libuv . process , 219libuv . timer 220) 221) 222end 223 224--- Reads a single integer from a file (e.g. a `/proc/sys` entry). 225---@param path string 226---@return integer? 227local function read_int ( path ) 228local ok , lines =pcall ( vim . fn . readfile , path , '' , 1 ) 229local v =ok and lines [ 1 ] and tonumber ( lines [ 1 ]) 230return v or nil 231end 232 233-- Note: this is part of check_performance(). 234---@async 235local function check_limits () 236-- 'ulimit -n' (RLIMIT_NOFILE): each Nvim buffer may hold an open swapfile. Sockets, channels, filewatchers also consume file descriptors. 237if vim . fn . has ( 'win32' ) == 0 then 238local ok , out =system ( { 'sh' , '-c' , 'ulimit -Sn' } ) -- Must use a shell. 239out =vim . trim ( out or '' ) 240local soft =tonumber ( out ) 241local used =require ( 'vim._core.proc' ). count_open_fds () 242local used_str =used and ( ', currently open: %d' ): format ( used ) or '' 243local raise_advice ={ 244'\'swapfile\' buffers, sockets, channels, and file-watchers consume file descriptors. A low limit causes "(libuv) kqueue(): Too many open files" (EMFILE) errors.' , 245'Increase the limit: add `ulimit -n 8192` to your shell rc. On macOS see also `launchctl limit maxfiles`; on Linux see `/etc/security/limits.conf` and systemd `LimitNOFILE`.' , 246} 247if out == 'unlimited' then 248health . ok (( 'ulimit -n (max open files): unlimited%s' ): format ( used_str )) 249elseif not ok or soft == nil then 250health . info (( 'ulimit -n (max open files): unknown (%s)%s' ): format ( out , used_str )) 251elseif soft < 1024 then 252health . warn (( 'ulimit -n (max open files) is low: %d%s' ): format ( soft , used_str ), raise_advice ) 253elseif used and used > soft * 0.8 then 254health . warn ( 255( 'Open files near the limit: %d of %d (ulimit -n)' ): format ( used , soft ), 256raise_advice 257) 258else 259health . ok (( 'ulimit -n (max open files): %d%s' ): format ( soft , used_str )) 260end 261end 262 263-- Linux inotify limits filewatchers (LSP, vim._watch). Exhausting them reports ENOSPC ("no space on device"). 264if vim . uv . os_uname (). sysname == 'Linux' then 265local watches =read_int ( '/proc/sys/fs/inotify/max_user_watches' ) 266local instances =read_int ( '/proc/sys/fs/inotify/max_user_instances' ) 267if watches and watches < 8192 then 268health . warn (( 'fs.inotify.max_user_watches is low: %d' ): format ( watches ), { 269'Filewatchers may fail with ENOSPC. To increase the limit: `sysctl fs.inotify.max_user_watches=524288` (persist in /etc/sysctl.conf).' , 270} ) 271end 272if instances and instances < 128 then 273health . warn (( 'fs.inotify.max_user_instances is low: %d' ): format ( instances ), { 274'To increase the limit: `sysctl fs.inotify.max_user_instances=512` (persist in /etc/sysctl.conf).' , 275} ) 276end 277end 278end 279 280---@async 281local function check_performance () 282health . start ( 'Performance' ) 283 284-- Check buildtype 285local buildtype =vim . fn . matchstr ( vim . fn . execute ( 'version' ), [[\v\cbuild type:?\s*[^\n\r\t]+]] ) 286if buildtype == '' then 287health . error ( 'failed to get build type from :version' ) 288elseif 289vim . regex ( [[\v(MinSizeRel|RelWithDebInfo|Release(Fast|Safe|Small)?)]] ): match_str ( buildtype ) 290then 291health . ok ( buildtype ) 292else 293health . info ( buildtype ) 294health . warn ( 'Non-optimized debug build. Nvim will be slower.' , { 295'Install a different Nvim package, or rebuild with `CMAKE_BUILD_TYPE=RelWithDebInfo` (CMake) or `-Doptimize=ReleaseFast` (Zig).' , 296suggest_faq , 297} ) 298end 299 300-- check for slow shell invocation 301local slow_cmd_time =1.5e9 302local start_time =vim . uv . hrtime () 303-- Vimscript's system() is used to actually invoke a shell 304vim . fn . system ( 'echo 1' ) 305local elapsed_time =vim . uv . hrtime () - start_time 306if elapsed_time > slow_cmd_time then 307health . warn ( 308'Slow shell invocation (took ' .. vim . fn . printf ( '%.2f' , elapsed_time / 1e9 ) .. ' seconds).' 309) 310end 311 312check_watchers () 313check_limits () 314end 315 316-- Load the remote plugin manifest file and check for unregistered plugins 317local function check_rplugin_manifest () 318health . start ( 'Remote Plugins' ) 319 320local existing_rplugins ={} --- @type table<string,string> 321--- @type {path:string}[] 322local items =vim . fn [ 'remote#host#PluginsForHost' ]( 'python3' ) 323for _ , item in ipairs ( items ) do 324existing_rplugins [ item . path ] ='python3' 325end 326 327local require_update =false 328--- @param path string 329local function handle_path ( path ) 330--- @type string[] 331local python_glob =vim . fn . glob ( path .. '/rplugin/python*' , true , true ) 332if vim . tbl_isempty ( python_glob ) then 333return 334end 335 336local python_dir =assert ( python_glob [ 1 ]) 337local python_version =vim . fs . basename ( python_dir ) 338 339--- @type string[] 340local scripts =vim . fn . glob ( python_dir .. '/*.py' , true , true ) 341vim . list_extend ( scripts , vim . fn . glob ( python_dir .. '/*/__init__.py' , true , true )) 342 343for _ , script in ipairs ( scripts ) do 344local contents =vim . fn . join ( vim . fn . readfile ( script )) 345if vim . regex ( [[\<\%(from\|import\)\s\+neovim\>]] ): match_str ( contents ) then 346if vim . regex ( [[[\/]__init__\.py$]] ): match_str ( script ) then 347script =vim . fs . normalize ( vim . fs . dirname ( script )) 348end 349if not existing_rplugins [ script ] then 350local msg =vim . fn . printf ( '"%s" is not registered.' , vim . fs . basename ( path )) 351if python_version == 'pythonx' then 352if vim . fn . has ( 'python3' ) == 0 then 353msg =msg .. ' (python3 not available)' 354end 355elseif vim . fn . has ( python_version ) == 0 then 356msg =msg .. vim . fn . printf ( ' (%s not available)' , python_version ) 357else 358require_update =true 359end 360 361health . warn ( msg ) 362end 363 364break 365end 366end 367end 368 369--- @type string[] 370local paths =vim . fn . map ( vim . split ( vim . o . runtimepath , ',' ), 'resolve(v:val)' ) 371 372for _ , path in ipairs ( paths ) do 373handle_path ( path ) 374end 375 376if require_update then 377health . warn ( 'Out of date' , { 'Run `:UpdateRemotePlugins`' } ) 378else 379health . ok ( 'Up to date' ) 380end 381end 382 383---@async 384local function check_tmux () 385if not vim . env . TMUX or vim . fn . executable ( 'tmux' ) == 0 then 386return 387end 388 389---@async 390---@param option string 391local get_tmux_option =function ( option ) 392local cmd ={ 'tmux' , 'show-option' , '-qvg' , option } -- try global scope 393local ok , out =system ( cmd ) 394local val =vim . fn . substitute ( out , [[\v(\s|\r|\n)]] , '' , 'g' ) 395if not ok then 396health . error (( 'command failed: %s\n%s' ): format ( vim . inspect ( cmd ), out )) 397return 'error' 398elseif val == '' then 399cmd ={ 'tmux' , 'show-option' , '-qvgs' , option } -- try session scope 400ok , out =system ( cmd ) 401val =vim . fn . substitute ( out , [[\v(\s|\r|\n)]] , '' , 'g' ) 402if not ok then 403health . error (( 'command failed: %s\n%s' ): format ( vim . inspect ( cmd ), out )) 404return 'error' 405end 406end 407return val 408end 409 410health . start ( 'tmux' ) 411 412health . warn ( 'tmux is detected. Images may not display correctly.' ) 413 414-- check escape-time 415local suggestions = 416{ 'set escape-time in ~/.tmux.conf:\nset-option -sg escape-time 10' , suggest_faq } 417local tmux_esc_time =get_tmux_option ( 'escape-time' ) 418if tmux_esc_time ~= 'error' then 419if tmux_esc_time == '' then 420health . error ( '`escape-time` is not set' , suggestions ) 421else 422local tmux_esc_time_ms =vim . _tointeger ( tmux_esc_time ) 423if not tmux_esc_time_ms then 424health . error ( '`escape-time` (' .. tmux_esc_time .. ') is not an integer' , suggestions ) 425elseif tmux_esc_time_ms > 300 then 426health . error ( '`escape-time` (' .. tmux_esc_time .. ') is higher than 300ms' , suggestions ) 427else 428health . ok ( 'escape-time: ' .. tmux_esc_time ) 429end 430end 431end 432 433-- check focus-events 434local tmux_focus_events =get_tmux_option ( 'focus-events' ) 435if tmux_focus_events ~= 'error' then 436if tmux_focus_events == '' or tmux_focus_events ~= 'on' then 437health . warn ( 438"`focus-events` is not enabled. |'autoread'| may not work." , 439{ '(tmux 1.9+ only) Set `focus-events` in ~/.tmux.conf:\nset-option -g focus-events on' } 440) 441else 442health . ok ( 'focus-events: ' .. tmux_focus_events ) 443end 444end 445 446-- check default-terminal and $TERM 447health . info ( '$TERM: ' .. vim . env . TERM ) 448local cmd ={ 'tmux' , 'show-option' , '-qvg' , 'default-terminal' } 449local ok , out =system ( cmd ) 450local tmux_default_term =vim . fn . substitute ( out , [[\v(\s|\r|\n)]] , '' , 'g' ) 451if tmux_default_term == '' then 452cmd ={ 'tmux' , 'show-option' , '-qvgs' , 'default-terminal' } 453ok , out =system ( cmd ) 454tmux_default_term =vim . fn . substitute ( out , [[\v(\s|\r|\n)]] , '' , 'g' ) 455end 456 457if not ok then 458health . error (( 'command failed: %s\n%s' ): format ( vim . inspect ( cmd ), out )) 459elseif tmux_default_term ~= vim . env . TERM then 460health . info ( 'default-terminal: ' .. tmux_default_term ) 461health . error ( 462'$TERM differs from the tmux `default-terminal` setting. Colors might look wrong.' , 463{ '$TERM may have been set by some rc (.bashrc, .zshrc, ...).' } 464) 465elseif 466not vim . regex ( [[\v(tmux-256color|tmux-direct|screen-256color)]] ): match_str ( assert ( vim . env . TERM )) 467then 468health . error ( 469'$TERM should be "screen-256color", "tmux-256color", or "tmux-direct" in tmux. Colors might look wrong.' , 470{ 471'Set default-terminal in ~/.tmux.conf:\nset-option -g default-terminal "screen-256color"' , 472suggest_faq , 473} 474) 475end 476 477-- check for RGB capabilities 478local _ , info =system ( { 'tmux' , 'show-messages' , '-T' } ) 479local has_setrgbb =vim . fn . stridx ( info , ' setrgbb: (string)' ) ~= - 1 480local has_setrgbf =vim . fn . stridx ( info , ' setrgbf: (string)' ) ~= - 1 481if not has_setrgbb or not has_setrgbf then 482health . warn ( 483"True color support could not be detected. |'termguicolors'| won't work properly." , 484{ 485"Add the following to your tmux configuration file, replacing XXX by the value of $TERM outside of tmux:\nset-option -a terminal-features 'XXX:RGB'" , 486"For older tmux versions use this instead:\nset-option -a terminal-overrides 'XXX:Tc'" , 487} 488) 489end 490end 491 492-- Note: this is part of check_terminal(). 493local function check_graphics () 494local supported , msg =require ( 'vim.ui.img' ). _supported () 495 496if supported then 497if msg then 498health . ok (( 'Graphics protocol: supported (%s)' ): format ( msg )) 499else 500health . ok ( 'Graphics protocol: supported' ) 501end 502else 503health . error ( 'Graphics protocol: not supported by this terminal.' ) 504end 505end 506 507-- Note: this is part of check_terminal(). 508---@async 509local function check_infocmp () 510if vim . fn . executable ( 'infocmp' ) == 0 then 511return 512end 513 514local cmd ={ 'infocmp' , '-L' } 515local ok , out =system ( cmd ) 516local kbs_entry =vim . fn . matchstr ( out , 'key_backspace=[^,[:space:]]*' ) 517local kdch1_entry =vim . fn . matchstr ( out , 'key_dc=[^,[:space:]]*' ) 518 519if 520not ok 521and ( 522vim . fn . has ( 'win32' ) == 0 523or vim . fn . matchstr ( 524out , 525[[infocmp: couldn't open terminfo file .\+\%(conemu\|vtpcon\|win32con\)]] 526) 527== '' 528) 529then 530health . error (( 'command failed: %s\n%s' ): format ( vim . inspect ( cmd ), out )) 531else 532health . info ( 533vim . fn . printf ( 534'key_backspace (kbs) terminfo entry: `%s`' , 535( kbs_entry == '' and '? (not found)' or kbs_entry ) 536) 537) 538 539health . info ( 540vim . fn . printf ( 541'key_dc (kdch1) terminfo entry: `%s`' , 542( kdch1_entry == '' and '? (not found)' or kdch1_entry ) 543) 544) 545end 546end 547 548---@async 549local function check_terminal () 550health . start ( 'Terminal' ) 551 552check_graphics () 553 554check_infocmp () 555 556for _ , env_var in ipairs ( { 557'XTERM_VERSION' , 558'VTE_VERSION' , 559'TERM_PROGRAM' , 560'COLORTERM' , 561'SSH_TTY' , 562} ) do 563if vim . env [ env_var ] then 564health . info ( string . format ( '$%s="%s"' , env_var , vim . env [ env_var ])) 565end 566end 567end 568 569---@async 570local function check_external_tools () 571health . start ( 'External Tools' ) 572 573if vim . fn . executable ( 'rg' ) == 1 then 574local rg_path =vim . fn . exepath ( 'rg' ) 575local rg_job =run_system ( { rg_path , '-V' } ) 576if rg_job . code == 0 then 577health . ok (( '%s (%s)' ): format ( vim . trim ( assert ( rg_job . stdout )), rg_path )) 578else 579health . warn ( 'found `rg` but failed to run `rg -V`' , { rg_job . stderr } ) 580end 581else 582health . warn ( 'ripgrep not available' ) 583end 584 585local open_cmd , err =vim . ui . _get_open_cmd () 586if open_cmd then 587health . ok (( 'vim.ui.open: handler found (%s)' ): format ( open_cmd [ 1 ])) 588else 589--- @cast err string 590health . warn ( err ) 591end 592 593-- `vim.pack` prefers git 2.36 but tries to work with 2.x. 594if vim . fn . executable ( 'git' ) == 1 then 595local git =vim . fn . exepath ( 'git' ) 596local version =run_system ( { 'git' , 'version' } ). stdout or '' 597health . ok (( '%s (%s)' ): format ( vim . trim ( version ), git )) 598else 599health . warn ( 'git not available (required by `vim.pack`)' ) 600end 601 602if vim . fn . executable ( 'curl' ) == 1 then 603local curl_path =vim . fn . exepath ( 'curl' ) 604local curl_job =run_system ( { curl_path , '--version' } ) 605 606if curl_job . code == 0 then 607local curl_out =curl_job . stdout 608if not curl_out or curl_out == '' then 609health . warn ( 610string . format ( '`%s --version` produced no output' , curl_path ), 611{ curl_job . stderr } 612) 613return 614end 615local curl_version =vim . version . parse ( curl_out ) 616if not curl_version then 617health . warn ( 'Unable to parse curl version from `curl --version`' ) 618return 619end 620if vim . version . le ( curl_version , { 7 , 12 , 3 } ) then 621health . warn (( 'curl version %s not compatible' ): format ( curl_version )) 622return 623end 624local lines ={ string . format ( 'curl %s (%s)' , curl_version , curl_path ) } 625 626for line in vim . gsplit ( curl_out , '\n' , { plain =true } ) do 627if line ~= '' then 628table . insert ( lines , line ) 629end 630end 631 632-- Add subtitle only if any env var is present 633local added_env_header =false 634for _ , var in ipairs ( { 635'curl_ca_bundle' , 636'curl_home' , 637'curl_ssl_backend' , 638'ssl_cert_dir' , 639'ssl_cert_file' , 640'https_proxy' , 641'http_proxy' , 642'all_proxy' , 643'no_proxy' , 644} --[[@as string[] ]] ) do 645local val =vim . env [ var ] 646if not val then 647var =var : upper () 648val =vim . env [ var ] 649end 650if val then 651if not added_env_header then 652table . insert ( lines , 'curl-related environment variables:' ) 653added_env_header =true 654end 655table . insert ( lines , string . format ( ' %s=%s' , var , val )) 656end 657end 658 659health . ok ( table . concat ( lines , '\n' )) 660else 661health . warn ( 'curl is installed but failed to run `curl --version`' , { curl_job . stderr } ) 662end 663else 664health . error ( 'curl not found' , { 665'Required for vim.net.request() to function.' , 666'Install curl using your package manager.' , 667} ) 668end 669end 670 671local function detect_terminal () 672local e =vim . env 673if e . TERM_PROGRAM then 674local v =e . TERM_PROGRAM_VERSION --- @type string? 675return e . TERM_PROGRAM_VERSION and ( e . TERM_PROGRAM .. ' ' .. v ) or e . TERM_PROGRAM 676end 677 678local map ={ 679KITTY_WINDOW_ID ='kitty' , 680ALACRITTY_SOCKET ='alacritty' , 681ALACRITTY_LOG ='alacritty' , 682WEZTERM_EXECUTABLE ='wezterm' , 683KONSOLE_VERSION =function () 684return 'konsole ' .. e . KONSOLE_VERSION 685end , 686VTE_VERSION =function () 687return 'vte ' .. e . VTE_VERSION 688end , 689} 690 691for key , val in pairs ( map ) do 692local env =e [ key ] --- @type string? 693if env then 694return type ( val ) == 'function' and val () or val 695end 696end 697 698return 'unknown' 699end 700 701---@async 702---@param nvim_version string 703local function check_stable_version ( nvim_version ) 704local ok , output = 705system ( { 'git' , 'ls-remote' , '--tags' , 'https://github.com/neovim/neovim' } , 5000 ) 706if not ok or output == '' then 707return 708end 709local stable_sha =assert ( 710output : match ( '(%x+)%s+refs/tags/stable%^{}' ) or output : match ( '(%x+)%s+refs/tags/stable\n' ) 711) 712local latest_version =assert ( output : match ( stable_sha .. '%s+refs/tags/v?(%d+%.%d+%.%d+)%^{}' )) 713local current_version =assert ( nvim_version : match ( 'v?(%d+%.%d+%.%d+)' )) 714local current =vim . version . parse ( current_version ) 715local latest =vim . version . parse ( latest_version ) 716if current and latest and vim . version . lt ( current , latest ) then 717vim . health . warn (( 'Nvim %s is available (current: %s)' ): format ( latest_version , current_version )) 718else 719vim . health . ok (( 'Up to date (%s)' ): format ( current_version )) 720end 721end 722 723---@async 724---@param commit string 725local function check_head_hash ( commit ) 726local ok , output =system ( 727{ 'git' , 'ls-remote' , 'https://github.com/neovim/neovim' , 'HEAD' , 'refs/tags/nightly' } , 7285000 729) 730if not ok or output == '' then 731return 732end 733 734local refs ={} ---@type table<string, string?> 735for line in output : gmatch ( '[^\n]+' ) do 736local sha , ref =line : match ( '^(%x+)%s+(%S+)$' ) 737if sha and ref then 738refs [ ref ] =sha 739end 740end 741 742local head_sha =assert ( refs [ 'HEAD' ]) 743local nightly_sha =refs [ 'refs/tags/nightly' ] 744 745if vim . startswith ( head_sha , commit ) then 746vim . health . ok ( 'Up to date (HEAD)' ) 747elseif nightly_sha and vim . startswith ( nightly_sha , commit ) then 748vim . health . ok ( 'Up to date (nightly)' ) 749else 750vim . health . warn ( 751( 'Build is outdated. Local: %s, HEAD: %s%s' ): format ( 752commit , 753head_sha : sub ( 1 , 12 ), 754nightly_sha and ( ', Nightly: ' .. nightly_sha : sub ( 1 , 12 )) or '' 755) 756) 757end 758end 759 760---@async 761local function check_sysinfo () 762vim . health . start ( 'System Info' ) 763 764-- Use :version because `vim.version().build` returns "Homebrew" for brew installs. 765local version_out =vim . api . nvim_exec2 ( 'version' , { output =true } ). output --[[@as string]] 766local nvim_version =version_out : match ( 'NVIM (v[^\n]+)' ) or 'unknown' 767local commit =( version_out : match ( '%+g(%x+)' ) or '' ): sub ( 1 , 12 ) 768 769if vim . fn . executable ( 'git' ) ~= 1 then 770vim . health . warn ( 'Cannot check for updates: git not found' ) 771elseif vim . trim ( commit ) ~= '' then 772check_head_hash ( commit ) 773else 774check_stable_version ( nvim_version ) 775end 776 777local os_info =vim . uv . os_uname () 778local os_string =os_info . sysname .. ' ' .. os_info . release 779local terminal =detect_terminal () 780local term_env =vim . env . TERM or 'unknown' 781 782vim . health . info (( 'Nvim version: `%s` %s' ): format ( nvim_version , commit )) 783vim . health . info ( 'Operating system: ' .. os_string ) 784vim . health . info ( 'Terminal: ' .. terminal ) 785vim . health . info ( '$TERM: ' .. term_env ) 786 787local body =vim . text . indent ( 7880 , 789string . format ( 790[[ 791## Problem 792 793Describe the problem (concisely). 794 795## Steps to reproduce 796 797``` 798nvim --clean 799``` 800 801## Expected behavior 802 803## System info 804 805- Nvim version (nvim -v): `%s` neovim/neovim@%s 806- Vim (not Nvim) behaves the same?: ? 807- Operating system/version: %s 808- Terminal name/version: %s 809- $TERM environment variable: `%s` 810- Installation: ? 811 812]] , 813nvim_version , 814commit , 815os_string , 816terminal , 817term_env 818) 819) 820 821nvim_on ( 'FileType' , nil , { pattern ='checkhealth' , once =true } , function ( ev ) 822local buf =ev . buf 823local win =vim . fn . bufwinid ( buf ) 824if win == - 1 then 825return 826end 827local encoded_body =vim . uri_encode ( body ) --- @type string 828local issue_url ='https://github.com/neovim/neovim/issues/new?type=Bug&body=' .. encoded_body 829 830--- Opens the prefilled issue from the checkhealth winbar. 831---@diagnostic disable-next-line: global-in-non-module 832_G . nvim_health_bugreport_open =function () 833vim . ui . open ( issue_url ) 834end 835vim . wo [ win ]. winbar = 836'%#WarningMsg#%@v:lua.nvim_health_bugreport_open@▶ Create Bug Report on GitHub%X%*' 837 838vim . api . nvim_create_autocmd ( 'BufDelete' , { 839buf =buf , 840once =true , 841command ='lua _G.nvim_health_bugreport_open = nil' , 842} ) 843end ) 844end 845 846---@async 847function M . check () 848check_sysinfo () 849check_config () 850check_runtime () 851check_performance () 852check_rplugin_manifest () 853check_terminal () 854check_tmux () 855check_external_tools () 856end 857 858return M