Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
chore: added healthcheck entry and updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrho committed Jul 9, 2021
1 parent 1818e90 commit 483d944
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ require 'nerveux'.setup {
}
```

## Troubleshooting

You can run `:checkhealth nerveux` to run a basic diagnostic.

You can also start neovim like this:

```sh
$> DEBUG_NERVEUX=1 nvim a_zettel.md
```

This will write debug logs to the following file: `~/.cache/nvim/nerveux.log`.

## Similar plugins

- [oberblastmeister/neuron.nvim](https://github.com/oberblastmeister/neuron.nvim)
Expand Down
4 changes: 4 additions & 0 deletions autoload/health/nerveux.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function! health#nerveux#check() abort
lua require"nerveux.checkhealth".checks()
endfunction

67 changes: 67 additions & 0 deletions lua/nerveux/checkhealth.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
local M = {}
local Path = require 'plenary.path'
local Job = require 'plenary.job'

local nerveux_config = require "nerveux.config"

local report_error = vim.fn['health#report_error']
local report_ok = vim.fn['health#report_ok']

local function is_neuron_cmd_ok()
vim.fn['health#report_info']('Checking neuron binary...')

local is_executable = vim.fn.executable(nerveux_config.neuron_cmd) == 1
local path_exists = Path:new(nerveux_config.neuron_cmd):exists()

return is_executable or path_exists
end

local function is_correct_neuron_version()
local version_string = Job:new({
command = nerveux_config.neuron_cmd,
args = {'--version'}
}):sync()
local major, minor = unpack(vim.split(version_string[1], '.', true))

return {tonumber(major) == 1 and tonumber(minor) >= 9, version_string[1]}
end

local function is_valid_zettelkasten_dir()
return Path:new(string.format([[%s/neuron.dhall]], nerveux_config.neuron_dir))
:exists()
end

M.checks = function()
vim.fn['health#report_start']('sanity checks')
if not is_neuron_cmd_ok() then
report_error(string.format([[ `%s` does not exist or is not executable ]],
nerveux_config.neuron_cmd),
"Make sure `neuron_cmd` is correct")
return
else
report_ok 'neuron executable exists'
end

local version_is_correct, error_detail = unpack(is_correct_neuron_version())
if not version_is_correct then
report_error(
string.format([[ Version `%s` is not supported ]], error_detail),
"Update neuron to version 1.9.x at least")
return
else
report_ok 'neuron version is >= 1.9.0 (neuron v2)'
end

if not is_valid_zettelkasten_dir() then
report_error(
string.format([[%s/neuron.dhall]], nerveux_config.neuron_dir) ..
" is not a valid directory",
"Set the proper directory via `neuron_dir` or change the current working directory")
else
report_ok '`neuron_dir` is a valid neuron directory'
end

end

dump()
return M

0 comments on commit 483d944

Please sign in to comment.