-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
[Feature] User Decorators #2948
Comments
That's a great idea! There's nothing blocking us from doing this: Add a Instantiate them with highest priority. Make the Add help entries that just direct to the Add |
|
Safer approach: Create a This class will be similar to
|
Challenges:
|
Migrating to classic to allow simple class instantiation and privacy: #2991 |
A proof-of-concept for user decorators has been created: #2996 I'd be most grateful if you tested this, instructions to follow. cd /path/to/nvim-tree.lua
git pull 2948-add-user-decorators
git checkout When you're finished testing: git checkout master |
Please note that this is a proof of concept for now. TODO:
Example decorator class to highlight and add an icon to files named "example": local UserDecorator = require("nvim-tree.renderer.decorator.user")
---A string with one or more highlight groups applied to it
---@class (exact) HighlightedString
---@field str string
---@field hl string[] highlight groups applied in order
---Custom user decorators must inherit from UserDecorator
---@class (exact) UserDecoratorExample: UserDecorator
---@field private my_icon HighlightedString
local UserDecoratorExample = UserDecorator:extend()
---Constructor will be called once per tree render, with no arguments.
function UserDecoratorExample:new()
UserDecoratorExample.super.new(self, {
enabled = true,
hl_pos = "name",
icon_placement = "right_align",
})
-- create your icon once, for convenience
self.my_icon = { str = "E", hl = { "ExampleIcon" } }
-- Define the icon sign only once
-- Only needed if you are using icon_placement = "signcolumn"
-- self:define_sign(self.my_icon)
end
---@param node Node
---@return HighlightedString[]|nil icons
function UserDecoratorExample:calculate_icons(node)
if node.name == "example" then
return { self.my_icon }
else
return nil
end
end
---@param node Node
---@return string|nil group
function UserDecoratorExample:calculate_highlight(node)
if node.name == "example" then
return "ExampleHighlight"
else
return nil
end
end Registering it: require("nvim-tree").setup({
renderer = {
user_decorators = {
{
class = UserDecoratorExample,
},
},
},
}) |
@b0o and @DMyashkov I would be most grateful for your testing and feedback. I'm open to any and all ideas and changes. |
@b0o you won't have access to explorer, however you will be able to use API: |
I would love to have an API for defining custom decorators. My use case is to add an icon/highlight for nodes which are in the quickfix list. I've come up with a hacky way to accomplish this, by overriding the bookmarks decorator:
It would be nice if there was an official way to do this.
The text was updated successfully, but these errors were encountered: