Skip to content

Refactor: attributes modules & line builder #1889

Open
@chomosuke

Description

@chomosuke

As discussed in #1871 (comment)

Background

nvim-tree is a very customizable plugin and it provide options to display certain attributes of files and directories.

Currently, 4 such attributes are implemented: git, diagnostics, modified and opened. However, they're all implemented separately, and as a result, have duplicated logic between them and lack feature parity (e.g. can only display diagnostics in signcolumn, can't see if file in a directory are opened without opening the directory).

Further more, it is more difficult that necessary to implement new attributes as there's no existing framework to allow such implementation without an understanding of how the renderer works. Many of the attributes' implementation are also tightly coupled with the rest of nvim-tree making maintenance more difficult.

Proposed solution

We split nvim-tree into three distinct part: core, attributes modules & line builder.

Git, diagnostics, modified & opened becomes attributes modules. They interact with core to attach attributes to paths (i.e. directories & files). Core can propagate attributes to parents / children at the attributes module's request.

Core calls line builder with all the path's attributes + other info like name, depth. Line builder returns everything the core needs to display including padding, signcolumn, highlights etc.

Resulting improvements

Direct improvements

  • Maintenance and the implementation of new attributes will be easier as attributes modules will be decoupled from the rest of nvim-tree.
  • User will be allowed to add their own attributes modules. If the modules is deemed useful enough we can add them as one of nvim-tree's build in modules.
  • User will be allowed to override the line builder.

Potential improvements

  • User can be allowed to filter based on arbitrary attributes.
  • Core can be made to only call line builder for paths that have their attributes changed instead of having to do a full reload, thus improving performance.

Decision to be made

  • Structure of the new config:
    • Do we break?
      • We can have more sensible default.
      • We can reorganize configurations, making configuration of all attributes modules more consistent with each other & making it better suited for the current architecture.
      • We can remove / change some of the API to better suit the current architecture, some of the API/option makes less sense with the refactoring such a custom_filter.

Steps

  • Expose API for attribute module to communicate with core.
  • Refector existing attributes to use the new API.
    • opened
    • modified
    • diagnostics
    • git
  • Decouple line builder from the rest of nvim-tree.
  • Restructure options (optional).
  • Add option to let user add their own attributes modules & override line builder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceperformance enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions