From 4d2aea341a5d0bf2a01adc0ad4ecf5d4877e1bd0 Mon Sep 17 00:00:00 2001 From: MeanderingProgrammer Date: Mon, 9 Sep 2024 03:29:53 -0700 Subject: [PATCH] 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. --- README.md | 2 -- doc/render-markdown.txt | 2 -- lua/render-markdown/health.lua | 34 +++++++++++++++++++--------------- lua/render-markdown/init.lua | 3 --- lua/render-markdown/state.lua | 3 --- lua/render-markdown/types.lua | 1 - 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index b48c3e2..c4712f0 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/doc/render-markdown.txt b/doc/render-markdown.txt index 30d6fba..5f03a1b 100644 --- a/doc/render-markdown.txt +++ b/doc/render-markdown.txt @@ -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, diff --git a/lua/render-markdown/health.lua b/lua/render-markdown/health.lua index 115f28f..dfa2c48 100644 --- a/lua/render-markdown/health.lua +++ b/lua/render-markdown/health.lua @@ -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]') @@ -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 @@ -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 diff --git a/lua/render-markdown/init.lua b/lua/render-markdown/init.lua index 9ab4a0a..cb7c9b7 100644 --- a/lua/render-markdown/init.lua +++ b/lua/render-markdown/init.lua @@ -180,7 +180,6 @@ local M = {} ---@field public log_level? render.md.config.LogLevel ---@field public file_types? string[] ---@field public injections? table ----@field public acknowledge_conflicts? boolean ---@field public latex? render.md.UserLatex ---@field public overrides? render.md.UserConfigOverrides ---@field public custom_handlers? table @@ -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, diff --git a/lua/render-markdown/state.lua b/lua/render-markdown/state.lua index b82ca53..dc051da 100644 --- a/lua/render-markdown/state.lua +++ b/lua/render-markdown/state.lua @@ -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 ---@field markdown_query vim.treesitter.Query @@ -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() @@ -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' }, diff --git a/lua/render-markdown/types.lua b/lua/render-markdown/types.lua index 752a4d9..d641c84 100644 --- a/lua/render-markdown/types.lua +++ b/lua/render-markdown/types.lua @@ -152,7 +152,6 @@ ---@field public log_level render.md.config.LogLevel ---@field public file_types string[] ---@field public injections table ----@field public acknowledge_conflicts boolean ---@field public latex render.md.Latex ---@field public overrides render.md.ConfigOverrides ---@field public custom_handlers table