Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,26 @@ local default_config = {
remove_colon_start = false,
remove_colon_end = true,
},
-- type and other hints
type_hints = {
-- type and other hints
show = true,
prefix = "",
separator = ", ",
remove_colon_start = false,
remove_colon_end = false,
},
position = {
-- where to show the hints. values can be:
-- nil: show hints after the end of the line
-- "max_len": show hints after the longest line in the file
-- "fixed_col": show hints after a fixed column, specified in padding
align = nil,
-- extra padding on the left if align is not nil
padding = 1,
},
only_current_line = false,
-- separator between types and parameter hints. Note that type hints are
-- shown before parameter
-- separator between types and parameter hints. Note that type hints are shown before parameter
labels_separator = " ",
-- whether to align to the length of the longest line in the file
max_len_align = false,
-- padding from the left if max_len_align is true
max_len_align_padding = 1,
-- highlight group
highlight = "LspInlayHint",
-- virt_text priority
Expand Down
13 changes: 9 additions & 4 deletions lua/lsp-inlayhints/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ local default_config = {
remove_colon_start = false,
remove_colon_end = false,
},
position = {
-- where to show the hints. values can be:
-- nil: show hints after the end of the line
-- "max_len": show hints after the longest line in the file
-- "fixed_col": show hints after a fixed column, specified in padding
align = nil,
-- extra padding on the left if align is not nil
padding = 1,
},
only_current_line = false,
-- separator between types and parameter hints. Note that type hints are shown before parameter
labels_separator = " ",
-- whether to align to the length of the longest line in the file
max_len_align = false,
-- padding from the left if max_len_align is true
max_len_align_padding = 1,
-- highlight group
highlight = "LspInlayHint",
-- virt_text priority
Expand Down
18 changes: 6 additions & 12 deletions lua/lsp-inlayhints/handler_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ local function get_max_len(bufnr, parsed_data)
end

local render_hints = function(bufnr, parsed, namespace, range)
local max_len
if opts.max_len_align then
max_len = get_max_len(bufnr, parsed)
local virt_text_win_col = 0
if opts.position.align == "max_len" then
virt_text_win_col = opts.position.padding + get_max_len(bufnr, parsed)
elseif opts.position.align == "fixed_col" then
virt_text_win_col = opts.position.padding
end

if opts.only_current_line then
Expand All @@ -115,20 +117,12 @@ local render_hints = function(bufnr, parsed, namespace, range)
virt_text = param_vt
end

local padding = ""
if opts.max_len_align then
padding = string.rep(
" ",
max_len - current_line(bufnr, line):len() + opts.max_len_align_padding
)
end

if virt_text ~= "" then
vim.api.nvim_buf_set_extmark(bufnr, namespace, line, 0, {
virt_text = {
{ padding, "NONE" },
{ virt_text, opts.highlight },
},
virt_text_win_col = virt_text_win_col,
hl_mode = "combine",
priority = opts.priority,
})
Expand Down