Skip to content

Commit 0581a9a

Browse files
Minor changes for version 0.10.0, nothing user facing
# Details - Update version passed to panvimdoc to 0.10.0 - Query type -> vim.treesitter.Query - Call parse on parser before iterating through trees, not needed when running but is needed for unit tests, unsure what changed - Multiple highlights are now added as list in virtual text, minor change needed to fix this in test - Assert path returned is string in minimal init, minor change vim.fn.stdpath / vim.fs.find - Unrelated to update: change width for stylua back to 120, add latex as needed parser in minimal init
1 parent 9376997 commit 0581a9a

File tree

7 files changed

+90
-45
lines changed

7 files changed

+90
-45
lines changed

.stylua.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
column_width = 160
1+
column_width = 120
22
line_endings = 'Unix'
33
indent_type = 'Spaces'
44
indent_width = 4

doc/render-markdown.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.9.5 Last change: 2024 May 15
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 May 16
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

justfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ docgen:
2323
../../open-source/panvimdoc/panvimdoc.sh \
2424
--project-name render-markdown \
2525
--input-file README.md \
26-
--vim-version 0.9.5
26+
--vim-version 0.10.0

lua/render-markdown/state.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
---@class State
4848
---@field config Config
4949
---@field enabled boolean
50-
---@field markdown_query Query
51-
---@field inline_query Query
50+
---@field markdown_query vim.treesitter.Query
51+
---@field inline_query vim.treesitter.Query
5252
local state = {}
5353
return state

lua/render-markdown/ui.lua

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ M.refresh = function()
2929

