nvim-config

Log | Files | Refs | Submodules | README

commit e77a504256e67020154b791f6741bf0a95e31135
parent 027486a55df60343e0f59a7f2ad69f70fd6bef6f
Author: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
Date:   Thu, 25 Aug 2022 13:47:57 +0200

feat: enhance lsp_status report

Diffstat:
Mlua/lsp_status.lua | 29++++++++++++-----------------
1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/lua/lsp_status.lua b/lua/lsp_status.lua @@ -1,7 +1,6 @@ local ns = vim.api.nvim_create_namespace "lsp-status" local ignore_messages = { - ltex = true, } local status = { @@ -10,11 +9,10 @@ local status = { active = {} } -local status_width = 50 +local status_width = math.floor((vim.o.columns - vim.o.textwidth) * 0.7) function status.create_win() if not status.win_nr then - vim.notify "Create" status.buf_nr = vim.api.nvim_create_buf(false, true); status.win_nr = vim.api.nvim_open_win(status.buf_nr, false, { focusable = false, @@ -52,16 +50,20 @@ local function adjust_width(src, width) end local function format(msg, width) + local inner_width = width - #msg.name - 1 + local fmt_msg if msg.message then local tmp = string.format("%s (%s)", msg.title, msg.message) if #tmp > width then - return adjust_width(msg.title, width) + fmt_msg = adjust_width(msg.title, inner_width) else - return adjust_width(tmp, width) + fmt_msg = adjust_width(tmp, inner_width) end else - return adjust_width(msg.title, width) + fmt_msg = adjust_width(msg.title, inner_width) end + + return fmt_msg .. " " .. msg.name end function status.redraw() @@ -72,24 +74,17 @@ function status.redraw() local title_lines = {} -- For each lsp, print the message - for name, msg in pairs(status.active) do + for _, msg in pairs(status.active) do table.insert(lines, format(msg, status_width)) - table.insert(lines, adjust_width(name, status_width)) - - title_lines[#lines] = true + title_lines[#lines] = #msg.name end vim.api.nvim_buf_set_lines(status.buf_nr, 0, -1, false, lines) -- Then highlight the lines for i = 1, vim.api.nvim_buf_line_count(status.buf_nr) do - local hl_name - if title_lines[i] then - hl_name = "Title" - else - hl_name = "NonText" - end - vim.api.nvim_buf_add_highlight(status.buf_nr, ns, hl_name, i - 1, 0, -1) + vim.api.nvim_buf_add_highlight(status.buf_nr, ns, "Comment", i - 1, 0, status_width - title_lines[i] - 1) + vim.api.nvim_buf_add_highlight(status.buf_nr, ns, "Title", i - 1, status_width - title_lines[i], -1) end else status.maybe_delete_win()