Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
feat(inlay_hints): Add left_align for fixed column
Browse files Browse the repository at this point in the history
Signed-off-by: Utkarsh Gupta <utkarshgupta137@gmail.com>
  • Loading branch information
utkarshgupta137 committed Mar 4, 2023
1 parent 71d2cf6 commit ae734a1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ local opts = {
-- padding from the left if max_len_align is true
max_len_align_padding = 1,

-- whether to show hints at a fixed column or not
left_align = false,

-- column to show the hints at if left_align is true
-- useful to set this to rustfmt.max_width + 1/2
left_align_column = 1,

-- whether to align to the extreme right or not
right_align = false,

Expand Down
9 changes: 8 additions & 1 deletion doc/rust-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,14 @@ for keys that are not provided.

-- padding from the left if max_len_align is true
max_len_align_padding = 1,


-- whether to show hints at a fixed column or not
left_align = false,

-- column to show the hints at if left_align is true
-- useful to set this to rustfmt.max_width + 1/2
left_align_column = 1,

-- whether to align to the extreme right or not
right_align = false,

Expand Down
7 changes: 7 additions & 0 deletions lua/rust-tools/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ local defaults = {
-- padding from the left if max_len_align is true
max_len_align_padding = 1,

-- whether to show hints at a fixed column or not
left_align = false,

-- column to show the hints at if left_align is true
-- useful to set this to rustfmt.max_width + 1/2
left_align_column = 1,

-- whether to align to the extreme right or not
right_align = false,

Expand Down
5 changes: 4 additions & 1 deletion lua/rust-tools/inlay_hints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,13 @@ local function render_line(line, line_hints, bufnr, max_line_len)
return
end

if opts.max_len_align then
if opts.max_len_align or opts.left_align then
local line_len =
string.len(vim.api.nvim_buf_get_lines(bufnr, line, line + 1, true)[1])

if opts.left_align then
max_line_len = opts.left_align_column
end
virt_text =
string.rep(" ", max_line_len - line_len + opts.max_len_align_padding)
end
Expand Down

0 comments on commit ae734a1

Please sign in to comment.