-
-
Notifications
You must be signed in to change notification settings - Fork 623
feat(log): add node inspection function #2541
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea - it will be most useful to have something that I always end up adding log lines for.
I am a bit hesitant:
- Inspecting nodes is massive as it goes up and down the tree.
- I don't want to encourage users to look into nodes. They are private and definitely shouldn't be mutated.
How about:
- Change this to log raw instead of print
- Accept an
options
parameter to pass directly to vim.inspect
RE 2. I wish we'd never let the nodes escape into public API. I'd like to provide a sanitised copy of nodes like |
I understand your concerns
This can be a good idea, but I don't know if it should go in the API, I'd rather put it in the |
Ah, that would work nicely. I imagine myself doing something like this in an event or mapping: local log = require("nvim-tree.log")
log.node("dev", node, "Event.NodeRenamed %s", data.new_name) I'm happy with your best judgement. This will be useful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre-emptive approval
local inspect_opts = {} | ||
|
||
--- @param opts table | ||
function M.set_inspect_opts(opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the inspect options are rarely changed, I chose to add this little function to set them instead of another parameter to the node
function.
api.tree.inspect_node_under_cursor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works beautifully, many thanks.
Do you want me to just merge after approval or do you want to do it?
--- @vararg any arguments for string.format | ||
function M.node(typ, node, fmt, ...) | ||
if M.enabled(typ) then | ||
node = node or require("nvim-tree.lib").get_node_at_cursor() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is very handy...
Oh, it's really no different to me, just merge whenever you feel like the PR is ready |
I am also happy either way. |
I often use this little function, exposing it in the api might be useful to someone.