3030
logger.start()
3131
vim.opt_local.conceallevel = state.config.conceal.rendered
32+
33+
-- Make sure injections are processed
34+
vim.treesitter.get_parser():parse(true)
35+
3236
vim.treesitter.get_parser():for_each_tree(function(tree, language_tree)
3337
local language = language_tree:lang()
3438
logger.debug({ language = language })

tests/init_spec.lua

+76-37
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async_tests.describe('init', function()
1717
local marks = vim.api.nvim_buf_get_extmarks(0, ui.namespace, 0, -1, { details = true })
1818
for _, mark in ipairs(marks) do
1919
local _, row, col, details = unpack(mark)
20-
table.insert(actual, {
20+
local mark_info = {
2121
row = { row, details.end_row },
2222
col = { col, details.end_col },
2323
hl_eol = details.hl_eol,
@@ -26,58 +26,68 @@ async_tests.describe('init', function()
2626
virt_text_pos = details.virt_text_pos,
2727
virt_lines = details.virt_lines,
2828
virt_lines_above = details.virt_lines_above,
29-
})
29+
}
30+
table.insert(actual, mark_info)
3031
end
3132

32-
local expected = {
33-
-- Headings 1 through 6 (minus 2)
33+
local expected = {}
34+
35+
-- Headings 1 through 6 (minus 2)
36+
vim.list_extend(expected, {
3437
{
3538
row = { 0, 1 },
3639
col = { 0, 0 },
3740
hl_eol = true,
3841
hl_group = 'DiffAdd',
39-
virt_text = { { '', 'markdownH1' }, { '󰲡 ', 'DiffAdd' } },
42+
virt_text = { { '󰲡 ', { 'markdownH1', 'DiffAdd' } } },
4043
virt_text_pos = 'overlay',
4144
},
4245
{
4346
row = { 2, 3 },
4447
col = { 0, 0 },
4548
hl_eol = true,
4649
hl_group = 'DiffDelete',
47-
virt_text = { { '', 'markdownH3' }, { ' 󰲥 ', 'DiffDelete' } },
50+
virt_text = { { ' 󰲥 ', { 'markdownH3', 'DiffDelete' } } },
4851
virt_text_pos = 'overlay',
4952
},
5053
{
5154
row = { 4, 5 },
5255
col = { 0, 0 },
5356
hl_eol = true,
5457
hl_group = 'DiffDelete',
55-
virt_text = { { '', 'markdownH4' }, { ' 󰲧 ', 'DiffDelete' } },
58+
virt_text = { { ' 󰲧 ', { 'markdownH4', 'DiffDelete' } } },
5659
virt_text_pos = 'overlay',
5760
},
5861
{
5962
row = { 6, 7 },
6063
col = { 0, 0 },
6164
hl_eol = true,
6265
hl_group = 'DiffDelete',
63-
virt_text = { { '', 'markdownH5' }, { ' 󰲩 ', 'DiffDelete' } },
66+
virt_text = { { ' 󰲩 ', { 'markdownH5', 'DiffDelete' } } },
6467
virt_text_pos = 'overlay',
6568
},
6669
{
6770
row = { 8, 9 },
6871
col = { 0, 0 },
6972
hl_eol = true,
7073
hl_group = 'DiffDelete',
71-
virt_text = { { '', 'markdownH6' }, { ' 󰲫 ', 'DiffDelete' } },
74+
virt_text = { { ' 󰲫 ', { 'markdownH6', 'DiffDelete' } } },
7275
virt_text_pos = 'overlay',
7376
},
74-
-- Code block
77+
})
78+
79+
-- Code block
80+
vim.list_extend(expected, {
7581
{
7682
row = { 10, 21 },
7783
col = { 0, 0 },
7884
hl_eol = true,
7985
hl_group = 'ColorColumn',
8086
},
87+
})
88+
89+
-- Unordered list
90+
vim.list_extend(expected, {
8191
-- List Item 1, bullet point
8292
{
8393
row = { 22, 22 },
@@ -141,42 +151,52 @@ async_tests.describe('init', function()
141151
virt_text = { { '', 'Normal' } },
142152
virt_text_pos = 'overlay',
143153
},
144-
-- Unchecked checkbox, bullet point, not created intentionally, remove if fixed
154+
})
155+
156+
-- Checkboxes
157+
vim.list_extend(expected, {
158+
-- Unchecked, bullet point, not created intentionally, remove if fixed
145159
{
146160
row = { 35, 35 },
147161
col = { 0, 2 },
148162
virt_text = { { '', 'Normal' } },
149163
virt_text_pos = 'overlay',
150164
},
151-
-- Unchecked checkbox, checkbox
165+
-- Unchecked, checkbox
152166
{
153167
row = { 35, 35 },
154168
col = { 2, 5 },
155169
virt_text = { { ' 󰄱 ', '@markup.list.unchecked' } },
156170
virt_text_pos = 'overlay',
157171
},
158-
-- Checked checkbox, bullet point, not created intentionally, remove if fixed
172+
-- Checked, bullet point, not created intentionally, remove if fixed
159173
{
160174
row = { 36, 36 },
161175
col = { 0, 2 },
162176
virt_text = { { '', 'Normal' } },
163177
virt_text_pos = 'overlay',
164178
},
165-
-- Checked checkbox, checkbox
179+
-- Checked, checkbox
166180
{
167181
row = { 36, 36 },
168182
col = { 2, 5 },
169183
virt_text = { { '', '@markup.heading' } },
170184
virt_text_pos = 'overlay',
171185
},
172-
-- Line break, TODO: fragile need to determine width
186+
})
187+
188+
-- Line break, TODO: fragile need to determine width
189+
vim.list_extend(expected, {
173190
{
174191
row = { 38 },
175192
col = { 0 },
176193
virt_text = { { string.rep('', 80), 'LineNr' } },
177194
virt_text_pos = 'overlay',
178195
},
179-
-- Quote lines
196+
})
197+
198+
-- Quote lines
199+
vim.list_extend(expected, {
180200
{
181201
row = { 40, 40 },
182202
col = { 0, 4 },
@@ -189,61 +209,77 @@ async_tests.describe('init', function()
189209
virt_text = { { '', '@markup.quote' } },
190210
virt_text_pos = 'overlay',
191211
},
192-
-- Table heading
193-
{
194-
row = { 43, 43 },
195-
col = { 0, 31 },
196-
virt_text = { { '│ Heading 1 │ Heading 2 │', '@markup.heading' } },
197-
virt_text_pos = 'overlay',
198-
},
199-
-- Table above
212+
})
213+
214+
local markdown_table = {
215+
'┌──────────────┬──────────────┐',
216+
'│ Heading 1 │ Heading 2 │',
217+
'├──────────────┼──────────────┤',
218+
'│ Row 1 Item 1 │ Row 1 Item 2 │',
219+
'│ Row 2 Item 1 │ Row 2 Item 2 │',
220+
'│ Row 3 Item 1 │ Row 3 Item 2 │',
221+
'└──────────────┴──────────────┘',
222+
}
223+
vim.list_extend(expected, {
224+
-- Above
200225
{
201226
row = { 43 },
202227
col = { 0 },
203-
virt_lines = { { { '┌──────────────┬──────────────┐', '@markup.heading' } } },
228+
virt_lines = { { { markdown_table[1], '@markup.heading' } } },
204229
virt_lines_above = true,
205230
},
206-
-- Table below heading
231+
-- Heading
232+
{
233+
row = { 43, 43 },
234+
col = { 0, 31 },
235+
virt_text = { { markdown_table[2], '@markup.heading' } },
236+
virt_text_pos = 'overlay',
237+
},
238+
-- Below heading
207239
{
208240
row = { 44, 44 },
209241
col = { 0, 31 },
210-
virt_text = { { '├──────────────┼──────────────┤', '@markup.heading' } },
242+
virt_text = { { markdown_table[3], '@markup.heading' } },
211243
virt_text_pos = 'overlay',
212244
},
213-
-- Table rows
245+
-- Rows
214246
{
215247
row = { 45, 45 },
216248
col = { 0, 31 },
217-
virt_text = { { '│ Row 1 Item 1 │ Row 1 Item 2 │', 'Normal' } },
249+
virt_text = { { markdown_table[4], 'Normal' } },
218250
virt_text_pos = 'overlay',
219251
},
220252
{
221253
row = { 46, 46 },
222254
col = { 0, 31 },
223-
virt_text = { { '│ Row 2 Item 1 │ Row 2 Item 2 │', 'Normal' } },
255+
virt_text = { { markdown_table[5], 'Normal' } },
224256
virt_text_pos = 'overlay',
225257
},
226258
{
227259
row = { 47, 47 },
228260
col = { 0, 31 },
229-
virt_text = { { '│ Row 3 Item 1 │ Row 3 Item 2 │', 'Normal' } },
261+
virt_text = { { markdown_table[6], 'Normal' } },
230262
virt_text_pos = 'overlay',
231263
},
232-
-- Table below
264+
-- Below
233265
{
234266
row = { 48 },
235267
col = { 0 },
236-
virt_lines = { { { '└──────────────┴──────────────┘', 'Normal' } } },
268+
virt_lines = { { { markdown_table[7], 'Normal' } } },
237269
virt_lines_above = true,
238270
},
239-
-- LaTeX inline, TODO: mock interaction with latex2text
271+
})
272+
273+
-- LaTeX, TODO: mock interaction with latex2text
274+
vim.list_extend(expected, {
275+
-- Inline
240276
{
241277
row = { 49, 49 },
242278
col = { 0, 21 },
243279
virt_lines = { { { '√(3x-1)+(1+x)^2', '@markup.math' } } },
244280
virt_lines_above = true,
245281
},
246-
-- LaTeX block, TODO: mock interaction with latex2text
282+
-- Block
247283
{
248284
row = { 51, 54 },
249285
col = { 0, 2 },
@@ -253,8 +289,11 @@ async_tests.describe('init', function()
253289
},
254290
virt_lines_above = true,
255291
},
256-
}
292+
})
257293

258-
eq(expected, actual)
294+
eq(#expected, #actual)
295+
for i, expected_mark_info in ipairs(expected) do
296+
eq(expected_mark_info, actual[i], string.format('Marks at index %d mismatch', i))
297+
end
259298
end)
260299
end)

tests/minimal.lua

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---@param path_name string
22
---@param plugin_name string
33
local function source_plugin(path_name, plugin_name)
4-
local path = vim.fs.find(path_name, { path = vim.fn.stdpath('data') })
5-
vim.opt.rtp:prepend(unpack(path))
4+
local data_path = vim.fn.stdpath('data')
5+
assert(type(data_path) == 'string')
6+
local plugin_path = vim.fs.find(path_name, { path = data_path })
7+
vim.opt.rtp:prepend(unpack(plugin_path))
68
vim.cmd.runtime('plugin/' .. plugin_name)
79
end
810

@@ -11,7 +13,7 @@ source_plugin('plenary.nvim', 'plenary.vim')
1113
source_plugin('nvim-treesitter', 'nvim-treesitter.lua')
1214

1315
-- https://github.com/ThePrimeagen/refactoring.nvim/blob/master/scripts/minimal.vim
14-
local required_parsers = { 'markdown', 'markdown_inline' }
16+
local required_parsers = { 'markdown', 'markdown_inline', 'latex' }
1517
local installed_parsers = require('nvim-treesitter.info').installed_parsers()
1618
local to_install = vim.tbl_filter(function(parser)
1719
return not vim.tbl_contains(installed_parsers, parser)

0 commit comments

Comments
 (0)