From fdaa883d9d3603586e0005f85eea176a93d24483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20To=C5=82kacz?= Date: Mon, 12 Aug 2024 10:43:26 -0400 Subject: [PATCH 1/2] Show lspkind error message just once Instead of showing an error message for every symbol in every outline window, show just one error on opening nvim. --- lua/outline/symbols.lua | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lua/outline/symbols.lua b/lua/outline/symbols.lua index ac6c542..01e27c2 100644 --- a/lua/outline/symbols.lua +++ b/lua/outline/symbols.lua @@ -45,6 +45,24 @@ for k, v in pairs(M.kinds) do M.str_to_kind[v] = k end +---@return table +local function get_lspkind() + local has_lspkind, lspkind = pcall(require, 'lspkind') + if has_lspkind then + return lspkind + end + vim.notify( + '[outline]: icon_source set to lspkind but failed to require lspkind!', + vim.log.levels.ERROR + ) + -- return lspkind stub + return { + symbolic = function(kind, opts) return '' end + } +end + +local lspkind = get_lspkind() + ---@param kind string|integer ---@param bufnr integer ---@return string icon @@ -66,17 +84,9 @@ function M.icon_from_kind(kind, bufnr) end if cfg.o.symbols.icon_source == 'lspkind' then - local has_lspkind, lspkind = pcall(require, 'lspkind') - if not has_lspkind then - vim.notify( - '[outline]: icon_source set to lspkind but failed to require lspkind!', - vim.log.levels.ERROR - ) - else - local icon = lspkind.symbolic(kindstr, { with_text = false }) - if icon and icon ~= '' then - return icon - end + local icon = lspkind.symbolic(kindstr, { with_text = false }) + if icon and icon ~= '' then + return icon end end From 7df74ef5ed4f0f557d7179945d22622766f57da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20To=C5=82kacz?= Date: Mon, 12 Aug 2024 11:00:33 -0400 Subject: [PATCH 2/2] Fix: do not require lspkind if not configured --- lua/outline/init.lua | 2 ++ lua/outline/symbols.lua | 43 ++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lua/outline/init.lua b/lua/outline/init.lua index b57b10b..f02ecef 100644 --- a/lua/outline/init.lua +++ b/lua/outline/init.lua @@ -3,6 +3,7 @@ local cfg = require('outline.config') local highlight = require('outline.highlight') local providers = require('outline.providers.init') local utils = require('outline.utils.init') +local symbols = require('outline.symbols') local M = { ---@type outline.Sidebar[] @@ -354,6 +355,7 @@ function M.setup(opts) cfg.setup(opts) highlight.setup() + symbols.setup() setup_global_autocmd() setup_commands() diff --git a/lua/outline/symbols.lua b/lua/outline/symbols.lua index 01e27c2..a3a4b68 100644 --- a/lua/outline/symbols.lua +++ b/lua/outline/symbols.lua @@ -45,23 +45,10 @@ for k, v in pairs(M.kinds) do M.str_to_kind[v] = k end ----@return table -local function get_lspkind() - local has_lspkind, lspkind = pcall(require, 'lspkind') - if has_lspkind then - return lspkind - end - vim.notify( - '[outline]: icon_source set to lspkind but failed to require lspkind!', - vim.log.levels.ERROR - ) - -- return lspkind stub - return { - symbolic = function(kind, opts) return '' end - } -end - -local lspkind = get_lspkind() +-- use a stub if lspkind is missing or not configured +local lspkind = { + symbolic = function(kind, opts) return '' end +} ---@param kind string|integer ---@param bufnr integer @@ -83,14 +70,26 @@ function M.icon_from_kind(kind, bufnr) end end - if cfg.o.symbols.icon_source == 'lspkind' then - local icon = lspkind.symbolic(kindstr, { with_text = false }) - if icon and icon ~= '' then - return icon - end + local icon = lspkind.symbolic(kindstr, { with_text = false }) + if icon and icon ~= '' then + return icon end return cfg.o.symbols.icons[kindstr].icon end +function M.setup() + if cfg.o.symbols.icon_source == 'lspkind' then + local has_lspkind, _lspkind = pcall(require, 'lspkind') + if has_lspkind then + lspkind = _lspkind + else + vim.notify( + '[outline]: icon_source set to lspkind but failed to require lspkind!', + vim.log.levels.ERROR + ) + end + end +end + return M