From bbe032ff1c40e9b695f8a5de9c779ee558dddf4f Mon Sep 17 00:00:00 2001 From: glepnir Date: Fri, 2 Aug 2024 19:31:28 +0800 Subject: [PATCH] fix: deprecate and add use_nerd --- lua/lspsaga/codeaction/lightbulb.lua | 4 ++-- lua/lspsaga/init.lua | 1 + lua/lspsaga/lspkind.lua | 13 ++++++++++++- lua/lspsaga/symbol/outline.lua | 9 +++++---- lua/lspsaga/symbol/winbar.lua | 9 ++++----- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lua/lspsaga/codeaction/lightbulb.lua b/lua/lspsaga/codeaction/lightbulb.lua index dc7507df5..3f7abb9a7 100644 --- a/lua/lspsaga/codeaction/lightbulb.lua +++ b/lua/lspsaga/codeaction/lightbulb.lua @@ -56,7 +56,7 @@ local function render(bufnr) local row = api.nvim_win_get_cursor(0)[1] - 1 local params = lsp.util.make_range_params() params.context = { - diagnostics = lsp.diagnostic.get_line_diagnostics(bufnr), + diagnostics = vim.diagnostic.get(bufnr, { lnum = row + 1 }), } lsp.buf_request(bufnr, 'textDocument/codeAction', params, function(_, result, _) @@ -72,7 +72,7 @@ local function render(bufnr) end) end -local timer = uv.new_timer() +local timer = assert(uv.new_timer()) local function update(buf) timer:stop() diff --git a/lua/lspsaga/init.lua b/lua/lspsaga/init.lua index 4c3eec930..0f8f6daf7 100644 --- a/lua/lspsaga/init.lua +++ b/lua/lspsaga/init.lua @@ -15,6 +15,7 @@ local default_config = { kind = nil, button = { '', '' }, imp_sign = '󰳛 ', + use_nerd = true, }, hover = { max_width = 0.9, diff --git a/lua/lspsaga/lspkind.lua b/lua/lspsaga/lspkind.lua index e5d4097b1..bec7b3284 100644 --- a/lua/lspsaga/lspkind.lua +++ b/lua/lspsaga/lspkind.lua @@ -71,8 +71,19 @@ local function get_kind() return kind end -local kind = get_kind() +local kind = ui.use_nerd and get_kind() or {} + +local function get_kind_icon(idx) + if not kind[idx] then + if ui.use_nerd then + vim.notify_once(('%d is missing in kind'):format(idx), vim.log.levels.WARN, {}) + end + return { '', '' } + end + return { kind[idx][1], kind[idx][2] } +end return { kind = kind, + get_kind_icon = get_kind_icon, } diff --git a/lua/lspsaga/symbol/outline.lua b/lua/lspsaga/symbol/outline.lua index a036b848e..8155cae4b 100644 --- a/lua/lspsaga/symbol/outline.lua +++ b/lua/lspsaga/symbol/outline.lua @@ -2,7 +2,7 @@ local ot = {} local api, fn = vim.api, vim.fn ---@diagnostic disable-next-line: deprecated local uv = vim.version().minor >= 10 and vim.uv or vim.loop -local kind = require('lspsaga.lspkind').kind +local get_kind_icon = require('lspsaga.lspkind').get_kind_icon local config = require('lspsaga').config local util = require('lspsaga.util') local symbol = require('lspsaga.symbol') @@ -124,8 +124,9 @@ function ot:parse(symbols, curline) end end + local hl, icon = unpack(get_kind_icon(node.kind)) buf_set_extmark(self.bufnr, ns, row - 1, #indent - 2, { - virt_text = { { kind[node.kind][2], 'Saga' .. kind[node.kind][1] } }, + virt_text = { { icon, 'Saga' .. hl } }, virt_text_pos = 'overlay', }) local inlevel = 4 + 2 * level @@ -214,7 +215,7 @@ function ot:collapse(node, curlnum) local tmp = node.next while tmp do - local icon = kind[tmp.value.kind][2] + local hl, icon = unpack(get_kind_icon(tmp.value.kind)) local level = tmp.value.inlevel buf_set_lines( self.bufnr, @@ -229,7 +230,7 @@ function ot:collapse(node, curlnum) tmp.value.expand = true end buf_set_extmark(self.bufnr, ns, row, level - 2, { - virt_text = { { icon, 'Saga' .. kind[tmp.value.kind][1] } }, + virt_text = { { icon, 'Saga' .. hl } }, virt_text_pos = 'overlay', }) local has_child = tmp.next and tmp.next.value.inlevel > level diff --git a/lua/lspsaga/symbol/winbar.lua b/lua/lspsaga/symbol/winbar.lua index 326819cce..2c7bf604f 100644 --- a/lua/lspsaga/symbol/winbar.lua +++ b/lua/lspsaga/symbol/winbar.lua @@ -3,7 +3,7 @@ local config = require('lspsaga').config.symbol_in_winbar local ui = require('lspsaga').config.ui local util = require('lspsaga.util') local symbol = require('lspsaga.symbol') -local kind = require('lspsaga.lspkind').kind +local get_kind_icon = require('lspsaga.lspkind').get_kind_icon local function bar_prefix() return { @@ -23,7 +23,7 @@ local function path_in_bar(buf) local items = {} local folder if ui.foldericon then - folder = kind[302][2] + folder = get_kind_icon(302)[2] end for item in util.path_itera(buf) do @@ -91,7 +91,7 @@ end -- pylsp local function has_container(node, elements) local bar = bar_prefix() - local type, icon = kind[5][1], kind[5][2] + local type, icon = unpack(get_kind_icon(5)) elements[#elements + 1] = string.format('%s%s#%s%s', bar.prefix, type, icon, node.containerName) end @@ -99,8 +99,7 @@ local function insert_elements(buf, node, elements) if config.hide_keyword and symbol:node_is_keyword(buf, node) then return end - local type = kind[node.kind][1] - local icon = kind[node.kind][2] + local type, icon = unpack(get_kind_icon(node.kind)) local bar = bar_prefix() if node.name:find('%%') then node.name = stl_escape(node.name)