Skip to content

Commit

Permalink
Merge pull request #85 from oskarrrrrrr/lspkind-error-msg
Browse files Browse the repository at this point in the history
Show lspkind error message just once
  • Loading branch information
hedyhli authored Aug 13, 2024
2 parents 1459e8c + 7df74ef commit b47514b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lua/outline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -354,6 +355,7 @@ function M.setup(opts)

cfg.setup(opts)
highlight.setup()
symbols.setup()

setup_global_autocmd()
setup_commands()
Expand Down
27 changes: 18 additions & 9 deletions lua/outline/symbols.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ for k, v in pairs(M.kinds) do
M.str_to_kind[v] = k
end

-- 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
---@return string icon
Expand All @@ -65,22 +70,26 @@ function M.icon_from_kind(kind, bufnr)
end
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 not has_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
)
else
local icon = lspkind.symbolic(kindstr, { with_text = false })
if icon and icon ~= '' then
return icon
end
end
end

return cfg.o.symbols.icons[kindstr].icon
end

return M

0 comments on commit b47514b

Please sign in to comment.