Skip to content

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

Open
@alex-courtis

Description

@alex-courtis
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?

Activity

added
PR pleasenvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated
APIAPI or Event
on Mar 30, 2024
alex-courtis

alex-courtis commented on Mar 30, 2024

@alex-courtis
MemberAuthor

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

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

        Participants

        @alex-courtis

        Issue actions

          Provide interface to customize the comparing function between two nodes · Issue #2729 · nvim-tree/nvim-tree.lua