Skip to content

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

Merged
merged 7 commits into from
Nov 25, 2023

Conversation

Akmadan23
Copy link
Collaborator

I often use this little function, exposing it in the api might be useful to someone.

Copy link
Member

@alex-courtis alex-courtis left a 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:

  1. Inspecting nodes is massive as it goes up and down the tree.
  2. 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

@alex-courtis
Copy link
Member

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 sort.sorter however that's going to be difficult...

@Akmadan23
Copy link
Collaborator Author

I understand your concerns

Change this to log raw instead of print

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 log module...

@alex-courtis
Copy link
Member

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 log module...

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.

Copy link
Member

@alex-courtis alex-courtis left a 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)
Copy link
Collaborator Author

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.

@Akmadan23 Akmadan23 changed the title feat: add api.tree.inspect_node_under_cursor feat(log): add node inspection function Nov 23, 2023
Copy link
Member

@alex-courtis alex-courtis left a 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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is very handy...

@Akmadan23
Copy link
Collaborator Author

Do you want me to just merge after approval or do you want to do it?

Oh, it's really no different to me, just merge whenever you feel like the PR is ready

@Akmadan23 Akmadan23 merged commit 5231562 into master Nov 25, 2023
@Akmadan23 Akmadan23 deleted the api-add-tree.inspect_node_under_cursor branch November 25, 2023 20:46
@alex-courtis
Copy link
Member

Do you want me to just merge after approval or do you want to do it?

Oh, it's really no different to me, just merge whenever you feel like the PR is ready

I am also happy either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants