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(ui): pass formatter opts to icon fetcher as well #944

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ofseed
Copy link
Contributor

@ofseed ofseed commented Jul 18, 2024

When a user customized the name by name_formatter, they would customize the icon too. I think it should be better to make them have the same arguments, but considering changing the arguments would be a breaking change, I recommend adding all the name_formatter properties to get_element_icon.

In my usage, I use the tab mode of bufferline, I don't want bufferline to show the name of buffers which has a special buftype when there is a normal buffer that exists in the tabpage.

@akinsho
Copy link
Owner

akinsho commented Jul 18, 2024

Hi @ofseed,

I'm not sure what you mean? they customize the icon too? as in they should be able to or they have to as well?

@ofseed
Copy link
Contributor Author

ofseed commented Jul 18, 2024

When using tab mode, there's buffers in name_formatter, but there's no equivalent for get_element_icon. We can only get information about the currently active buffer

@ofseed
Copy link
Contributor Author

ofseed commented Jul 18, 2024

My usage:

mode = "tabs",
name_formatter = function(args)
  if vim.bo[args.bufnr].buftype ~= "" then
    for _, bufnr in ipairs(args.buffers) do
      if vim.bo[bufnr].buftype == "" then
        return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":t")
      end
    end
  end
end,
get_element_icon = function(args)
  local loaded, devicons = pcall(require, "nvim-web-devicons")
  if not loaded then
    return ""
  end
  if vim.bo[args.bufnr].buftype ~= "" then
    for _, bufnr in ipairs(args.buffers) do
      if vim.bo[bufnr].buftype == "" then
        return devicons.get_icon(
          vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":t"),
          nil,
          { default = true }
        )
      end
    end
  end
end,

@ofseed
Copy link
Contributor Author

ofseed commented Jul 20, 2024

I'm not sure what you mean? they customize the icon too? as in they should be able to or they have to as well?

@akinsho I mean they should be able to, because there's no extra information like buffers opened in the tab in current API, we chan only get current active file's filetype for path, even cannot get it's bufnr

@@ -136,7 +136,7 @@ The available configuration are:
},
color_icons = true | false, -- whether or not to add the filetype icon highlights
get_element_icon = function(element)
-- element consists of {filetype: string, path: string, extension: string, directory: string}
-- element consists of {filetype: string, extension: string, directory: string, type:string?}, and all the properties same as the `name_formatter` function
Copy link
Owner

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path is included in name_formatter arguments, which I explained will be fully included. So it simplifies the expression, not changing the behavior.

filetype = vim.bo[buf.id].filetype,
directory = is_directory,
extension = buf.extension,
type = buf.buftype,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we passing in the buffer type at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:

type = tab.buftype,

Actually, I found it might be a mistake, it may be intended to be used here
if type == "terminal" then return webdev_icons.get_icon(type) end

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.

@ofseed
Copy link
Contributor Author

ofseed commented Jul 29, 2024

@akinsho I have already provided explanations for your questions. Could you please review them again?

@akinsho
Copy link
Owner

akinsho commented Jul 29, 2024

@ofseed this will have to wait till I have free time

@ofseed
Copy link
Contributor Author

ofseed commented Jul 29, 2024

I just wanted to avoid the message getting lost in the notifications. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants