Fix: do not require lspkind if not configured
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user