You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: change_events list & link.wiki.body function
## Details
This change exposes 2 new configuration options to allow users to show
the contents of diagnostics in wiki links as shown in discussion [#228](#228)
without using a separate fork that has accrued merge conflicts.
This is a modified version of PR [#345](#345)
but it offloads the specific details to user configuration. Instead we
expose the information needed through a user configurable function and
the user can use this to change the body of a wiki link as they please.
### Events
The first part is the top level `change_events` configuration which gets
joined to the list of default events that trigger re-rendering due to
content changes. Since diagnostics changing now impacts the rendered
view we need to add the `DiagnosticChanged` event to the list.
```lua
require('render-markdown').setup({
change_events = { 'DiagnosticChanged' },
})
```
Since it's configurable this is only needed for users that want rendering
that depends on diagnostics, by default no additional events are added.
### Body
Now we use the `link.wiki.body` configuration to dynamically set the
main text of a wiki link based on any overlapping diagnostics. This is
appended to the icon. If a `nil` return value is provided we fallback to
the existing logic with no changes.
Below as an implementation specific to the `zk-nvim` plugin, but it is
easily modified to match any similar use case:
```lua
require('render-markdown').setup({
link = {
wiki = {
body = function(ctx)
local diagnostics = vim.diagnostic.get(ctx.buf, {
lnum = ctx.row,
severity = vim.diagnostic.severity.HINT,
})
for _, diagnostic in ipairs(diagnostics) do
if diagnostic.source == 'zk' then
return diagnostic.message
end
end
return nil
end,
},
},
})
```
Co-authored-by: Michael McDonagh <[email protected]>
0 commit comments