[mirror] Make your go dev experience better github.com/olexsmir/gopher.nvim
neovim golang
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(health): mark all bin deps as required, check if vim version is 0.10 or higher

+33 -37
+33 -37
lua/gopher/health.lua
··· 1 + local c = require("gopher.config").commands 1 2 local health = {} 2 - local cmd = require("gopher.config").commands 3 3 4 4 local deps = { 5 + vim_version = "nvim-0.10", 5 6 bin = { 6 7 { 7 - bin = cmd.go, 8 + bin = c.go, 8 9 msg = "required for `:GoGet`, `:GoMod`, `:GoGenerate`, `:GoWork`, `:GoInstallDeps`, `:GoInstallDepsSync`", 9 - optional = false, 10 10 }, 11 - { bin = cmd.gomodifytags, msg = "required for `:GoTagAdd`, `:GoTagRm`", optional = true }, 12 - { bin = cmd.impl, msg = "required for `:GoImpl`", optional = true }, 13 - { bin = cmd.iferr, msg = "required for `:GoIfErr`", optional = true }, 14 - { 15 - bin = cmd.gotests, 16 - msg = "required for `:GoTestAdd`, `:GoTestsAll`, `:GoTestsExp`", 17 - optional = true, 18 - }, 11 + { bin = c.gomodifytags, msg = "required for `:GoTagAdd`, `:GoTagRm`" }, 12 + { bin = c.impl, msg = "required for `:GoImpl`" }, 13 + { bin = c.iferr, msg = "required for `:GoIfErr`" }, 14 + { bin = c.gotests, msg = "required for `:GoTestAdd`, `:GoTestsAll`, `:GoTestsExp`" }, 19 15 }, 20 16 treesitter = { 21 17 { parser = "go", msg = "required for most of the parts of `gopher.nvim`" }, 22 18 }, 23 19 } 24 20 25 - ---@param bin string 26 - ---@return boolean 27 - local function is_binary_found(bin) 28 - return vim.fn.executable(bin) == 1 21 + ---@param bin {bin:string, msg:string, optional:boolean} 22 + local function check_binary(bin) 23 + if vim.fn.executable(bin.bin) == 1 then 24 + vim.health.ok(bin.bin .. " is found oh PATH: `" .. vim.fn.exepath(bin.bin) .. "`") 25 + else 26 + vim.health.error(bin.bin .. " not found on PATH, " .. bin.msg) 27 + end 29 28 end 30 29 31 - ---@param ft string 32 - ---@return boolean 33 - local function is_treesitter_parser_available(ft) 34 - local ok, parser = pcall(vim.treesitter.get_parser, 0, ft) 35 - return ok and parser ~= nil 30 + ---@param ts {parser:string, msg:string} 31 + local function check_treesitter(ts) 32 + local ok, parser = pcall(vim.treesitter.get_parser, 0, ts.parser) 33 + if ok and parser ~= nil then 34 + vim.health.ok("`" .. ts.parser .. "` parser is installed") 35 + else 36 + vim.health.error("`" .. ts.parser .. "` parser not found") 37 + end 36 38 end 37 39 38 40 function health.check() 39 - vim.health.start "required binaries" 40 - vim.health.info "all those binaries can be installed by `:GoInstallDeps`" 41 + vim.health.start "Neovim version" 42 + if vim.fn.has(deps.vim_version) == 1 then 43 + vim.health.ok "Neovim version is compatible" 44 + else 45 + vim.health.error(deps.vim_version .. " or newer is required") 46 + end 47 + 48 + vim.health.start "Required binaries (those can be installed with `:GoInstallDeps`)" 41 49 for _, bin in ipairs(deps.bin) do 42 - if is_binary_found(bin.bin) then 43 - vim.health.ok(bin.bin .. " installed") 44 - else 45 - if bin.optional then 46 - vim.health.warn(bin.bin .. " not found, " .. bin.msg) 47 - else 48 - vim.health.error(bin.bin .. " not found, " .. bin.msg) 49 - end 50 - end 50 + check_binary(bin) 51 51 end 52 52 53 - vim.health.start "required treesitter parsers" 53 + vim.health.start "Treesitter" 54 54 for _, parser in ipairs(deps.treesitter) do 55 - if is_treesitter_parser_available(parser.parser) then 56 - vim.health.ok(parser.parser .. " parser installed") 57 - else 58 - vim.health.error(parser.parser .. " parser not found, " .. parser.msg) 59 - end 55 + check_treesitter(parser) 60 56 end 61 57 end 62 58