From a3717e7a4e87632fee8a53b3299fd72b30bdfbeb Mon Sep 17 00:00:00 2001 From: eph Date: Fri, 27 Dec 2024 11:25:43 +0800 Subject: [PATCH 1/2] feat: icon_fetcher adds symbol parameter --- lua/outline/parser.lua | 2 +- lua/outline/symbols.lua | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lua/outline/parser.lua b/lua/outline/parser.lua index 3f3415d..9d40351 100644 --- a/lua/outline/parser.lua +++ b/lua/outline/parser.lua @@ -37,7 +37,7 @@ local function parse_result(result, depth, hierarchy, parent, bufnr) local node = { deprecated = value.deprecated, kind = value.kind, - icon = symbols.icon_from_kind(value.kind, bufnr), + icon = symbols.icon_from_kind(value.kind, bufnr, value), name = value.name or value.text, detail = value.detail, line = selectionRange.start.line, diff --git a/lua/outline/symbols.lua b/lua/outline/symbols.lua index a3a4b68..f73e792 100644 --- a/lua/outline/symbols.lua +++ b/lua/outline/symbols.lua @@ -52,8 +52,9 @@ local lspkind = { ---@param kind string|integer ---@param bufnr integer +---@param symbol? outline.Symbol ---@return string icon -function M.icon_from_kind(kind, bufnr) +function M.icon_from_kind(kind, bufnr, symbol) local kindstr = kind if type(kind) ~= 'string' then kindstr = M.kinds[kind] @@ -63,7 +64,7 @@ function M.icon_from_kind(kind, bufnr) end if type(cfg.o.symbols.icon_fetcher) == 'function' then - local icon = cfg.o.symbols.icon_fetcher(kindstr, bufnr) + local icon = cfg.o.symbols.icon_fetcher(kindstr, bufnr, symbol) -- Allow returning empty string if icon then return icon From b7906817d5249122ce1020233b2e03d760c1b94c Mon Sep 17 00:00:00 2001 From: eph Date: Fri, 27 Dec 2024 20:28:12 +0800 Subject: [PATCH 2/2] docs: update icon_fetcher usage and example --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 67433ea..ad0f462 100644 --- a/README.md +++ b/README.md @@ -918,6 +918,24 @@ symbols = { -- ... end, } +``` + + The `icon_fetcher` function may also accept a third parameter, the symbol + which type is outline.Symbol. Provider can add extra info to symbol. + For example, access specifier information can be added at the icon location. + +```lua +symbols = { + icon_fetcher = function(kind, bufnr, symbol) + local access_icons = { public = '○', protected = '◉', private = '●' } + local icon = require('outline.config').o.symbols.icons[kind].icon + -- ctags provider add `access` key + if symbol and symbol.access then + return icon .. ' ' .. access_icons[symbol.access] + end + return icon + end, +} ``` See [this section](#custom-icons) for other examples of this function.