mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
fix(lsp): add spacing for inlay hints separately #24079
Problem: Spacing around inlay hints has the same highlight as the hint itself. The LSP spec for inlay hints specifically mentions the padding should not be coloured: /** Render padding before the hint. Note: Padding should use the editor's background color, not the background color of the hint itself. That means padding can be used to visually align/separate an inlay hint. */ paddingLeft?: boolean; /** Render padding after the hint. Note: Padding should use the editor's background color, not the background color of the hint itself. That means padding can be used to visually align/separate an inlay hint. */ paddingRight?: boolean; Solution: Add the space as separate parts of the virtual text, don't add the space to the text itself.
This commit is contained in:
@@ -252,18 +252,18 @@ api.nvim_set_decoration_provider(namespace, {
|
|||||||
text = text .. part.value
|
text = text .. part.value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local vt = {}
|
||||||
if hint.paddingLeft then
|
if hint.paddingLeft then
|
||||||
text = ' ' .. text
|
vt[#vt + 1] = { ' ' }
|
||||||
end
|
end
|
||||||
|
vt[#vt + 1] = { text, 'LspInlayHint' }
|
||||||
if hint.paddingRight then
|
if hint.paddingRight then
|
||||||
text = text .. ' '
|
vt[#vt + 1] = { ' ' }
|
||||||
end
|
end
|
||||||
api.nvim_buf_set_extmark(bufnr, namespace, lnum, hint.position.character, {
|
api.nvim_buf_set_extmark(bufnr, namespace, lnum, hint.position.character, {
|
||||||
virt_text_pos = 'inline',
|
virt_text_pos = 'inline',
|
||||||
ephemeral = false,
|
ephemeral = false,
|
||||||
virt_text = {
|
virt_text = vt,
|
||||||
{ text, 'LspInlayHint' },
|
|
||||||
},
|
|
||||||
hl_mode = 'combine',
|
hl_mode = 'combine',
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user