@@ -24,50 +24,54 @@ local function on_attach()
2424 end
2525end
2626
27- require (" project" ).setup ({
28- -- first argument is the workspace name
29- manual_mode = true ,
30- before_attach = function (target_dir )
31- local persistence = require (" persistence" )
32- if persistence .active () then
33- local cwd = vim .uv .cwd ()
34- if cwd and vim .fs .normalize (cwd ) ~= vim .fs .normalize (target_dir ) then
35- persistence .save ()
27+ defer .on_load (" project" , function ()
28+ require (" project" ).setup ({
29+ -- first argument is the workspace name
30+ manual_mode = true ,
31+ before_attach = function (target_dir )
32+ local persistence = require (" persistence" )
33+ if persistence .active () then
34+ local cwd = vim .uv .cwd ()
35+ if cwd and vim .fs .normalize (cwd ) ~= vim .fs .normalize (target_dir ) then
36+ persistence .save ()
37+ end
38+ persistence .stop ()
3639 end
37- persistence .stop ()
38- end
39- end ,
40- on_attach = on_attach ,
41- })
40+ end ,
41+ on_attach = on_attach ,
42+ })
43+ --
44+ -- dont autoload if nvim start with arg
45+ if vim .fn .argc (- 1 ) > 0 then
46+ return
47+ end
48+
49+ local root , method = require (" project" ).get_project_root ()
50+ if not root then
51+ return
52+ end
53+
54+ if vim .fn .fnamemodify (vim .fn .getcwd (), " :p:h" ) == root then
55+ on_attach ()
56+ return
57+ end
58+
59+ require (" project.api" ).set_pwd (root , method )
60+
61+ defer .on_postload (" telescope" , function ()
62+ require (" telescope" ).load_extension (" projects" )
63+ end )
64+
65+ pickers .map (pickers .prefix .. " w" , function (telescope )
66+ telescope .extensions .projects .projects ()
67+ end , { desc = " projects" })
68+ end )
4269
4370vim .api .nvim_create_autocmd ({ " VimEnter" }, {
4471 pattern = " *" ,
4572 group = vim .api .nvim_create_augroup (" ProjectVimEnter" , {}),
4673 nested = true ,
4774 callback = function ()
48- -- dont autoload if nvim start with arg
49- if vim .fn .argc (- 1 ) > 0 then
50- return
51- end
52-
53- local root , method = require (" project" ).get_project_root ()
54- if not root then
55- return
56- end
57-
58- if vim .fn .fnamemodify (vim .fn .getcwd (), " :p:h" ) == root then
59- on_attach ()
60- return
61- end
62-
63- require (" project.api" ).set_pwd (root , method )
75+ defer .ensure (" project" )
6476 end ,
6577})
66-
67- defer .on_postload (" telescope" , function ()
68- require (" telescope" ).load_extension (" projects" )
69- end )
70-
71- pickers .map (pickers .prefix .. " w" , function (telescope )
72- telescope .extensions .projects .projects ()
73- end , { desc = " projects" })
0 commit comments