Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: icon_fetcher adds symbol parameter #109

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lua/outline/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions lua/outline/symbols.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down