-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
base: master
Are you sure you want to change the base?
Conversation
73b6d8e
to
7c431b8
Compare
@@ -1796,6 +1800,26 @@ function M.open_float(opts, ...) | |||
end | |||
end | |||
|
|||
if message_kind == 'markdown' then |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
neovim/runtime/lua/vim/diagnostic.lua
Lines 1798 to 1812 in 4459e0c
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
There was a problem hiding this comment.
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(?)
There was a problem hiding this comment.
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 👀
1d64305
to
0fa805e
Compare
Done |
Implementation proposal for microsoft/language-server-protocol#1905.