Skip to content

Commit

Permalink
Make use of Nvim's new vim.health functions if available (#91)
Browse files Browse the repository at this point in the history
* Make use of Nvim's new vim.health functions if available

* Fix styling
  • Loading branch information
RVxLab authored Jun 22, 2024
1 parent 25891e2 commit fb8d142
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions lua/laravel/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,84 @@ local environment = require "laravel.environment"
local api = require "laravel.api"
local M = {}

local report_start = vim.health.start or vim.health.report_start
local report_ok = vim.health.ok or vim.health.report_ok
local report_info = vim.health.info or vim.health.report_info
local report_warn = vim.health.warn or vim.health.report_warn
local report_error = vim.health.error or vim.health.report_error

M.check = function()
vim.health.report_start "Laravel"
report_start "Laravel"

vim.health.report_start "External Dependencies"
report_start "External Dependencies"
if vim.fn.executable "rg" == 1 then
vim.health.report_ok "rg installed"
report_ok "rg installed"
else
vim.health.report_warn(
"ripgrep is missing, is required for finding view usage",
{ "Installed from your package manager" }
)
report_warn("ripgrep is missing, is required for finding view usage", { "Installed from your package manager" })
end

vim.health.report_start "Plugin Dependencies"
report_start "Plugin Dependencies"
local ok_null_ls, _ = pcall(require, "null-ls")
if ok_null_ls then
vim.health.report_ok "Null LS is installed"
report_ok "Null LS is installed"
else
vim.health.report_warn(
report_warn(
"Null LS is not installed, this is use to add completion, diagnostic and Code actions",
{ "Install it from `https://github.com/nvimtools/none-ls.nvim`" }
)
end
local ok_luannip, _ = pcall(require, "luasnip")
if ok_luannip then
vim.health.report_ok "luasnip is installed"
report_ok "luasnip is installed"
else
vim.health.report_warn(
report_warn(
"Luasnip is not installed, this is use to snippets related to larevel",
{ "Install it from `https://github.com/L3MON4D3/LuaSnip`" }
)
end

local ok_nui, _ = pcall(require, "nui.popup")
if ok_nui then
vim.health.report_ok "Nui is installed"
report_ok "Nui is installed"
else
vim.health.report_warn(
report_warn(
"Nui is not installed, this is use to create the UI for the command",
{ "Install it from `https://github.com/MunifTanjim/nui.nvim`" }
)
end

local ok_telescope, _ = pcall(require, "telescope")
if ok_telescope then
vim.health.report_ok "Telescope is installed"
report_ok "Telescope is installed"
else
vim.health.report_warn(
report_warn(
"Telescope is not installed, A lot of functions uses telescope for the pickers",
{ "Install it from `https://github.com/nvim-telescope/telescope.nvim`" }
)
end

vim.health.report_start "Environment"
report_start "Environment"

if not environment.environment then
vim.health.report_error(
report_error(
"Environment not configure for this directory, no more checks",
{ "Check project is laravel, current directory `:pwd` is the root of laravel project" }
)
return
end

vim.health.report_ok "Environment setup successful"
report_ok "Environment setup successful"

vim.health.report_info("Name: " .. environment.environment.name)
vim.health.report_info "Condition: "
vim.health.report_info(vim.inspect(environment.environment.condition))
vim.health.report_info "Commands: "
vim.health.report_info(vim.inspect(environment.environment.commands))
report_info("Name: " .. environment.environment.name)
report_info "Condition: "
report_info(vim.inspect(environment.environment.condition))
report_info "Commands: "
report_info(vim.inspect(environment.environment.commands))

vim.health.report_start "Composer Dependencies"
report_start "Composer Dependencies"

if not environment.get_executable "composer" then
vim.health.report_error "Composer executable not found can't check dependencies"
report_error "Composer executable not found can't check dependencies"
end

local composer_dependencies = {
Expand All @@ -88,12 +91,9 @@ M.check = function()

for _, dependency in pairs(composer_dependencies) do
if api.is_composer_package_install(dependency.name) then
vim.health.report_ok(string.format("Composer dependency `%s` is installed", dependency.name))
report_ok(string.format("Composer dependency `%s` is installed", dependency.name))
else
vim.health.report_warn(
string.format("Composer dependency `%s` is not installed", dependency.name),
{ dependency.messages }
)
report_warn(string.format("Composer dependency `%s` is not installed", dependency.name), { dependency.messages })
end
end
end
Expand Down

0 comments on commit fb8d142

Please sign in to comment.