diff --git a/README.md b/README.md index 72f67a8..4157b99 100644 --- a/README.md +++ b/README.md @@ -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 + left_align_column = 100, + -- whether to align to the extreme right or not right_align = false, diff --git a/doc/rust-tools.txt b/doc/rust-tools.txt index 6242870..28e909a 100644 --- a/doc/rust-tools.txt +++ b/doc/rust-tools.txt @@ -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 + left_align_column = 100, + -- whether to align to the extreme right or not right_align = false, diff --git a/lua/rust-tools/config.lua b/lua/rust-tools/config.lua index d4ce0ac..6af0e79 100644 --- a/lua/rust-tools/config.lua +++ b/lua/rust-tools/config.lua @@ -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 + left_align_column = 100, + -- whether to align to the extreme right or not right_align = false, diff --git a/lua/rust-tools/inlay_hints.lua b/lua/rust-tools/inlay_hints.lua index 0df31a1..31fd5de 100644 --- a/lua/rust-tools/inlay_hints.lua +++ b/lua/rust-tools/inlay_hints.lua @@ -197,12 +197,16 @@ 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]) - virt_text = - string.rep(" ", max_line_len - line_len + opts.max_len_align_padding) + if opts.left_align then + virt_text = string.rep(" ", opts.left_align_column - line_len) + else + virt_text = + string.rep(" ", max_line_len - line_len + opts.max_len_align_padding) + end end -- segregate parameter hints and other hints