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

feat(lsp): markdown diagnostic messages proposal #27693

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MariaSolOs
Copy link
Member

@MariaSolOs MariaSolOs commented Mar 1, 2024

Implementation proposal for microsoft/language-server-protocol#1905.

runtime/lua/vim/diagnostic.lua Outdated Show resolved Hide resolved
runtime/lua/vim/lsp/buf.lua Outdated Show resolved Hide resolved
@@ -1796,6 +1800,26 @@ function M.open_float(opts, ...)
end
end

if message_kind == 'markdown' then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I get this right that this takes the kind from the first diagnostic and then formats all messages accordingly?

What if some are text and others markdown? That could cause to wrong highlighting

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duh you're right. These diagnostics might not all have the same kind. I should instead set message_kind to markdown if any one of them has Markdown content.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should instead set message_kind to markdown if any one of them has Markdown content.

I think the highlighting should be restricted to the messages where message_kind is markdown. Highlighting plaintext as markdown can lead to incorrect styling. E.g. unquoted variables like _foo with a trailing _ later in the text would highlight the whole section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree; that's the whole point of declaring the format: knowing when to parse/render and when not to.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then what if some diagnostics have message_kind set to markdown and others set to plaintext? They would all be displayed in the same floating window, so how do we highlight that?

I might be missing something here though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what's the best way to go about it, but we have to correlate diagnostics with the line numbers where the messages of them were rendered.

Or maybe the highlight application can be integrated directly into the loop here:

for j = 1, #message_lines do
local pre = j == 1 and prefix or string.rep(' ', #prefix)
local suf = j == #message_lines and suffix or ''
table.insert(lines, pre .. message_lines[j] .. suf)
table.insert(highlights, {
hlname = hiname,
prefix = {
length = j == 1 and #prefix or 0,
hlname = prefix_hl_group,
},
suffix = {
length = j == #message_lines and #suffix or 0,
hlname = suffix_hl_group,
},
})

Otherwise it would need to track the number of lines used per diagnostic. For example if there are 3 diagnostics, where the second uses markdown you'd have a mapping of:

  • 1-diagnostic: rendered in line 1-4,
  • 2-diagnostic: rendered in line 5-6,
  • 3-diagnostic: rendered in line 7

And then the api.nvim_buf_add_highlight would only affect line 5-6

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#28412 might be useful for this(?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, that does look handy 👀

runtime/lua/vim/lsp/buf.lua Outdated Show resolved Hide resolved
runtime/lua/vim/diagnostic.lua Outdated Show resolved Hide resolved
@MariaSolOs MariaSolOs force-pushed the poc branch 2 times, most recently from 1d64305 to 0fa805e Compare March 21, 2024 01:57
@MariaSolOs
Copy link
Member Author

MariaSolOs commented Mar 21, 2024

Note to self: Remove hardcoded protocol changes and use the generator script to pick up the upstream definitions, but we need microsoft/language-server-protocol#1910 to be merged first.

Done

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

Successfully merging this pull request may close these issues.

6 participants