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

Commit bb6e785

Browse files
feat!(position): optimize max_len align & add fixed_col align
1 parent 62c7b8d commit bb6e785

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,26 @@ local default_config = {
6464
remove_colon_start = false,
6565
remove_colon_end = true,
6666
},
67+
-- type and other hints
6768
type_hints = {
68-
-- type and other hints
6969
show = true,
7070
prefix = "",
7171
separator = ", ",
7272
remove_colon_start = false,
7373
remove_colon_end = false,
7474
},
75+
position = {
76+
-- where to show the hints. values can be:
77+
-- nil: show hints after the end of the line
78+
-- "max_len": show hints after the longest line in the file
79+
-- "fixed_col": show hints after a fixed column, specified in padding
80+
align = nil,
81+
-- extra padding on the left if align is not nil
82+
padding = 1,
83+
},
7584
only_current_line = false,
76-
-- separator between types and parameter hints. Note that type hints are
77-
-- shown before parameter
85+
-- separator between types and parameter hints. Note that type hints are shown before parameter
7886
labels_separator = " ",
79-
-- whether to align to the length of the longest line in the file
80-
max_len_align = false,
81-
-- padding from the left if max_len_align is true
82-
max_len_align_padding = 1,
8387
-- highlight group
8488
highlight = "LspInlayHint",
8589
-- virt_text priority

lua/lsp-inlayhints/config.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,18 @@ local default_config = {
4040
remove_colon_start = false,
4141
remove_colon_end = false,
4242
},
43+
position = {
44+
-- where to show the hints. values can be:
45+
-- nil: show hints after the end of the line
46+
-- "max_len": show hints after the longest line in the file
47+
-- "fixed_col": show hints after a fixed column, specified in padding
48+
align = nil,
49+
-- extra padding on the left if align is not nil
50+
padding = 1,
51+
},
4352
only_current_line = false,
4453
-- separator between types and parameter hints. Note that type hints are shown before parameter
4554
labels_separator = " ",
46-
-- whether to align to the length of the longest line in the file
47-
max_len_align = false,
48-
-- padding from the left if max_len_align is true
49-
max_len_align_padding = 1,
5055
-- highlight group
5156
highlight = "LspInlayHint",
5257
-- virt_text priority

lua/lsp-inlayhints/handler_helper.lua

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ local function get_max_len(bufnr, parsed_data)
8787
end
8888

8989
local render_hints = function(bufnr, parsed, namespace, range)
90-
local max_len
91-
if opts.max_len_align then
92-
max_len = get_max_len(bufnr, parsed)
90+
local virt_text_win_col = 0
91+
if opts.position.align == "max_len" then
92+
virt_text_win_col = opts.position.padding + get_max_len(bufnr, parsed)
93+
elseif opts.position.align == "fixed_col" then
94+
virt_text_win_col = opts.position.padding
9395
end
9496

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

118-
local padding = ""
119-
if opts.max_len_align then
120-
padding = string.rep(
121-
" ",
122-
max_len - current_line(bufnr, line):len() + opts.max_len_align_padding
123-
)
124-
end
125-
126120
if virt_text ~= "" then
127121
vim.api.nvim_buf_set_extmark(bufnr, namespace, line, 0, {
128122
virt_text = {
129-
{ padding, "NONE" },
130123
{ virt_text, opts.highlight },
131124
},
125+
virt_text_win_col = virt_text_win_col,
132126
hl_mode = "combine",
133127
priority = opts.priority,
134128
})

0 commit comments

Comments
 (0)