nvim-tree / nvim-tree/nvim-tree.lua
Provide interface to customize the comparing function between two nodes
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 8.6k
- Forks
- 639
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 2
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lua/nvim-tree/explorer/sorters.lua, especially the current comparison logic around lines 100 and 133-143, and review the linked discussion for the unresolved design. Determine how a two-node comparator and reusable sorting utilities should fit the existing sort.sorter option; completion depends on agreeing on that interface and updating its behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100