diff options
author | Matthieu Coudron <teto@users.noreply.github.com> | 2020-12-20 21:59:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-20 21:59:25 +0100 |
commit | 1e5913483469528c7e8d1f927b28c0185eb94941 (patch) | |
tree | 9544669134d0e97aae394f43b787b2ccd3959a60 /runtime/lua/vim/lsp/util.lua | |
parent | b1711e6f922598f00c4d2c879094afdbba44c187 (diff) | |
download | rneovim-1e5913483469528c7e8d1f927b28c0185eb94941.tar.gz rneovim-1e5913483469528c7e8d1f927b28c0185eb94941.tar.bz2 rneovim-1e5913483469528c7e8d1f927b28c0185eb94941.zip |
lsp: add $/progress report (#13294)
Heavily inspired by https://github.com/nvim-lua/lsp-status.nvim.
listen to the LspProgressUpdate event to update your statusline.
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 3da4dd6219..0972ea83c4 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -120,6 +120,63 @@ local function get_line_byte_from_position(bufnr, position) return col end +--- Process and return progress reports from lsp server +function M.get_progress_messages() + + local new_messages = {} + local msg_remove = {} + local progress_remove = {} + + for _, client in ipairs(vim.lsp.get_active_clients()) do + local messages = client.messages + local data = messages + for token, ctx in pairs(data.progress) do + + local new_report = { + name = data.name, + title = ctx.title or "empty title", + message = ctx.message, + percentage = ctx.percentage, + progress = true, + } + table.insert(new_messages, new_report) + + if ctx.done then + table.insert(progress_remove, {client = client, token = token}) + end + end + + for i, msg in ipairs(data.messages) do + if msg.show_once then + msg.shown = msg.shown + 1 + if msg.shown > 1 then + table.insert(msg_remove, {client = client, idx = i}) + end + end + + table.insert(new_messages, {name = data.name, content = msg.content}) + end + + if next(data.status) ~= nil then + table.insert(new_messages, { + name = data.name, + content = data.status.content, + uri = data.status.uri, + status = true + }) + end + for _, item in ipairs(msg_remove) do + table.remove(client.messages, item.idx) + end + + for _, item in ipairs(progress_remove) do + client.messages.progress[item.token] = nil + end + end + + return new_messages +end + --- Applies a list of text edits to a buffer. --@param text_edits (table) list of `TextEdit` objects --@param buf_nr (number) Buffer id |