nvim-config

Log | Files | Refs | Submodules | README

commit 81d956d6b0c9f04691b0068c6757cb97497569ef
parent 8fb9d4a5557390f5990950e1a8805f1bad38ed5c
Author: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
Date:   Thu, 25 Aug 2022 14:41:40 +0200

feat: make lsp_status a plugin

Diffstat:
Mlua/lsp_config.lua | 2+-
Dlua/lsp_status.lua | 119-------------------------------------------------------------------------------
Mlua/plugins.lua | 3+++
3 files changed, 4 insertions(+), 120 deletions(-)

diff --git a/lua/lsp_config.lua b/lua/lsp_config.lua @@ -8,7 +8,7 @@ vim.diagnostic.config { vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'rounded' }) vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'rounded' }) -require"lsp_status" +require"notifier".setup{} local function on_attach(client, bufnr) local function set_keymap(lhs, func, ...) diff --git a/lua/lsp_status.lua b/lua/lsp_status.lua @@ -1,119 +0,0 @@ -local ns = vim.api.nvim_create_namespace "lsp-status" - -local ignore_messages = { -} - -local status = { - buf_nr = nil, - win_nr = nil, - active = {} -} - -local status_width = math.floor((vim.o.columns - vim.o.textwidth) * 0.7) - -function status.create_win() - if not status.win_nr then - status.buf_nr = vim.api.nvim_create_buf(false, true); - status.win_nr = vim.api.nvim_open_win(status.buf_nr, false, { - focusable = false, - style = "minimal", - border = "none", - noautocmd = true, - relative = "editor", - anchor = "SE", - width = status_width, - height = 3, - row = vim.o.lines - vim.o.cmdheight - 1, - col = vim.o.columns, - zindex = 10, - }) - end -end - -function status.maybe_delete_win(force) - if force or vim.tbl_isempty(status.active) then - vim.api.nvim_win_close(status.win_nr, true) - status.win_nr = nil - end -end - -local function adjust_width(src, width) - if #src > width then - return string.sub(src, 1, width - 3) .. "..." - else - local acc = src - while #acc < width do - acc = " " .. acc - end - - return acc - end -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 - fmt_msg = adjust_width(msg.title, inner_width) - else - fmt_msg = adjust_width(tmp, inner_width) - end - else - fmt_msg = adjust_width(msg.title, inner_width) - end - - return fmt_msg .. " " .. msg.name -end - -function status.redraw() - status.create_win() - - if not vim.tbl_isempty(status.active) then - local lines = {} - local title_lines = {} - - -- For each lsp, print the message - for _, msg in pairs(status.active) do - table.insert(lines, format(msg, status_width)) - 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 - 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 - - vim.api.nvim_win_set_height(status.win_nr, #lines) - else - status.maybe_delete_win() - end -end - -function status.handle(msg) - if msg.done then - status.active[msg.name] = nil - else - status.active[msg.name] = msg - end - vim.schedule(status.redraw) -end - -local function progress_handle() - local new_messages = vim.lsp.util.get_progress_messages() - for _, msg in ipairs(new_messages) do - if not ignore_messages[msg.name] and msg.progress then - status.handle(msg) - end - end - return false -end - -vim.api.nvim_create_autocmd({ "User" }, { - pattern = "LspProgressUpdate", - callback = progress_handle -}) diff --git a/lua/plugins.lua b/lua/plugins.lua @@ -33,6 +33,8 @@ return packer.startup(function(use) localuse { 'vigoux/complementree.nvim', requires = { 'L3MON4D3/LuaSnip', 'nvim-treesitter/nvim-treesitter', { 'romgrk/fzy-lua-native', run = 'make' } } } + + -- UI and things use { 'nvim-telescope/telescope.nvim', requires = { @@ -44,6 +46,7 @@ return packer.startup(function(use) require 'tele_config' end } + localuse "vigoux/notifier.nvim" -- use { 'neovim/nvimdev.nvim', requires = {'neomake/neomake'}}