Skip to content

Commit c283dec

Browse files
feat: check disable_pattern exists and notify if not
## Details Related issues: - #386 - #388 The current approach of assuming that most people with dev builds would update on new releases does not hold true enough. Take a similar approach as the pcall around `nvim_buf_set_extmark` and notify users that they should update with a more targeted error message rather than bubbling up a stack trace when things fail.
1 parent 6b66c32 commit c283dec

File tree

10 files changed

+46
-32
lines changed

10 files changed

+46
-32
lines changed

demo/minit.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ vim.opt.statuscolumn = '%s%=%{v:relnum?v:relnum:v:lnum} '
1212
vim.opt.showmode = false
1313

1414
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
15-
if not vim.uv.fs_stat(lazypath) then
16-
local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
17-
vim.fn.system({ 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath })
18-
end
15+
assert(vim.uv.fs_stat(lazypath))
1916
vim.opt.rtp:prepend(lazypath)
2017

2118
require('lazy').setup({

lua/render-markdown/core/buffer.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local Env = require('render-markdown.lib.env')
1+
local Compat = require('render-markdown.lib.compat')
22

33
---@class render.md.Buffer
44
---@field private buf integer
@@ -15,7 +15,7 @@ function Buffer.new(buf)
1515
local self = setmetatable({}, Buffer)
1616
self.buf = buf
1717
self.empty = true
18-
self.timer = Env.uv.new_timer()
18+
self.timer = Compat.uv.new_timer()
1919
self.running = false
2020
self.marks = nil
2121
return self

lua/render-markdown/core/conceal.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local Compat = require('render-markdown.lib.compat')
12
local Env = require('render-markdown.lib.env')
23
local Str = require('render-markdown.lib.str')
34

@@ -89,7 +90,7 @@ end
8990
---@return boolean
9091
function Conceal:hidden(node)
9192
-- conceal lines metadata require neovim >= 0.11.0 to function
92-
return Env.has_11 and self:line(node).hidden
93+
return Compat.has_11 and self:line(node).hidden
9394
end
9495

9596
---@param node render.md.Node

lua/render-markdown/core/extmark.lua

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local Compat = require('render-markdown.lib.compat')
2+
13
---@class render.md.Extmark
24
---@field private id? integer
35
---@field private mark render.md.Mark
@@ -40,13 +42,7 @@ function Extmark:show(ns, buf)
4042
if ok then
4143
self.id = id
4244
else
43-
local message = {
44-
string.format('render-markdown.nvim set extmark error (%s)', id),
45-
'you are running an old build of neovim that has now been released',
46-
'your build does not have all the features that are in the release',
47-
'update your build or switch to the release version',
48-
}
49-
vim.notify_once(table.concat(message, '\n'), vim.log.levels.ERROR)
45+
Compat.release_notification(string.format('nvim_buf_set_extmark error (%s)', id))
5046
end
5147
end
5248

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '8.2.2'
8+
M.version = '8.2.3'
99

1010
function M.check()
1111
M.start('version')

lua/render-markdown/integ/ts.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local Env = require('render-markdown.lib.env')
1+
local Compat = require('render-markdown.lib.compat')
22

33
---@class render.md.integ.TreeSitter
44
---@field private initialized boolean
@@ -38,9 +38,8 @@ function M.inject(language, injection)
3838
if injection == nil or not injection.enabled then
3939
return
4040
end
41-
4241
local query = ''
43-
if Env.has_11 then
42+
if Compat.has_11 then
4443
query = query .. ';; extends' .. '\n'
4544
else
4645
local files = vim.treesitter.query.get_files(language, 'injections')
@@ -60,16 +59,20 @@ end
6059
---@param language string
6160
---@param pattern? render.md.Pattern
6261
function M.disable(language, pattern)
63-
if not Env.has_11 then
62+
if pattern == nil or not pattern.disable then
6463
return
6564
end
66-
if pattern == nil or not pattern.disable then
65+
if not Compat.has_11 then
6766
return
6867
end
6968
local query = vim.treesitter.query.get(language, 'highlights')
7069
if query == nil then
7170
return
7271
end
72+
if query.query.disable_pattern == nil then
73+
Compat.release_notification('TSQuery missing disable_pattern API')
74+
return
75+
end
7376
local query_directives = query.info.patterns
7477
for _, directive in ipairs(pattern.directives) do
7578
local query_directive = query_directives[directive.id]

lua/render-markdown/lib/compat.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
---@class render.md.Compat
22
local M = {}
33

4+
M.uv = vim.uv or vim.loop
5+
M.has_10 = vim.fn.has('nvim-0.10') == 1
6+
M.has_11 = vim.fn.has('nvim-0.11') == 1
7+
48
---@param win integer
59
---@param extmarks render.md.Extmark[]
610
---@see vim.lsp.util.open_floating_preview
@@ -26,4 +30,18 @@ function M.lsp_window_height(win, extmarks)
2630
end
2731
end
2832

33+
---@param cause string
34+
function M.release_notification(cause)
35+
local message = {
36+
'MeanderingProgrammer/render-markdown.nvim',
37+
cause,
38+
'you are running an old build of neovim that has now been released',
39+
'your build does not have all the features that are in the release',
40+
'update your build or switch to the release version',
41+
}
42+
vim.schedule(function()
43+
vim.notify_once(table.concat(message, '\n'), vim.log.levels.ERROR)
44+
end)
45+
end
46+
2947
return M

lua/render-markdown/lib/env.lua

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
local Compat = require('render-markdown.lib.compat')
2+
13
---@class render.md.Env
24
local M = {}
35

4-
M.uv = vim.uv or vim.loop
5-
6-
M.has_10 = vim.fn.has('nvim-0.10') == 1
7-
M.has_11 = vim.fn.has('nvim-0.11') == 1
8-
96
---@param key 'ft'|'cmd'
107
---@return string[]
118
function M.lazy(key)
@@ -39,7 +36,7 @@ function M.file_size_mb(file)
3936
file = vim.api.nvim_buf_get_name(file)
4037
end
4138
local ok, stats = pcall(function()
42-
return M.uv.fs_stat(file)
39+
return Compat.uv.fs_stat(file)
4340
end)
4441
if not ok or stats == nil then
4542
return 0
@@ -51,9 +48,9 @@ end
5148
---@return fun()
5249
function M.runtime(callback)
5350
return function()
54-
local start_time = M.uv.hrtime()
51+
local start_time = Compat.uv.hrtime()
5552
callback()
56-
local end_time = M.uv.hrtime()
53+
local end_time = Compat.uv.hrtime()
5754
vim.print(string.format('Runtime (ms): %.1f', (end_time - start_time) / 1e+6))
5855
end
5956
end

lua/render-markdown/lib/marks.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local Compat = require('render-markdown.lib.compat')
12
local Context = require('render-markdown.core.context')
23
local Env = require('render-markdown.lib.env')
34
local Str = require('render-markdown.lib.str')
@@ -95,13 +96,13 @@ end
9596
---@param opts render.md.MarkOpts
9697
---@return boolean, string, string
9798
function Marks:validate(opts)
98-
if opts.virt_text_pos == 'inline' and not Env.has_10 then
99+
if opts.virt_text_pos == 'inline' and not Compat.has_10 then
99100
return false, "virt_text_pos = 'inline'", '0.10.0'
100101
end
101-
if opts.virt_text_repeat_linebreak ~= nil and not Env.has_10 then
102+
if opts.virt_text_repeat_linebreak ~= nil and not Compat.has_10 then
102103
return false, 'virt_text_repeat_linebreak', '0.10.0'
103104
end
104-
if opts.conceal_lines ~= nil and not Env.has_11 then
105+
if opts.conceal_lines ~= nil and not Compat.has_11 then
105106
return false, 'conceal_lines', '0.11.0'
106107
end
107108
return true, '', ''

lua/render-markdown/state.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local Compat = require('render-markdown.lib.compat')
12
local Config = require('render-markdown.config')
23
local Env = require('render-markdown.lib.env')
34
local log = require('render-markdown.core.log')
@@ -31,7 +32,7 @@ function M.setup(default_config, user_config)
3132
local config = vim.tbl_deep_extend('force', default_config, preset_config, user_config)
3233

3334
-- Override settings that require neovim >= 0.10.0 and have compatible alternatives
34-
if not Env.has_10 then
35+
if not Compat.has_10 then
3536
config.code.position = 'right'
3637
end
3738

0 commit comments

Comments
 (0)