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

Commit

Permalink
feat!(position): add start_of_line aligning
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshgupta137 committed Apr 23, 2023
1 parent 62c7b8d commit 6624989
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,19 @@ 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
-- "start_of_line": show hints relative to the start of the line (set padding to ~100)
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
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
-- "start_of_line": show hints relative to the start of the line (set padding to ~100)
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
15 changes: 8 additions & 7 deletions lua/lsp-inlayhints/handler_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ 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)
if opts.position.align then
if opts.position.align == "max_len" then
max_len = get_max_len(bufnr, parsed)
elseif opts.position.align == "start_of_line" then
max_len = 0
end
end

if opts.only_current_line then
Expand All @@ -116,11 +120,8 @@ local render_hints = function(bufnr, parsed, namespace, range)
end

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

if virt_text ~= "" then
Expand Down

0 comments on commit 6624989

Please sign in to comment.