-
-
Notifications
You must be signed in to change notification settings - Fork 231
feat(ui): pass formatter opts to icon fetcher as well #944
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -110,22 +110,23 @@ function Tabpage:new(tab) | |||||
| tab.modified = get_modified_state(tab.buffers) | ||||||
| tab.buftype = vim.bo[tab.buf].buftype | ||||||
| tab.extension = fn.fnamemodify(tab.path, ":e") | ||||||
| tab.icon, tab.icon_highlight = utils.get_icon({ | ||||||
| ---@type bufferline.TabFormatterOpts | ||||||
| local formatter_opts = { | ||||||
| name = tab.name, | ||||||
| path = tab.path, | ||||||
| bufnr = tab.buf, | ||||||
| tabnr = tab.id, | ||||||
| buffers = tab.buffers, | ||||||
| } | ||||||
| if tab.name_formatter and type(tab.name_formatter) == "function" then | ||||||
| tab.name = tab.name_formatter(formatter_opts) or tab.name | ||||||
| end | ||||||
| tab.icon, tab.icon_highlight = utils.get_icon(vim.tbl_extend("keep", { | ||||||
| filetype = vim.bo[tab.buf].filetype, | ||||||
| directory = fn.isdirectory(tab.path) > 0, | ||||||
| path = tab.path, | ||||||
| extension = tab.extension, | ||||||
| type = tab.buftype, | ||||||
| }) | ||||||
| if tab.name_formatter and type(tab.name_formatter) == "function" then | ||||||
| tab.name = tab.name_formatter({ | ||||||
| name = tab.name, | ||||||
| path = tab.path, | ||||||
| bufnr = tab.buf, | ||||||
| tabnr = tab.id, | ||||||
| buffers = tab.buffers, | ||||||
| }) or tab.name | ||||||
| end | ||||||
| }, formatter_opts)) | ||||||
| setmetatable(tab, self) | ||||||
| self.__index = self | ||||||
| return tab | ||||||
|
|
@@ -166,23 +167,29 @@ function Buffer:new(buf) | |||||
| buf.buftype = vim.bo[buf.id].buftype | ||||||
| buf.extension = fn.fnamemodify(buf.path, ":e") | ||||||
| local is_directory = fn.isdirectory(buf.path) > 0 | ||||||
| buf.icon, buf.icon_highlight = utils.get_icon({ | ||||||
| filetype = vim.bo[buf.id].filetype, | ||||||
| directory = is_directory, | ||||||
| path = buf.path, | ||||||
| extension = buf.extension, | ||||||
| type = buf.buftype, | ||||||
| }) | ||||||
| local name = "[No Name]" | ||||||
| if buf.path and #buf.path > 0 then | ||||||
| name = fn.fnamemodify(buf.path, ":t") | ||||||
| name = is_directory and name .. "/" or name | ||||||
| end | ||||||
|
|
||||||
| ---@type bufferline.BufFormatterOpts | ||||||
| local formatter_opts = { | ||||||
| name = name, | ||||||
| path = buf.path, | ||||||
| bufnr = buf.id, | ||||||
| } | ||||||
| if buf.name_formatter and type(buf.name_formatter) == "function" then | ||||||
| name = buf.name_formatter({ name = name, path = buf.path, bufnr = buf.id }) or name | ||||||
| name = buf.name_formatter(formatter_opts) or name | ||||||
| end | ||||||
|
|
||||||
| buf.icon, buf.icon_highlight = utils.get_icon(vim.tbl_extend("keep", { | ||||||
| filetype = vim.bo[buf.id].filetype, | ||||||
| directory = is_directory, | ||||||
| extension = buf.extension, | ||||||
| type = buf.buftype, | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we passing in the buffer type at all?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept this because we have done this already, you can see it there: bufferline.nvim/lua/bufferline/models.lua Line 118 in 0b2fd86
Actually, I found it might be a mistake, it may be intended to be used here bufferline.nvim/lua/bufferline/utils/init.lua Line 229 in 0b2fd86
But the type here will be the global variable included in Lua stdlib, the type function, so it's a false condition. type was not documented, but I kept it to avoid underlying breaking change.
|
||||||
| }, formatter_opts)) | ||||||
|
|
||||||
| buf.name = name | ||||||
|
|
||||||
| setmetatable(buf, self) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This removes path which is a breaking change and adds type which it doesn't explain here what that is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pathis included inname_formatterarguments, which I explained will be fully included. So it simplifies the expression, not changing the behavior.