-
Notifications
You must be signed in to change notification settings - Fork 4
healthchecks #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
healthchecks #55
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c316f32
LSP healthcheck
NobbZ 1ac3913
fix an issue with beancount setup
NobbZ 7e24b11
healtcheck for complete loading
NobbZ 1cf39f9
add documentation for healthchecks
NobbZ d568b5e
refactore criticality
NobbZ d76f4cf
Check for `git` and `rg` as well
NobbZ 8fba43b
refactor actual reporting in program check
NobbZ 34411c7
use `string.format` instead of handcrafting the message
NobbZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,3 +23,5 @@ WK.add({ | |
| }) | ||
|
|
||
| gitsigns.setup() | ||
|
|
||
| require("nobbz.health").register_program("git", true) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| local M = {} | ||
|
|
||
| local programs = {} | ||
| local done = false | ||
|
|
||
| local CRITICALITY = { OK = 1, ERROR = 2, WARN = 3, NOTICE = 4, } | ||
|
|
||
| ---Checks if a program is available in the system `PATH` | ||
| ---@param program string the program to check | ||
| ---@return boolean whether the program is in the `PATH` | ||
| local function in_path(program) | ||
| return vim.fn.executable(program) == 1 | ||
| end | ||
|
|
||
| ---Performs health checks for all registered programs | ||
| ---Displays results sorted by criticality and then alphabetically | ||
| local function check_programs() | ||
| local binaries = {} | ||
|
|
||
| vim.health.start("Programs in `PATH`:") | ||
| for program, required in pairs(programs) do | ||
| if in_path(program) then | ||
| table.insert(binaries, { program, vim.health.ok, "is installed", CRITICALITY.OK, }) | ||
| elseif required then | ||
| table.insert(binaries, { program, vim.health.error, "is not installed", CRITICALITY.ERROR, }) | ||
| else | ||
| table.insert(binaries, { program, vim.health.info, "is not installed", CRITICALITY.NOTICE, }) | ||
| end | ||
| end | ||
|
|
||
| table.sort(binaries, function(a, b) | ||
| -- Sort by program name, if same criticality | ||
| if a[4] == b[4] then return a[1] < b[1] end | ||
|
|
||
| -- Sort by criticality otherwise | ||
| return a[4] < b[4] | ||
| end) | ||
|
|
||
| for _, info in ipairs(binaries) do | ||
| local report_func = info[2] | ||
| local program = vim.fs.basename(info[1]) | ||
| local msg = info[3] | ||
|
|
||
| local message = string.format("`%s` %s", program, msg) | ||
|
|
||
| report_func(message) | ||
| end | ||
| end | ||
|
|
||
| ---Registers a program for the healthcheck, the program will be searched in the | ||
| ---`PATH`. | ||
| --- | ||
| ---If a program is registered for a second time, the `required` will be overwritten. | ||
| --- | ||
| ---@param program string the name of the program | ||
| ---@param required boolean whether the program is required (missing programs | ||
| --- will issue an error when required, a warning otherwise) | ||
| M.register_program = function(program, required) | ||
| programs[program] = required | ||
| end | ||
|
|
||
| ---Unregisters a program from the healthcheck | ||
| ---@param program string the program to unregister, it will not be checked by | ||
| --- the healthcheck anymore | ||
| M.unregister_program = function(program) | ||
| programs[program] = nil | ||
| end | ||
|
|
||
| ---Registers an LSP server for healthcheck | ||
| ---Automatically registers the LSP binary as optional by default, | ||
| ---but makes it required when a relevant filetype is opened | ||
| ---@param lsp string the name of the LSP server as defined in lspconfig | ||
| M.register_lsp = function(lsp) | ||
| local config = require("lspconfig")[lsp] | ||
| local program = config.cmd[1] | ||
| local pattern = config.filetypes[1] | ||
|
|
||
| M.register_program(program, false) | ||
|
|
||
| vim.api.nvim_create_autocmd("FileType", { | ||
| pattern = pattern, | ||
| callback = function() | ||
| M.register_program(program, true) | ||
| end, | ||
| }) | ||
| end | ||
|
|
||
| ---Marks the configuration as completely loaded | ||
| ---This affects the health check status message | ||
| M.done = function() | ||
| done = true | ||
| end | ||
|
|
||
| ---Runs all registered health checks, usually called by `:checkhealth`. | ||
| ---Displays overall configuration status and checks all registered programs | ||
| M.check = function() | ||
| vim.health.start("nobbz") | ||
| if done then | ||
| vim.health.ok("Config loaded completely") | ||
| else | ||
| vim.health.warn("Config *not* loaded completely") | ||
| end | ||
|
|
||
| check_programs() | ||
| end | ||
|
|
||
| return M | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,3 +61,5 @@ lazy.add_specs({ | |
| }) | ||
|
|
||
| lazy.finish() | ||
|
|
||
| require("nobbz.health").done() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,5 @@ require("lspconfig").nil_ls.setup({ | |
| }, | ||
| }, | ||
| }) | ||
|
|
||
| require("nobbz.health").register_lsp("nil_ls") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,5 @@ require("lspconfig").basedpyright.setup({ | |
| }, | ||
| }, | ||
| }) | ||
|
|
||
| require("nobbz.health").register_lsp("basedpyright") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.