Skip to content

Commit

Permalink
feat: improve health check for obsidian.nvim conflict
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
MeanderingProgrammer committed Sep 9, 2024
1 parent c862841 commit 4d2aea3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 26 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ require('render-markdown').setup({
-- Vim modes that will show a rendered view of the markdown file
-- All other modes will be uneffected by this plugin
render_modes = { 'n', 'c' },
-- Set to avoid seeing warnings for conflicts in health check
acknowledge_conflicts = false,
anti_conceal = {
-- This enables hiding any added text on the line the cursor is on
enabled = true,
Expand Down
2 changes: 0 additions & 2 deletions doc/render-markdown.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ Full Default Configuration ~
-- Vim modes that will show a rendered view of the markdown file
-- All other modes will be uneffected by this plugin
render_modes = { 'n', 'c' },
-- Set to avoid seeing warnings for conflicts in health check
acknowledge_conflicts = false,
anti_conceal = {
-- This enables hiding any added text on the line the cursor is on
enabled = true,
Expand Down
34 changes: 19 additions & 15 deletions lua/render-markdown/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local M = {}

---@private
---@type string
M.version = '6.3.3'
M.version = '6.3.4'

function M.check()
vim.health.start('render-markdown.nvim [version]')
Expand Down Expand Up @@ -47,15 +47,14 @@ function M.check()
end

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

---@private
Expand Down Expand Up @@ -111,15 +110,20 @@ end

---@private
---@param name string
---@param advice? string[]
function M.check_plugin(name, advice)
local has_plugin = pcall(require, name)
---@param validate? fun(plugin: any): string?
function M.check_plugin(name, validate)
local has_plugin, plugin = pcall(require, name)
if not has_plugin then
vim.health.ok(name .. ': not installed')
elseif advice == nil then
elseif validate == nil then
vim.health.error(name .. ': installed')
else
vim.health.warn(name .. ': installed', advice)
local advice = validate(plugin)
if advice == nil then
vim.health.ok(name .. ': installed but should not conflict')
else
vim.health.error(name .. ': installed', advice)
end
end
end

Expand Down
3 changes: 0 additions & 3 deletions lua/render-markdown/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ local M = {}
---@field public log_level? render.md.config.LogLevel
---@field public file_types? string[]
---@field public injections? table<string, render.md.UserInjection>
---@field public acknowledge_conflicts? boolean
---@field public latex? render.md.UserLatex
---@field public overrides? render.md.UserConfigOverrides
---@field public custom_handlers? table<string, render.md.Handler>
Expand Down Expand Up @@ -275,8 +274,6 @@ M.default_config = {
-- Vim modes that will show a rendered view of the markdown file
-- All other modes will be uneffected by this plugin
render_modes = { 'n', 'c' },
-- Set to avoid seeing warnings for conflicts in health check
acknowledge_conflicts = false,
anti_conceal = {
-- This enables hiding any added text on the line the cursor is on
enabled = true,
Expand Down
3 changes: 0 additions & 3 deletions lua/render-markdown/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ local configs = {}
---@field enabled boolean
---@field log_level render.md.config.LogLevel
---@field file_types string[]
---@field acknowledge_conflicts boolean
---@field latex render.md.Latex
---@field custom_handlers table<string, render.md.Handler>
---@field markdown_query vim.treesitter.Query
Expand All @@ -37,7 +36,6 @@ function M.setup(default_config, user_config)
M.enabled = config.enabled
M.log_level = config.log_level
M.file_types = config.file_types
M.acknowledge_conflicts = config.acknowledge_conflicts
M.latex = config.latex
M.custom_handlers = config.custom_handlers
vim.schedule(function()
Expand Down Expand Up @@ -425,7 +423,6 @@ function M.validate()
log_level = one_of(config.log_level, { 'debug', 'error' }, {}, false),
file_types = string_array(config.file_types, false),
injections = { config.injections, 'table' },
acknowledge_conflicts = { config.acknowledge_conflicts, 'boolean' },
latex = { config.latex, 'table' },
overrides = { config.overrides, 'table' },
custom_handlers = { config.custom_handlers, 'table' },
Expand Down
1 change: 0 additions & 1 deletion lua/render-markdown/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
---@field public log_level render.md.config.LogLevel
---@field public file_types string[]
---@field public injections table<string, render.md.Injection>
---@field public acknowledge_conflicts boolean
---@field public latex render.md.Latex
---@field public overrides render.md.ConfigOverrides
---@field public custom_handlers table<string, render.md.Handler>

0 comments on commit 4d2aea3

Please sign in to comment.