88local MODSTR = ' project.popup'
99local ERROR = vim .log .levels .ERROR
1010local WARN = vim .log .levels .WARN
11+ local uv = vim .uv or vim .loop
1112local in_list = vim .list_contains
1213local empty = vim .tbl_isempty
1314
@@ -39,7 +40,7 @@ local function hidden_avail(path, hidden)
3940
4041 local fd = Util .executable (' fd' ) and ' fd' or (Util .executable (' fdfind' ) and ' fdfind' or ' ' )
4142 if fd == ' ' then
42- error ((' (%s.hidden_avail): `fd`/`fdfind` could be found PATH!' ):format (MODSTR ), ERROR )
43+ error ((' (%s.hidden_avail): `fd`/`fdfind` not found in found PATH!' ):format (MODSTR ), ERROR )
4344 end
4445
4546 local cmd = { fd , ' -Iad1' }
@@ -102,8 +103,7 @@ local function open_node(proj, only_cd, ran_cd)
102103 })
103104 end
104105 if not ran_cd then
105- local success = require (' project.api' ).set_pwd (proj , ' prompt' )
106- if not success then
106+ if not require (' project.api' ).set_pwd (proj , ' prompt' ) then
107107 vim .notfy (' (open_node): Unsucessful `set_pwd`!' , ERROR )
108108 return
109109 end
@@ -114,7 +114,7 @@ local function open_node(proj, only_cd, ran_cd)
114114 vim .g .project_nvim_cwd = proj
115115 end
116116
117- local dir = vim . uv .fs_scandir (proj )
117+ local dir = uv .fs_scandir (proj )
118118 if not dir then
119119 vim .notify ((' (%s.open_node): NO DIR `%s`!' ):format (MODSTR , proj ), ERROR )
120120 return
@@ -123,13 +123,12 @@ local function open_node(proj, only_cd, ran_cd)
123123 local hidden = require (' project.config' ).options .show_hidden
124124 local ls = {}
125125 while true do
126- local node = vim . uv .fs_scandir_next (dir )
126+ local node = uv .fs_scandir_next (dir )
127127 if not node then
128128 break
129129 end
130130 node = proj .. ' /' .. node
131- local stat = vim .uv .fs_stat (node )
132- if stat then
131+ if uv .fs_stat (node ) then
133132 local hid = is_hidden (node )
134133 if (hidden and hid ) or hidden_avail (node , hidden ) then
135134 table.insert (ls , node )
@@ -154,7 +153,7 @@ local function open_node(proj, only_cd, ran_cd)
154153 end
155154
156155 item = Util .rstrip (' /' , vim .fn .fnamemodify (item , ' :p' ))
157- local stat = vim . uv .fs_stat (item )
156+ local stat = uv .fs_stat (item )
158157 if not stat then
159158 return
160159 end
@@ -192,6 +191,7 @@ function Popup.select.new(opts)
192191 if empty (opts ) then
193192 error ((' (%s.select.new): Empty args for constructor!' ):format (MODSTR ), ERROR )
194193 end
194+
195195 if Util .vim_has (' nvim-0.11' ) then
196196 vim .validate (' choices' , opts .choices , ' function' , false , ' fun(): table<string, function>' )
197197 vim .validate (' choices_list' , opts .choices_list , ' function' , false , ' fun(): string[]' )
@@ -204,8 +204,7 @@ function Popup.select.new(opts)
204204 })
205205 end
206206
207- --- @type Project.Popup.SelectChoices | ProjectCmdFun
208- local T = setmetatable ({
207+ local T = setmetatable ({ --- @type Project.Popup.SelectChoices | ProjectCmdFun
209208 choices = opts .choices ,
210209 choices_list = opts .choices_list ,
211210 }, {
@@ -267,8 +266,7 @@ Popup.delete_menu = Popup.select.new({
267266 vim .ui .select (choices_list , {
268267 prompt = ' Select a project to delete:' ,
269268 format_item = function (item ) --- @param item string
270- local session = require (' project.utils.history' ).session_projects
271- if in_list (session , item ) then
269+ if in_list (require (' project.utils.history' ).session_projects , item ) then
272270 return ' * ' .. item
273271 end
274272 return item
@@ -298,8 +296,7 @@ Popup.delete_menu = Popup.select.new({
298296 return recents
299297 end ,
300298 choices = function ()
301- --- @type table<string , fun ()>
302- local T = {}
299+ local T = {} --- @type table<string , function>
303300 for _ , proj in ipairs (require (' project.utils.history' ).get_recent_projects ()) do
304301 T [proj ] = function ()
305302 require (' project.utils.history' ).delete_project (proj )
@@ -357,9 +354,7 @@ Popup.recents_menu = Popup.select.new({
357354Popup .open_menu = Popup .select .new ({
358355 callback = function ()
359356 local choices_list = Popup .open_menu .choices_list ()
360- vim .ui .select (choices_list , {
361- prompt = ' Select an operation:' ,
362- }, function (item )
357+ vim .ui .select (choices_list , { prompt = ' Select an operation:' }, function (item )
363358 if not item then
364359 return
365360 end
@@ -379,28 +374,16 @@ Popup.open_menu = Popup.select.new({
379374 choices = function ()
380375 local Config = require (' project.config' )
381376 local res = { --- @type table<string , ProjectCmdFun>
382- [' Project Session' ] = function ()
383- Popup .session_menu ()
384- end ,
385- [' New Project' ] = function ()
386- require (' project.commands' ).cmds .ProjectAdd ()
387- end ,
388- [' Open Recent Project' ] = function ()
389- Popup .recents_menu ()
390- end ,
391- [' Delete A Project' ] = function ()
392- Popup .delete_menu ()
393- end ,
394- [' Show Config' ] = function ()
395- require (' project.commands' ).cmds .ProjectConfig ()
396- end ,
397- [' Open History' ] = function ()
398- vim .cmd .ProjectHistory ()
399- end ,
377+ [' Project Session' ] = Popup .session_menu ,
378+ [' New Project' ] = require (' project.commands' ).cmds .ProjectAdd ,
379+ [' Open Recent Project' ] = Popup .recents_menu ,
380+ [' Delete A Project' ] = Popup .delete_menu ,
381+ [' Show Config' ] = require (' project.commands' ).cmds .ProjectConfig ,
382+ [' Open History' ] = vim .cmd .ProjectHistory ,
400383 [' Open Help Docs' ] = function ()
401384 vim .cmd .help (' project-nvim' )
402385 end ,
403- [' Run Checkhealth' ] = function ()
386+ [' Run Checkhealth' ] = vim . cmd . ProjectHealth or function ()
404387 vim .cmd .checkhealth (' project' )
405388 end ,
406389 [' Go To Source Code' ] = function ()
@@ -409,22 +392,14 @@ Popup.open_menu = Popup.select.new({
409392 Exit = function () end ,
410393 }
411394 if vim .g .project_telescope_loaded == 1 then
412- res [' Open Telescope Picker' ] = function ()
413- require (' telescope._extensions.projects' ).projects ()
414- end
395+ res [' Open Telescope Picker' ] = require (' telescope._extensions.projects' ).projects
415396 end
416397 if Config .options .fzf_lua .enabled then
417- res [' Open Fzf-Lua Picker' ] = function ()
418- require (' project.extensions.fzf-lua' ).run_fzf_lua ()
419- end
398+ res [' Open Fzf-Lua Picker' ] = require (' project.extensions.fzf-lua' ).run_fzf_lua
420399 end
421400 if Config .options .log .enabled then
422- res [' Open Log' ] = function ()
423- require (' project.utils.log' ).open_win ()
424- end
425- res [' Clear Log' ] = function ()
426- require (' project.utils.log' ).clear_log ()
427- end
401+ res [' Open Log' ] = require (' project.utils.log' ).open_win
402+ res [' Clear Log' ] = require (' project.utils.log' ).clear_log
428403 end
429404 return res
430405 end ,
0 commit comments