Skip to content

Commit e82db1c

Browse files
committed
chore: resolve undefined-field
1 parent 5c46c9c commit e82db1c

File tree

5 files changed

+46
-62
lines changed

5 files changed

+46
-62
lines changed

Diff for: lua/nvim-tree/git/utils.lua

-45
Original file line numberDiff line numberDiff line change
@@ -127,51 +127,6 @@ function M.file_status_to_dir_status(status, cwd)
127127
return r
128128
end
129129

130-
---Git file status for an absolute path with optional fallback
131-
---@param parent_ignored boolean
132-
---@param status table?
133-
---@param path string
134-
---@param path_fallback string?
135-
---@return GitStatus
136-
function M.git_status_file(parent_ignored, status, path, path_fallback)
137-
---@type GitStatus
138-
local st = {}
139-
140-
if parent_ignored then
141-
st.file = "!!"
142-
elseif status and status.files then
143-
st.file = status.files[path] or status.files[path_fallback]
144-
end
145-
146-
return st
147-
end
148-
149-
---Git file and directory status for an absolute path with optional file fallback
150-
---@param parent_ignored boolean
151-
---@param status table?
152-
---@param path string
153-
---@param path_file string? alternative file path when no other file status
154-
---@return GitStatus?
155-
function M.git_status_dir(parent_ignored, status, path, path_file)
156-
---@type GitStatus?
157-
local st
158-
159-
if parent_ignored then
160-
st = {}
161-
st.file = "!!"
162-
elseif status then
163-
st = {}
164-
st.file = status.files and (status.files[path] or status.files[path_file])
165-
if status.dirs then
166-
st.dir = {}
167-
st.dir.direct = status.dirs.direct and status.dirs.direct[path]
168-
st.dir.indirect = status.dirs.indirect and status.dirs.indirect[path]
169-
end
170-
end
171-
172-
return st
173-
end
174-
175130
function M.setup(opts)
176131
if opts.git.cygwin_support then
177132
M.use_cygpath = vim.fn.executable("cygpath") == 1

Diff for: lua/nvim-tree/node/directory-link.lua

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local git_utils = require("nvim-tree.git.utils")
2-
31
local DirectoryNode = require("nvim-tree.node.directory")
42

53
---@class (exact) DirectoryLinkNode: DirectoryNode
@@ -36,11 +34,24 @@ function DirectoryLinkNode:destroy()
3634
DirectoryNode.destroy(self)
3735
end
3836

39-
-----Update the directory GitStatus of link target and the file status of the link itself
40-
-----@param parent_ignored boolean
41-
-----@param status table|nil
37+
---Update the directory GitStatus of link target and the file status of the link itself
38+
---@param parent_ignored boolean
39+
---@param status table|nil
4240
function DirectoryLinkNode:update_git_status(parent_ignored, status)
43-
self.git_status = git_utils.git_status_dir(parent_ignored, status, self.link_to, self.absolute_path)
41+
if parent_ignored then
42+
self.git_status = {}
43+
self.git_status.file = "!!"
44+
elseif status then
45+
self.git_status = {}
46+
self.git_status.file = status.files and (status.files[self.link_to] or status.files[self.absolute_path])
47+
if status.dirs then
48+
self.git_status.dir = {}
49+
self.git_status.dir.direct = status.dirs.direct and status.dirs.direct[self.absolute_path]
50+
self.git_status.dir.indirect = status.dirs.indirect and status.dirs.indirect[self.absolute_path]
51+
end
52+
else
53+
self.git_status = nil
54+
end
4455
end
4556

4657
---Create a sanitized partial copy of a node, populating children recursively.

Diff for: lua/nvim-tree/node/directory.lua

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local git_utils = require("nvim-tree.git.utils")
2-
31
local Node = require("nvim-tree.node")
42

53
---@class (exact) DirectoryNode: Node
@@ -69,7 +67,20 @@ end
6967
---@param parent_ignored boolean
7068
---@param status table|nil
7169
function DirectoryNode:update_git_status(parent_ignored, status)
72-
self.git_status = git_utils.git_status_dir(parent_ignored, status, self.absolute_path, nil)
70+
if parent_ignored then
71+
self.git_status = {}
72+
self.git_status.file = "!!"
73+
elseif status then
74+
self.git_status = {}
75+
self.git_status.file = status.files and status.files[self.absolute_path]
76+
if status.dirs then
77+
self.git_status.dir = {}
78+
self.git_status.dir.direct = status.dirs.direct and status.dirs.direct[self.absolute_path]
79+
self.git_status.dir.indirect = status.dirs.indirect and status.dirs.indirect[self.absolute_path]
80+
end
81+
else
82+
self.git_status = nil
83+
end
7384
end
7485

7586
---@return string[]? xy short-format statuses

Diff for: lua/nvim-tree/node/file-link.lua

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local git_utils = require("nvim-tree.git.utils")
2-
31
local FileNode = require("nvim-tree.node.file")
42

53
---@class (exact) FileLinkNode: FileNode
@@ -32,11 +30,16 @@ function FileLinkNode:destroy()
3230
FileNode.destroy(self)
3331
end
3432

35-
-----Update the GitStatus of the target otherwise the link itself
36-
-----@param parent_ignored boolean
37-
-----@param status table|nil
33+
---Update the GitStatus of the target otherwise the link itself
34+
---@param parent_ignored boolean
35+
---@param status table|nil
3836
function FileLinkNode:update_git_status(parent_ignored, status)
39-
self.git_status = git_utils.git_status_file(parent_ignored, status, self.link_to, self.absolute_path)
37+
self.git_status = {}
38+
if parent_ignored then
39+
self.git_status.file = "!!"
40+
elseif status and status.files then
41+
self.git_status.file = status.files[self.link_to] or status.files[self.absolute_path]
42+
end
4043
end
4144

4245
---Create a sanitized partial copy of a node

Diff for: lua/nvim-tree/node/file.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local git_utils = require("nvim-tree.git.utils")
21
local utils = require("nvim-tree.utils")
32

43
local Node = require("nvim-tree.node")
@@ -44,7 +43,12 @@ end
4443
---@param parent_ignored boolean
4544
---@param status table|nil
4645
function FileNode:update_git_status(parent_ignored, status)
47-
self.git_status = git_utils.git_status_file(parent_ignored, status, self.absolute_path, nil)
46+
self.git_status = {}
47+
if parent_ignored then
48+
self.git_status.file = "!!"
49+
elseif status and status.files then
50+
self.git_status.file = status.files[self.absolute_path]
51+
end
4852
end
4953

5054
---@return string[]? xy short-format statuses

0 commit comments

Comments
 (0)