From ae734a16aad78480687f1d84aab1be1589331e5b Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Sat, 4 Mar 2023 11:23:27 +0530 Subject: [PATCH] feat(inlay_hints): Add left_align for fixed column Signed-off-by: Utkarsh Gupta --- README.md | 7 +++++++ doc/rust-tools.txt | 9 ++++++++- lua/rust-tools/config.lua | 7 +++++++ lua/rust-tools/inlay_hints.lua | 5 ++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 72f67a8..cbe33d2 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 + 1/2 + left_align_column = 1, + -- 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..03b1099 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 + 1/2 + left_align_column = 1, + -- 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..5318b0a 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 + 1/2 + left_align_column = 1, + -- 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..ff9b4e0 100644 --- a/lua/rust-tools/inlay_hints.lua +++ b/lua/rust-tools/inlay_hints.lua @@ -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