Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull WikiLink text from diagnostics #345

Closed
wants to merge 3 commits into from

Conversation

mcDevnagh
Copy link
Contributor

No description provided.

MeanderingProgrammer added a commit that referenced this pull request Feb 25, 2025
## 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]>
@MeanderingProgrammer
Copy link
Owner

MeanderingProgrammer commented Feb 25, 2025

Thanks for the PR and taking the initiative to add this!

I've merged the necessary functionality here: 0df6719

More details here: #228 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants