diff --git a/README.md b/README.md index 4d79ea2..5b0d9a0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/lsp-inlayhints/config.lua b/lua/lsp-inlayhints/config.lua index e8ff4ed..a1f2768 100644 --- a/lua/lsp-inlayhints/config.lua +++ b/lua/lsp-inlayhints/config.lua @@ -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 diff --git a/lua/lsp-inlayhints/handler_helper.lua b/lua/lsp-inlayhints/handler_helper.lua index 83120f0..f1f1f33 100644 --- a/lua/lsp-inlayhints/handler_helper.lua +++ b/lua/lsp-inlayhints/handler_helper.lua @@ -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 @@ -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