Skip to content

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

Open
@alex-courtis

Description

@alex-courtis

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIAPI or EventPR pleasenvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions