Skip to content

Commit 1faa656

Browse files
chore: use node type to determine marker instead of text for completions
1 parent cbabe00 commit 1faa656

File tree

3 files changed

+34
-39
lines changed

3 files changed

+34
-39
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44

55
### Features
66

7+
- individual components can all specify render modes [#269](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/269)
8+
[4d8e991](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/4d8e991d0c6e5298b79a6fb5ee44a7925e88180d)
79
- nvim-cmp completion source [3d2dc15](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/3d2dc15542e56671dd14dfbfff63434ec21d8fcd)
810
- blink.cmp completion source [3d2dc15](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/3d2dc15542e56671dd14dfbfff63434ec21d8fcd)
911
- coq_nvim completion source [#258](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/258)
1012
[#259](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/259) [75cdf9d](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/75cdf9d2b049f0e27440bd78cc52b39acd15cd6e)
1113
- dash width and margin percent [#272](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/272)
14+
- include icon provider warning in health check [032c640](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/032c6401b6f076adeb704bb8a3ac174fb813fbdb)
15+
- inline code padding [#274](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/274)
16+
[65b263d](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/65b263d6fc578131747f681d22f0b3a757e75443)
17+
- handle more list types for completions [c00cc1e](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/c00cc1e2cbd5a55ca0c6c2e27fcf4a02ff731434)
18+
- include markers in completion items based on context [#277](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/277)
1219

1320
### Bug Fixes
1421

@@ -22,6 +29,7 @@
2229
- @argizuno
2330
- @TheLeoP
2431
- @Kurama622
32+
- @AlexandreDoucet
2533

2634
## 7.7.0 (2024-12-07)
2735

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 = '7.7.10'
8+
M.version = '7.7.11'
99

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

lua/render-markdown/integ/source.lua

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,14 @@ local state = require('render-markdown.state')
33
local util = require('render-markdown.core.util')
44

55
local list_markers = {
6-
'list_marker_minus',
7-
'list_marker_star',
8-
'list_marker_plus',
6+
list_marker_minus = '-',
7+
list_marker_star = '*',
8+
list_marker_plus = '+',
99
}
1010

1111
---@class render.md.Source
1212
local M = {}
1313

14-
---@private
15-
---@param row integer
16-
---@param node TSNode
17-
---@return string
18-
function M.list_prefix(row, node)
19-
local marker = node:named_child(0)
20-
if not marker then
21-
return ''
22-
end
23-
24-
local marker_row = marker:range()
25-
if marker_row == row then
26-
return '' -- Don't run if on the same line, entry should already have a list marker.
27-
end
28-
29-
-- Retrieve the line from the buffer
30-
local marker_line = vim.api.nvim_buf_get_lines(0, marker_row, marker_row + 1, false)[1]
31-
32-
if not marker_line or #marker_line == 0 then
33-
return '' -- Return empty if the line is empty or doesn't exist
34-
end
35-
36-
-- Define valid list markers
37-
local valid_markers = { ['-'] = true, ['+'] = true, ['*'] = true }
38-
local first_char = marker_line:match('%S')
39-
40-
-- Return corresponding marker if valid, otherwise default to empty string
41-
return valid_markers[first_char] and first_char .. ' ' or ''
42-
end
43-
4414
---@return boolean
4515
function M.enabled()
4616
return manager.is_attached(util.current('buf'))
@@ -67,18 +37,35 @@ function M.items(buf, row, col)
6737
for _, component in pairs(config.callout) do
6838
table.insert(items, M.item(component.raw, component.rendered, nil))
6939
end
70-
elseif node:type() == 'list_item' or vim.tbl_contains(list_markers, node:type()) then
71-
local list_prefix = M.list_prefix(row, node)
40+
elseif node:type() == 'list_item' or list_markers[node:type()] ~= nil then
7241
local checkbox = config.checkbox
73-
table.insert(items, M.item(list_prefix .. '[ ] ', checkbox.unchecked.icon, 'unchecked'))
74-
table.insert(items, M.item(list_prefix .. '[x] ', checkbox.checked.icon, 'checked'))
42+
local prefix = M.list_prefix(row, node)
43+
table.insert(items, M.item(prefix .. '[ ] ', checkbox.unchecked.icon, 'unchecked'))
44+
table.insert(items, M.item(prefix .. '[x] ', checkbox.checked.icon, 'checked'))
7545
for name, component in pairs(checkbox.custom) do
76-
table.insert(items, M.item(list_prefix .. component.raw .. ' ', component.rendered, name))
46+
table.insert(items, M.item(prefix .. component.raw .. ' ', component.rendered, name))
7747
end
7848
end
7949
return items
8050
end
8151

52+
---@private
53+
---@param row integer
54+
---@param node TSNode
55+
---@return string
56+
function M.list_prefix(row, node)
57+
local marker_node = node:named_child(0)
58+
if marker_node == nil then
59+
return ''
60+
end
61+
local marker_row = marker_node:range()
62+
if marker_row == row then
63+
return ''
64+
end
65+
local marker = list_markers[marker_node:type()]
66+
return marker ~= nil and marker .. ' ' or ''
67+
end
68+
8269
---@private
8370
---@param raw string
8471
---@param rendered string

0 commit comments

Comments
 (0)