Skip to content

Commit 4d2aea3

Browse files
feat: improve health check for obsidian.nvim conflict
## Details Currently when using obsidian.nvim we provide blanket advice to disable the UI and allow the warning to be supressed with a configuration option. This is ok, but ideally we would actually do the check to make sure the UI is disabled and avoid the error entirely if it is. This change does exactly this by pulling the UI enable option from the obsidian.nvim client. This is very fragile and has no guarantee of working long term, but it should do well enough for now. It's likely as fragile as the advice provided before. This does remove the `acknowledge_conflicts` option which in some ways is not backwards compatible. However this option only plays a role in the health check warning and assuming the advice was followed there should continue to be no errors to users in the health check. As such I will say this is a non breaking change, but anyone using this option should remove it. Keeping it causes no problems, except in the health check for the config.
1 parent c862841 commit 4d2aea3

File tree

6 files changed

+19
-26
lines changed

6 files changed

+19
-26
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ require('render-markdown').setup({
210210
-- Vim modes that will show a rendered view of the markdown file
211211
-- All other modes will be uneffected by this plugin
212212
render_modes = { 'n', 'c' },
213-
-- Set to avoid seeing warnings for conflicts in health check
214-
acknowledge_conflicts = false,
215213
anti_conceal = {
216214
-- This enables hiding any added text on the line the cursor is on
217215
enabled = true,

doc/render-markdown.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ Full Default Configuration ~
243243
-- Vim modes that will show a rendered view of the markdown file
244244
-- All other modes will be uneffected by this plugin
245245
render_modes = { 'n', 'c' },
246-
-- Set to avoid seeing warnings for conflicts in health check
247-
acknowledge_conflicts = false,
248246
anti_conceal = {
249247
-- This enables hiding any added text on the line the cursor is on
250248
enabled = true,

lua/render-markdown/health.lua

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local M = {}
55

66
---@private
77
---@type string
8-
M.version = '6.3.3'
8+
M.version = '6.3.4'
99

1010
function M.check()
1111
vim.health.start('render-markdown.nvim [version]')
@@ -47,15 +47,14 @@ function M.check()
4747
end
4848

4949
vim.health.start('render-markdown.nvim [conflicts]')
50-
if state.acknowledge_conflicts then
51-
vim.health.ok('conflicts acknowledged')
52-
else
53-
M.check_plugin('headlines')
54-
M.check_plugin('obsidian', {
55-
'Ensure UI is disabled by setting ui = { enable = false } in obsidian.nvim config',
56-
'Acknowledge conflicts to avoid this warning by setting { acknowledge_conflicts = true }',
57-
})
58-
end
50+
M.check_plugin('headlines')
51+
M.check_plugin('obsidian', function(obsidian)
52+
if obsidian.get_client().opts.ui.enable == false then
53+
return nil
54+
else
55+
return 'Ensure UI is disabled by setting ui = { enable = false } in obsidian.nvim config'
56+
end
57+
end)
5958
end
6059

6160
---@private
@@ -111,15 +110,20 @@ end
111110

112111
---@private
113112
---@param name string
114-
---@param advice? string[]
115-
function M.check_plugin(name, advice)
116-
local has_plugin = pcall(require, name)
113+
---@param validate? fun(plugin: any): string?
114+
function M.check_plugin(name, validate)
115+
local has_plugin, plugin = pcall(require, name)
117116
if not has_plugin then
118117
vim.health.ok(name .. ': not installed')
119-
elseif advice == nil then
118+
elseif validate == nil then
120119
vim.health.error(name .. ': installed')
121120
else
122-
vim.health.warn(name .. ': installed', advice)
121+
local advice = validate(plugin)
122+
if advice == nil then
123+
vim.health.ok(name .. ': installed but should not conflict')
124+
else
125+
vim.health.error(name .. ': installed', advice)
126+
end
123127
end
124128
end
125129

lua/render-markdown/init.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ local M = {}
180180
---@field public log_level? render.md.config.LogLevel
181181
---@field public file_types? string[]
182182
---@field public injections? table<string, render.md.UserInjection>
183-
---@field public acknowledge_conflicts? boolean
184183
---@field public latex? render.md.UserLatex
185184
---@field public overrides? render.md.UserConfigOverrides
186185
---@field public custom_handlers? table<string, render.md.Handler>
@@ -275,8 +274,6 @@ M.default_config = {
275274
-- Vim modes that will show a rendered view of the markdown file
276275
-- All other modes will be uneffected by this plugin
277276
render_modes = { 'n', 'c' },
278-
-- Set to avoid seeing warnings for conflicts in health check
279-
acknowledge_conflicts = false,
280277
anti_conceal = {
281278
-- This enables hiding any added text on the line the cursor is on
282279
enabled = true,

lua/render-markdown/state.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ local configs = {}
1010
---@field enabled boolean
1111
---@field log_level render.md.config.LogLevel
1212
---@field file_types string[]
13-
---@field acknowledge_conflicts boolean
1413
---@field latex render.md.Latex
1514
---@field custom_handlers table<string, render.md.Handler>
1615
---@field markdown_query vim.treesitter.Query
@@ -37,7 +36,6 @@ function M.setup(default_config, user_config)
3736
M.enabled = config.enabled
3837
M.log_level = config.log_level
3938
M.file_types = config.file_types
40-
M.acknowledge_conflicts = config.acknowledge_conflicts
4139
M.latex = config.latex
4240
M.custom_handlers = config.custom_handlers
4341
vim.schedule(function()
@@ -425,7 +423,6 @@ function M.validate()
425423
log_level = one_of(config.log_level, { 'debug', 'error' }, {}, false),
426424
file_types = string_array(config.file_types, false),
427425
injections = { config.injections, 'table' },
428-
acknowledge_conflicts = { config.acknowledge_conflicts, 'boolean' },
429426
latex = { config.latex, 'table' },
430427
overrides = { config.overrides, 'table' },
431428
custom_handlers = { config.custom_handlers, 'table' },

lua/render-markdown/types.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
---@field public log_level render.md.config.LogLevel
153153
---@field public file_types string[]
154154
---@field public injections table<string, render.md.Injection>
155-
---@field public acknowledge_conflicts boolean
156155
---@field public latex render.md.Latex
157156
---@field public overrides render.md.ConfigOverrides
158157
---@field public custom_handlers table<string, render.md.Handler>

0 commit comments

Comments
 (0)