Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a802d2e

Browse files
feat(health): Add healthcheck
1 parent af90f8f commit a802d2e

File tree

4 files changed

+67
-7
lines changed

4 files changed

+67
-7
lines changed

docs/troubleshoot.org

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#+OPTIONS: H:9 ^:nil
22
* Troubleshooting
3+
💡 TIP: Run ~:checkhealth orgmode~ to check if Orgmode is correctly installed and configured.
4+
35
** Indentation is not working
46

57
Make sure you are not overriding indentexpr in Org buffers with [[https://github.com/nvim-treesitter/nvim-treesitter#indentation][nvim-treesitter indentation]]

ftplugin/org.lua

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ end
55
vim.b.did_ftplugin = true
66

77
local config = require('orgmode.config')
8-
local utils = require('orgmode.utils')
98

109
vim.b.org_bufnr = vim.api.nvim_get_current_buf()
1110

lua/orgmode/health.lua

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
local h = vim.health
2+
3+
local M = {}
4+
5+
function M.check()
6+
h.start('Orgmode')
7+
M.check_has_treesitter()
8+
M.check_setup()
9+
M.check_shellslash()
10+
end
11+
12+
function M.check_has_treesitter()
13+
local ok, result, err = pcall(vim.treesitter.language.add, 'org')
14+
if not ok or (not result and err ~= nil) then
15+
return h.error('Treesitter grammar is not installed. Run `:Org install_treesitter_grammar` to install it.')
16+
end
17+
return h.ok('Treesitter grammar installed')
18+
end
19+
20+
function M.check_setup()
21+
local config = require('orgmode.config')
22+
local orgmode = require('orgmode')
23+
24+
if not orgmode.is_setup_called() then
25+
h.warn('Setup not called')
26+
else
27+
h.ok('Setup called')
28+
end
29+
30+
if not config.org_agenda_files or #config.org_agenda_files == 0 then
31+
h.warn('No agenda files configured. Set `org_agenda_files` in your config.')
32+
else
33+
h.ok('`org_agenda_files` configured')
34+
end
35+
if not config.org_default_notes_file or config.org_default_notes_file == '' then
36+
h.warn('No default notes file configured. Set `org_default_notes_file` in your config.')
37+
else
38+
h.ok('`org_default_notes_file` configured')
39+
end
40+
end
41+
42+
function M.check_shellslash()
43+
if vim.fn.has('win32') ~= 1 then
44+
return
45+
end
46+
if not vim.opt.shellslash:get() then
47+
h.warn(
48+
'`shellslash` is not set. This might cause issues with file paths in links. Set `vim.opt.shellslash = true` in your configuration.'
49+
)
50+
else
51+
h.ok('`shellslash` is set')
52+
end
53+
end
54+
55+
return M

lua/orgmode/init.lua

+10-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local auto_instance_keys = {
1616

1717
---@class Org
1818
---@field initialized boolean
19+
---@field setup_called boolean
1920
---@field files OrgFiles
2021
---@field highlighter OrgHighlighter
2122
---@field agenda OrgAgenda
@@ -38,6 +39,7 @@ setmetatable(Org, {
3839
function Org:new()
3940
require('orgmode.org.global')(self)
4041
self.initialized = false
42+
self.setup_called = false
4143
self:setup_autocmds()
4244
require('orgmode.config'):setup_ts_predicates()
4345
return self
@@ -112,19 +114,14 @@ function Org:setup_autocmds()
112114
})
113115
end
114116

115-
function Org.setup_ts_grammar()
116-
require('orgmode.utils').echo_info(
117-
'calling require("orgmode").setup_ts_grammar() is no longer necessary. Dependency on nvim-treesitter was removed'
118-
)
119-
end
120-
121117
---@param opts? OrgConfigOpts
122118
---@return Org
123119
function Org.setup(opts)
124120
opts = opts or {}
125121
local config = require('orgmode.config'):extend(opts)
126122
config:install_grammar()
127123
instance = Org:new()
124+
instance.setup_called = true
128125
vim.defer_fn(function()
129126
if config.notifications.enabled and #vim.api.nvim_list_uis() > 0 then
130127
Org.files:load():next(vim.schedule_wrap(function()
@@ -224,6 +221,13 @@ function Org.destroy()
224221
end
225222
end
226223

224+
function Org.is_setup_called()
225+
if not instance then
226+
return false
227+
end
228+
return instance.setup_called
229+
end
230+
227231
function _G.orgmode.statusline()
228232
if not instance or not instance.initialized then
229233
return ''

0 commit comments

Comments
 (0)