-
-
Notifications
You must be signed in to change notification settings - Fork 611
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
fix: arithmetic on nil value error on first git project open #3064
Conversation
@@ -391,7 +391,7 @@ function Explorer:populate_children(handle, cwd, node, project, parent) | |||
end | |||
else | |||
for reason, value in pairs(FILTER_REASON) do | |||
if filter_reason == value then |
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.
It looks like node.hidden_stats
could still be nil, as it's an optional member.
How about something really defensive like:
diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua
index 0fdd46a..c42ffe0 100644
--- a/lua/nvim-tree/explorer/init.lua
+++ b/lua/nvim-tree/explorer/init.lua
@@ -389,9 +389,9 @@ function Explorer:populate_children(handle, cwd, node, project, parent)
nodes_by_path[child.absolute_path] = true
child:update_git_status(node_ignored, project)
end
- else
+ elseif node.hidden_stats then
for reason, value in pairs(FILTER_REASON) do
- if filter_reason == value then
+ if filter_reason == value and type(node.hidden_stats[reason]) == "number" then
node.hidden_stats[reason] = node.hidden_stats[reason] + 1
end
end
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.
Implemented it and it works for me as well.
I only have this issue on windows so this defensive version might be better to not break anything on linux.
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.
Many thanks for your contribution!
I'm glad you were able to test windows.
No problem, was just a small fix for myself anyways :) |
Apologies; I didn't press the merge button. |
When opening neovim in a directory with a git repo for the first time after PC reboot, I always got this error message:
This small change fixes it for me. I don't looked into the code all that deep, so maybe there is a better fix.
On a quick scim through the Issues I didn't find any matching Issue, maybe I overlooked it.