Skip to content
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

feat(#1389): add recurse opt for git and diag moves #2525

Merged
merged 8 commits into from
Jan 6, 2024
Merged

feat(#1389): add recurse opt for git and diag moves #2525

merged 8 commits into from
Jan 6, 2024

Conversation

antznin
Copy link
Contributor

@antznin antznin commented Nov 9, 2023

Would like having comments on this feature that I personally find useful. This solves the initial problem stated in #1389, I think. Also works when nvim-tree.git.show_on_dirs or nvim-tree.git.show_on_open_dirs are set to true/false.

@antznin antznin marked this pull request as draft November 10, 2023 02:05
@antznin antznin marked this pull request as ready for review November 10, 2023 02:35
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.

This is great! I've been wanting this for a long time...

Works beautifully:

  • one deep
  • many deep
  • deltas at multiple levels
  • group_empty = true
  • show_on_dirs = true show_on_open_dirs = false

Except for:

  • show_on_dirs = false - does not recurse

lua/nvim-tree/actions/moves/git.lua Outdated Show resolved Hide resolved
lua/nvim-tree/actions/moves/git.lua Outdated Show resolved Hide resolved
doc/nvim-tree-lua.txt Outdated Show resolved Hide resolved
@antznin
Copy link
Contributor Author

antznin commented Nov 13, 2023

Except for:

* [ ]  `show_on_dirs = false` - does not recurse

@alex-courtis This cannot work with show_on_dirs set to false because move_to_next_git_item() does not see the inner nodes statuses. Is this behavior OK? I don't see another approach that would make this work with show_on_dirs = false.

@alex-courtis
Copy link
Member

alex-courtis commented Nov 13, 2023

Except for:

* [ ]  `show_on_dirs = false` - does not recurse

@alex-courtis This cannot work with show_on_dirs set to false because move_to_next_git_item() does not see the inner nodes statuses. Is this behavior OK? I don't see another approach that would make this work with show_on_dirs = false.

I see. It looks like we have a short-circuit to not retrieve git status on folders:

That's OK; we can remove that one: git status is now very cheap and will likely be fetched at some point.

lua/nvim-tree/keymap.lua Outdated Show resolved Hide resolved
@antznin antznin changed the title feat(#1389): add git next_recurse feat(#1389): add recurse opt for git and diag moves Dec 3, 2023
@antznin
Copy link
Contributor Author

antznin commented Dec 3, 2023

My previous commit defines a new recurse api opt, and moves the logic to actions/moves/item.lua. However there were some limitations, and perhaps bugs I faced. Let me summarize here below:

  • The opened case is different because there is no show_on_dirs/show_on_open_dirs for this type of move. The way it is currently implemented, it does not propagate that information to the parent. The only way I would see opened being recursive at the moment would be for the parent nodes (directories) to hold that opened information on their children.

  • The show_on_dirs/show_on_open_dirs options are acting strange for diagnostics. If show_on_dirs = true and show_on_open_dirs = false, the diagnostic mark is not propagated to the parent directories when they are closed. When both options are set to true the parent directory does show the diagnostic mark and the recurse works the same as for git. Git does not have that issue: the status is correctly displayed on the closed directory when show_on_dirs = true and show_on_open_dirs = false.

  • Taking my previous comment in consideration, diagnostics and git recurse moves do work well together though when both are enabled 👍.

I was able to map these next moves with the recurse opt like so:

  vim.keymap.set('n', ']e', function() api.node.navigate.diagnostics.next({recurse=true}) end, opts('Next Diagnostic'))
  vim.keymap.set('n', ']c', function() api.node.navigate.git.next({recurse=true}) end, opts('Next Git'))

It this the way you suggested it to be @alex-courtis?

@alex-courtis
Copy link
Member

It this the way you suggested it to be @alex-courtis?

Fantastic! I'll review and test this one next weekend.

@alex-courtis
Copy link
Member

The show_on_dirs/show_on_open_dirs options are acting strange for diagnostics. If show_on_dirs = true and show_on_open_dirs = false, the diagnostic mark is not propagated to the parent directories when they are closed. When both options are set to true the parent directory does show the diagnostic mark and the recurse works the same as for git. Git does not have that issue: the status is correctly displayed on the closed directory when show_on_dirs = true and show_on_open_dirs = false.

I'm completely fine with that: there are many factors at play with diagnostics, which are usually quite lazy. Git is always known. We could try and tweak if it becomes a problem.

@alex-courtis
Copy link
Member

  • The opened case is different because there is no show_on_dirs/show_on_open_dirs for this type of move. The way it is currently implemented, it does not propagate that information to the parent. The only way I would see opened being recursive at the moment would be for the parent nodes (directories) to hold that opened information on their children.

Many thanks for looking into that one; YAGNI

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.

Looking good; all the pieces are there and work, just needs API tidy.

Many thanks for all your work on this one and apologies for lacking the time to review.

lua/nvim-tree/api.lua Outdated Show resolved Hide resolved
@antznin
Copy link
Contributor Author

antznin commented Dec 25, 2023

@alex-courtis Should be good now.

lua/nvim-tree/api.lua Outdated Show resolved Hide resolved
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.

This is looking great - change is well contained with a very small blast radius.

Same test results as #2525 (review)

Is it intended for this functionality to work when show_on_dirs = false? Did you look at always retrieving git status as per #2525 (comment) ?

If we don't intend it to work we could:

  • document the limitation
  • document the fallback behaviour
  • show_on_dirs = false
  • missing prevs
  • minor nits

lua/nvim-tree/actions/moves/item.lua Outdated Show resolved Hide resolved
lua/nvim-tree/api.lua Outdated Show resolved Hide resolved
@antznin
Copy link
Contributor Author

antznin commented Dec 30, 2023

Is it intended for this functionality to work when show_on_dirs = false? Did you look at always retrieving git status as per #2525 (comment) ?

@alex-courtis No, it will not work when show_on_dirs = false atm because the recursive mechanism relies on the original move mechanism: if no status is shown anywhere in the tree, moving is not possible even if one of the directory contains a file with a status.

Retrieving the git status for a directory when show_on_dirs = false is possible though, and would remove this limitation. I could work on this later but right now I will I will document the limitation in this PR instead.

@alex-courtis
Copy link
Member

Retrieving the git status for a directory when show_on_dirs = false is possible though, and would remove this limitation. I could work on this later but right now I will I will document the limitation in this PR instead.

No worries. I will hold you to that ;)

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.

This is great, it's working exactly as advertised.

However, we should still implement the prev use cases. They will inevitably be requested as soon as users discover this new functionality, which will be surprisingly quick.

I'm not seeing any reason why we can't do that with move_next_recursive - it's quite comprehensive.

Also... merge conflicts, sorry.

doc/nvim-tree-lua.txt Outdated Show resolved Hide resolved
The recurse opt can be used to directly go to the next item showing
git/diagnostic status recursively.

Signed-off-by: Antonin Godard <[email protected]>
Rename get_status to status_is_valid.

Use status_is_valid function in multiple place to avoid duplicating
code.

Signed-off-by: Antonin Godard <[email protected]>
The root node cannot have a status. Previously if moving from the root
node, status_is_valid was trying to fetch the status from it and errored.

Signed-off-by: Antonin Godard <[email protected]>
@antznin
Copy link
Contributor Author

antznin commented Jan 5, 2024

Hi @alex-courtis, here are 4 commits implementing next and prev recursive moves as discussed.

doc/nvim-tree-lua.txt Outdated Show resolved Hide resolved
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.

Everything works and is documented, great job!

  • move to utils.lua
  • remove limitation from diagnostics help

lua/nvim-tree/actions/moves/item.lua Outdated Show resolved Hide resolved
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.

Working nicely, many thanks for all your work.

Changing my git bindings now :)

@alex-courtis alex-courtis merged commit 5d13cc8 into nvim-tree:master Jan 6, 2024
4 checks passed
alex-courtis added a commit that referenced this pull request Jan 7, 2024
…2525)

* feat(#1389): add next recursive for git and diag moves

The recurse opt can be used to directly go to the next item showing
git/diagnostic status recursively.

Signed-off-by: Antonin Godard <[email protected]>

* refactor: status logic in single function

Rename get_status to status_is_valid.

Use status_is_valid function in multiple place to avoid duplicating
code.

Signed-off-by: Antonin Godard <[email protected]>

* feat(#1389): add prev recursive for git and diag moves

Signed-off-by: Antonin Godard <[email protected]>

* fix(#1389): next recursive: take root node into account

The root node cannot have a status. Previously if moving from the root
node, status_is_valid was trying to fetch the status from it and errored.

Signed-off-by: Antonin Godard <[email protected]>

* fix(#1389): doc: remove show_on_open_dirs limitation

Signed-off-by: Antonin Godard <[email protected]>

* feat(#1389): move find_node_line to utils

Signed-off-by: Antonin Godard <[email protected]>

* feat(#1389): doc: note recursive moves are to files only, tidy

---------

Signed-off-by: Antonin Godard <[email protected]>
Co-authored-by: Alexander Courtis <[email protected]>
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.

4 participants