4646
4747--- @param state neotree.State
4848--- @param items neotree.FileItem[]
49+ --- @param callback fun ( results : string[] )
50+ --- @overload fun ( state : neotree.State , items : neotree.FileItem[] ): string[]
4951M .mark_ignored = function (state , items , callback )
5052 local folders = {}
5153 log .trace (" ================================================================================" )
@@ -54,50 +56,50 @@ M.mark_ignored = function(state, items, callback)
5456 for _ , item in ipairs (items ) do
5557 local folder = utils .split_path (item .path )
5658 if folder then
57- if not folders [folder ] then
58- folders [folder ] = {}
59- end
59+ folders [folder ] = folders [folder ] or {}
6060 table.insert (folders [folder ], item .path )
6161 end
6262 end
6363
64- local function process_result (result )
64+ --- @param results string[]
65+ local function process_results (results )
6566 if utils .is_windows then
6667 -- on Windows, git seems to return quotes and double backslash "path\\directory"
67- result = vim .tbl_map (function (item )
68+ --- @param item string
69+ results = vim .tbl_map (function (item )
6870 item = item :gsub (" \\\\ " , " \\ " )
6971 return item
70- end , result )
72+ end , results )
7173 else
7274 -- check-ignore does not indicate directories the same as 'status' so we need to
7375 -- add the trailing slash to the path manually if not on Windows.
74- log .trace (" IGNORED: Checking types of" , # result , " items to see which ones are directories" )
75- for i , item in ipairs (result ) do
76+ log .trace (" IGNORED: Checking types of" , # results , " items to see which ones are directories" )
77+ for i , item in ipairs (results ) do
7678 local stat = uv .fs_stat (item )
7779 if stat and stat .type == " directory" then
78- result [i ] = item .. sep
80+ results [i ] = item .. sep
7981 end
8082 end
8183 end
82- result = vim .tbl_map (function (item )
84+ --- @param item string
85+ results = vim .tbl_map (function (item )
86+ item = item :gsub (" \\\\ " , " \\ " )
8387 -- remove leading and trailing " from git output
8488 item = item :gsub (' ^"' , " " ):gsub (' "$' , " " )
8589 -- convert octal encoded lines to utf-8
8690 item = git_utils .octal_to_utf8 (item )
8791 return item
88- end , result )
89- return result
92+ end , results )
93+ return results
9094 end
9195
96+ --- @param all_results string[]
9297 local function finalize (all_results )
93- local show_gitignored = state .filtered_items and state .filtered_items .hide_gitignored == false
94- log .trace (" IGNORED: Comparing results to mark items as ignored:" , show_gitignored )
9598 local ignored , not_ignored = 0 , 0
9699 for _ , item in ipairs (items ) do
97100 if M .is_ignored (all_results , item .path , item .type ) then
98101 item .filtered_by = item .filtered_by or {}
99102 item .filtered_by .gitignored = true
100- item .filtered_by .show_gitignored = show_gitignored
101103 ignored = ignored + 1
102104 else
103105 not_ignored = not_ignored + 1
@@ -107,6 +109,7 @@ M.mark_ignored = function(state, items, callback)
107109 log .trace (" ================================================================================" )
108110 end
109111
112+ --- @type string[]
110113 local all_results = {}
111114 if type (callback ) == " function" then
112115 local jobs = {}
@@ -145,14 +148,14 @@ M.mark_ignored = function(state, items, callback)
145148 log .trace (" IGNORED: Running async git with args: " , args )
146149 end ,
147150 on_exit = function (self , code , _ )
148- local result
151+ local results
149152 if code ~= 0 then
150153 log .debug (" Failed to load ignored files for" , folder , " :" , self :stderr_result ())
151- result = {}
154+ results = {}
152155 else
153- result = self :result ()
156+ results = self :result ()
154157 end
155- vim .list_extend (all_results , process_result ( result ))
158+ vim .list_extend (all_results , process_results ( results ))
156159
157160 running_jobs = running_jobs - 1
158161 completed_jobs = completed_jobs + 1
@@ -173,7 +176,7 @@ M.mark_ignored = function(state, items, callback)
173176 log .debug (" Failed to load ignored files for" , state .path , " :" , result )
174177 result = {}
175178 end
176- vim .list_extend (all_results , process_result (result ))
179+ vim .list_extend (all_results , process_results (result ))
177180 end
178181 finalize (all_results )
179182 return all_results
0 commit comments