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

Provide interface to customize the comparing function between two nodes #2729

Open
alex-courtis opened this issue Mar 30, 2024 · 1 comment
Labels
API API or Event PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated

Comments

@alex-courtis
Copy link
Member

Discussed in https://github.com/nvim-tree/nvim-tree.lua/discussions/2727

Originally posted by rennsax March 27, 2024
We can use the option sort.sorter to customize how the files are sorted. If a function is provided, the argument is a table of all nodes. After sorted by the user's function, nvim-tree still needs to perform merge sort on the result.

I just found the interface is too complex to customize (not to mention the performance issue) when I was trying to tweak nvim-tree to put some special files (like CMakeLists.txt) at the end.

Firstly, the interface can be more elegant if it just requires a function that compare two nodes with necessary information and return a boolean value indicating which one should precede. And the implementation of this function will be much more clear.

Secondly, I suggest that nvim-tree/explorer/sorts.lua could export some function utility for file sorting to ease the complexity of writing the comparing logic from scratch.

Is this a better design?

@alex-courtis alex-courtis added PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated API API or Event labels Mar 30, 2024
@alex-courtis
Copy link
Member Author

That sounds reasonable. Please:

  1. Sketch out the API here, maybe with some examples
  2. Create a PR to build it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API API or Event PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated
Projects
None yet
Development

No branches or pull requests

1 participant