|
| 1 | +--- Health checks for nvim-spectre. |
| 2 | +--- Run with :checkhealth spectre |
| 3 | +local M = {} |
| 4 | + |
| 5 | +--- Check if an external command is available. |
| 6 | +---@param cmd string |
| 7 | +---@param optional boolean? |
| 8 | +---@param install_hint string? |
| 9 | +local function check_executable(cmd, optional, install_hint) |
| 10 | + if vim.fn.executable(cmd) == 1 then |
| 11 | + vim.health.ok(('%s: found'):format(cmd)) |
| 12 | + elseif optional then |
| 13 | + vim.health.warn(('%s: not found (optional)'):format(cmd), install_hint and { install_hint } or nil) |
| 14 | + else |
| 15 | + vim.health.error(('%s: not found'):format(cmd), install_hint and { install_hint } or nil) |
| 16 | + end |
| 17 | +end |
| 18 | + |
| 19 | +M.check = function() |
| 20 | + vim.health.start('spectre') |
| 21 | + |
| 22 | + -- Neovim version check |
| 23 | + if vim.fn.has('nvim-0.8') == 1 then |
| 24 | + vim.health.ok(('Neovim version: %s'):format(tostring(vim.version()))) |
| 25 | + else |
| 26 | + vim.health.error('Neovim >= 0.8 is required') |
| 27 | + end |
| 28 | + |
| 29 | + -- Required dependency: plenary.nvim |
| 30 | + local has_plenary = pcall(require, 'plenary') |
| 31 | + if has_plenary then |
| 32 | + vim.health.ok('plenary.nvim: found') |
| 33 | + else |
| 34 | + vim.health.error('plenary.nvim: not found', { 'Install nvim-lua/plenary.nvim' }) |
| 35 | + end |
| 36 | + |
| 37 | + -- Search engines |
| 38 | + vim.health.start('spectre: search engines') |
| 39 | + check_executable('rg', false, "Install BurntSushi/ripgrep: 'cargo install ripgrep' or use your package manager") |
| 40 | + check_executable('ag', true, 'Install ggreer/the_silver_searcher (optional alternative to rg)') |
| 41 | + |
| 42 | + -- Replace engines |
| 43 | + vim.health.start('spectre: replace engines') |
| 44 | + local uname = vim.loop.os_uname().sysname |
| 45 | + if uname == 'Darwin' then |
| 46 | + if vim.fn.executable('gsed') == 1 then |
| 47 | + vim.health.ok('gsed: found (recommended on macOS)') |
| 48 | + elseif vim.fn.executable('sed') == 1 then |
| 49 | + vim.health.warn('sed: found, but gsed is recommended on macOS', { 'Install with: brew install gnu-sed' }) |
| 50 | + else |
| 51 | + vim.health.error('sed/gsed: not found', { 'Install with: brew install gnu-sed' }) |
| 52 | + end |
| 53 | + else |
| 54 | + check_executable('sed', false) |
| 55 | + end |
| 56 | + check_executable('sd', true, "Install chmln/sd: 'cargo install sd' (optional alternative to sed)") |
| 57 | + |
| 58 | + -- Optional: native Rust module (spectre_oxi) |
| 59 | + vim.health.start('spectre: optional components') |
| 60 | + local has_oxi = pcall(require, 'spectre_oxi') |
| 61 | + if has_oxi then |
| 62 | + vim.health.ok('spectre_oxi (native Rust module): found') |
| 63 | + else |
| 64 | + vim.health.info('spectre_oxi (native Rust module): not found (optional, build with ./build.sh)') |
| 65 | + end |
| 66 | + |
| 67 | + -- Optional: icon providers |
| 68 | + local has_devicons = pcall(require, 'nvim-web-devicons') |
| 69 | + local has_mini_icons = pcall(require, 'mini.icons') |
| 70 | + if has_devicons then |
| 71 | + vim.health.ok('nvim-web-devicons: found') |
| 72 | + elseif has_mini_icons then |
| 73 | + vim.health.ok('mini.icons: found') |
| 74 | + else |
| 75 | + vim.health.info('No icon provider found (optional: install nvim-web-devicons or mini.icons)') |
| 76 | + end |
| 77 | +end |
| 78 | + |
| 79 | +return M |
0 commit comments