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 highlight = require('outline.highlight')
|
||||||
local providers = require('outline.providers.init')
|
local providers = require('outline.providers.init')
|
||||||
local utils = require('outline.utils.init')
|
local utils = require('outline.utils.init')
|
||||||
|
local symbols = require('outline.symbols')
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
---@type outline.Sidebar[]
|
---@type outline.Sidebar[]
|
||||||
@@ -354,6 +355,7 @@ function M.setup(opts)
|
|||||||
|
|
||||||
cfg.setup(opts)
|
cfg.setup(opts)
|
||||||
highlight.setup()
|
highlight.setup()
|
||||||
|
symbols.setup()
|
||||||
|
|
||||||
setup_global_autocmd()
|
setup_global_autocmd()
|
||||||
setup_commands()
|
setup_commands()
|
||||||
|
|||||||
@@ -45,23 +45,10 @@ for k, v in pairs(M.kinds) do
|
|||||||
M.str_to_kind[v] = k
|
M.str_to_kind[v] = k
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return table
|
-- use a stub if lspkind is missing or not configured
|
||||||
local function get_lspkind()
|
local lspkind = {
|
||||||
local has_lspkind, lspkind = pcall(require, 'lspkind')
|
symbolic = function(kind, opts) return '' end
|
||||||
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 kind string|integer
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
@@ -83,14 +70,26 @@ function M.icon_from_kind(kind, bufnr)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if cfg.o.symbols.icon_source == 'lspkind' then
|
local icon = lspkind.symbolic(kindstr, { with_text = false })
|
||||||
local icon = lspkind.symbolic(kindstr, { with_text = false })
|
if icon and icon ~= '' then
|
||||||
if icon and icon ~= '' then
|
return icon
|
||||||
return icon
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return cfg.o.symbols.icons[kindstr].icon
|
return cfg.o.symbols.icons[kindstr].icon
|
||||||
end
|
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
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user