Skip to content

Commit 39a330f

Browse files
chore(refactor): update order that nodes are processed in
## Details Previously we used the `LanguageTree:for_each_tree` API to iterate over and generate decorations for each language root (for supported languages), with a special case to handle `markdown` after the others. This works for the most part but I have some ideas on the back-burner that could benefit from generalizing this approach a little more as well as providing additional information to the various decoration providers. So now in the `for_each_tree` callback we store a language to `TSNode[]` map for "valid" nodes. After that we sort the set of languages in the order of: other, latex, markdown. Note: currently latex being after other is not necessary, while markdown MUST be last. Then we process all the nodes within each language, before moving on to the others, so there is no longer any interleaving when it comes to the language nodes are associated with. The processing after this is essentially identical to before. The main difference is we now also provide whether this is the last node for this particular language. Note: last is in the context of the current render cycle, not necessarily the last node in the document. With this information we can do clever things like storing all the nodes in a list and only generating decorations once we reach the last node. For example this would allow us to process all `latex` nodes in one batch and we could take advantage of `async` tasks to really speed things up. Unrelated schema validation changes: - update `map` class definition - rename `Fields` -> `Record`
1 parent 6594102 commit 39a330f

File tree

18 files changed

+74
-64
lines changed

18 files changed

+74
-64
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
[b7dad79](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/b7dad793f4750b7e95884c0db374b917898a979b)
1717
- allow nested markdown to be skipped [#510](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/510)
1818
[c203eae](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/c203eae127bd3397985408038f4d74fc952532e2)
19-
- scope and autolink highlights conflict [#518](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/518)
20-
[7fd9116](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/7fd911692e5bc705c5487ae1c390d0b6d9738d87)
2119

2220
### Bug Fixes
2321

@@ -27,6 +25,8 @@
2725
- use display width for latex formula alignment [c4ff9ac](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/c4ff9acddcf0f79b3187393319adb5cac5865bd3)
2826
- anti-conceal ignore modes [8074a9c](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/8074a9cc9a6f737320b7a0d76b2c4c3485155688)
2927
- component level render modes [84d4928](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/84d4928cb4b508847294002835989880da4ce13b)
28+
- scope and autolink highlights conflict [#518](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/518)
29+
[7fd9116](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/7fd911692e5bc705c5487ae1c390d0b6d9738d87)
3030

3131
### Collaborator Shoutouts
3232

doc/custom-handlers.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Each handler must conform to the following interface:
1919
---@class (exact) render.md.handler.Context
2020
---@field buf integer
2121
---@field root TSNode
22+
---@field last boolean
2223

2324
---@class (exact) render.md.Mark
2425
---@field modes? render.md.Modes
@@ -48,6 +49,7 @@ The `parse` function takes a `ctx` parameter whose fields are:
4849

4950
- `buf`: The buffer containing the root node
5051
- `root`: The root treesitter node for the specified language
52+
- `last`: Whether this is the last treesitter root for the specified language
5153

5254
The `extends` parameter defines whether the builtin handler should still be run in
5355
conjunction with this one. Defaults to `false`.

lua/render-markdown/config/anti_conceal.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function M.schema()
7777
disabled_modes = modes,
7878
above = { type = 'number' },
7979
below = { type = 'number' },
80-
ignore = { map = { key = { enum = Element }, value = modes } },
80+
ignore = { map = { { enum = Element }, modes } },
8181
},
8282
}
8383
end

lua/render-markdown/config/base.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
---@class render.md.base.Cfg
88
local M = {}
99

10-
---@param additional_fields render.md.schema.Fields
10+
---@param child render.md.schema.Record
1111
---@return render.md.Schema
12-
function M.schema(additional_fields)
13-
---@type render.md.schema.Fields
14-
local fields = {
12+
function M.schema(child)
13+
---@type render.md.schema.Record
14+
local parent = {
1515
enabled = { type = 'boolean' },
1616
render_modes = {
1717
union = { { list = { type = 'string' } }, { type = 'boolean' } },
1818
},
1919
}
2020
---@type render.md.Schema
21-
return { record = vim.tbl_deep_extend('error', fields, additional_fields) }
21+
return { record = vim.tbl_deep_extend('error', parent, child) }
2222
end
2323

2424
return M

lua/render-markdown/config/callout.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function M.schema()
6464
},
6565
}
6666
---@type render.md.Schema
67-
return { map = { key = { type = 'string' }, value = callout } }
67+
return { map = { { type = 'string' }, callout } }
6868
end
6969

7070
return M

lua/render-markdown/config/checkbox.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function M.schema()
8585
right_pad = { type = 'number' },
8686
unchecked = component,
8787
checked = component,
88-
custom = { map = { key = { type = 'string' }, value = custom } },
88+
custom = { map = { { type = 'string' }, custom } },
8989
})
9090
end
9191

lua/render-markdown/config/handlers.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
---@class (exact) render.md.handler.Context
66
---@field buf integer
77
---@field root TSNode
8+
---@field last boolean
89

910
---@class render.md.handlers.Cfg
1011
local M = {}
@@ -25,7 +26,7 @@ function M.schema()
2526
},
2627
}
2728
---@type render.md.Schema
28-
return { map = { key = { type = 'string' }, value = handler } }
29+
return { map = { { type = 'string' }, handler } }
2930
end
3031

3132
return M

lua/render-markdown/config/heading.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ function M.schema()
182182
below = { type = 'string' },
183183
backgrounds = { list = { type = 'string' } },
184184
foregrounds = { list = { type = 'string' } },
185-
custom = { map = { key = { type = 'string' }, value = custom } },
185+
custom = { map = { { type = 'string' }, custom } },
186186
})
187187
end
188188

lua/render-markdown/config/html.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function M.schema()
5252
highlight = { type = 'string' },
5353
},
5454
},
55-
tag = { map = { key = { type = 'string' }, value = tag } },
55+
tag = { map = { { type = 'string' }, tag } },
5656
})
5757
end
5858

lua/render-markdown/config/injections.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function M.schema()
3434
},
3535
}
3636
---@type render.md.Schema
37-
return { map = { key = { type = 'string' }, value = injection } }
37+
return { map = { { type = 'string' }, injection } }
3838
end
3939

4040
return M

0 commit comments

Comments
 (0)