@@ -13,8 +13,7 @@ local plugin_map = {}
13
13
14
14
-- Data paths
15
15
local data_dir = vim .fn .stdpath (' data' )
16
- local START_DIR = joinpath (data_dir , ' site' , ' pack' , ' strive' , ' start' )
17
- local OPT_DIR = joinpath (data_dir , ' site' , ' pack' , ' strive' , ' opt' )
16
+ local PACK_DIR = joinpath (data_dir , ' strive' )
18
17
19
18
-- Add to packpath
20
19
vim .opt .packpath :prepend (joinpath (data_dir , ' site' ))
629
628
630
629
-- Get the plugin installation path
631
630
function Plugin :get_path ()
632
- return (not self .is_local and not self .local_path )
633
- and joinpath (self .is_lazy and OPT_DIR or START_DIR , self .plugin_name )
631
+ return (not self .is_local and not self .local_path ) and joinpath (PACK_DIR , self .plugin_name )
634
632
or (joinpath (self .local_path , self .plugin_name ) or self .name )
635
633
end
636
634
@@ -692,7 +690,7 @@ function Plugin:load_scripts()
692
690
end
693
691
694
692
-- Load a plugin and its dependencies
695
- function Plugin :load ()
693
+ function Plugin :load (do_action , callback )
696
694
if self .loaded then
697
695
return true
698
696
end
@@ -709,24 +707,20 @@ function Plugin:load()
709
707
load_opts (self .init_opts )
710
708
end
711
709
712
- if self .is_local then
713
- vim .opt .rtp :append (plugin_path )
710
+ vim .opt .rtp :append (plugin_path )
714
711
715
- local after_path = joinpath (plugin_path , ' after' )
716
- if isdir (after_path ) then
717
- vim .opt .rtp :append (after_path )
718
- end
712
+ local after_path = joinpath (plugin_path , ' after' )
713
+ if isdir (after_path ) then
714
+ vim .opt .rtp :append (after_path )
715
+ end
719
716
720
- local result = Async .try_await (self :load_scripts ())
721
- if result .error then
722
- M .log (
723
- ' error' ,
724
- string.format (' Failed to load scripts for %s: %s' , self .name , tostring (result .error ))
725
- )
726
- return
727
- end
728
- elseif self .is_lazy then
729
- vim .cmd .packadd (self .plugin_name )
717
+ local result = Async .try_await (self :load_scripts ())
718
+ if result .error then
719
+ M .log (
720
+ ' error' ,
721
+ string.format (' Failed to load scripts for %s: %s' , self .name , tostring (result .error ))
722
+ )
723
+ return
730
724
end
731
725
732
726
self .loaded = true
@@ -767,6 +761,14 @@ function Plugin:load()
767
761
load_opts (self .config_opts )
768
762
end
769
763
764
+ if do_action and self .run_action then
765
+ vim .cmd (self .run_action )
766
+ end
767
+
768
+ if callback then
769
+ callback ()
770
+ end
771
+
770
772
return true
771
773
end )()
772
774
@@ -815,34 +817,9 @@ function Plugin:ft(filetypes)
815
817
group = id ,
816
818
pattern = self .filetypes ,
817
819
once = true ,
818
- callback = function (args )
819
- if not self .loaded and self :load () then
820
- local augroup_name = nil
821
- if self .plugin_name :find (' lspconfig' , 1 , true ) then
822
- augroup_name = ' nvim.lsp.enable'
823
- else
824
- local res = api .nvim_exec2 (' autocmd FileType' , { output = true })
825
- if not res .output then
826
- return
827
- end
828
- res = { unpack (vim .split (res .output , ' \n ' ), 1 ) }
829
- for i , item in ipairs (res ) do
830
- if item :find (self .plugin_name , 1 , true ) then
831
- augroup_name = res [i - 1 ]:match (' ^%s*(%S+)' )
832
- end
833
- end
834
- end
835
-
836
- if augroup_name then
837
- vim .schedule (function ()
838
- api .nvim_exec_autocmds (' FileType' , {
839
- group = augroup_name ,
840
- buffer = args .buf ,
841
- data = args .data ,
842
- modeline = false ,
843
- })
844
- end )
845
- end
820
+ callback = function ()
821
+ if not self .loaded then
822
+ self :load ()
846
823
end
847
824
end ,
848
825
})
@@ -873,17 +850,9 @@ function Plugin:cmd(commands)
873
850
-- Remove this command to avoid recursion
874
851
pcall (api .nvim_del_user_command , name )
875
852
local args = opts .args ~= ' ' and (' ' .. opts .args ) or ' '
876
- local bang = opts .bang
877
-
878
- Async .async (function ()
879
- self :load ()
880
- if self .is_local then
881
- Async .await (Async .delay (5 ))
882
- end
883
- Async .safe_schedule (function ()
884
- execute (name , bang , args )
885
- end )
886
- end )()
853
+ self :load (false , function ()
854
+ execute (name , opts .bang , args )
855
+ end )
887
856
end , {
888
857
nargs = ' *' ,
889
858
bang = true ,
@@ -988,7 +957,7 @@ function Plugin:theme(name)
988
957
local installed = Async .await (self :is_installed ())
989
958
if installed then
990
959
vim .schedule (function ()
991
- vim .opt .rtp :append (joinpath (START_DIR , self .plugin_name ))
960
+ vim .opt .rtp :append (joinpath (PACK_DIR , self .plugin_name ))
992
961
vim .cmd .colorscheme (self .colorscheme )
993
962
end )
994
963
end
@@ -1087,8 +1056,7 @@ function Plugin:install()
1087
1056
1088
1057
-- Run build command if specified
1089
1058
if self .run_action then
1090
- self :load ()
1091
- vim .cmd (self .run_action )
1059
+ self :load (true )
1092
1060
end
1093
1061
else
1094
1062
self .status = STATUS .ERROR
@@ -1305,8 +1273,7 @@ function Plugin:install_with_retry()
1305
1273
1306
1274
-- Run command if specified
1307
1275
if self .run_action then
1308
- self :load ()
1309
- vim .cmd (self .run_action )
1276
+ self :load (true )
1310
1277
end
1311
1278
else
1312
1279
self .status = STATUS .ERROR
@@ -1543,7 +1510,7 @@ function M.clean()
1543
1510
end
1544
1511
1545
1512
-- Scan both start and opt directories
1546
- scan_directory (START_DIR )
1513
+ scan_directory (PACK_DIR )
1547
1514
scan_directory (OPT_DIR )
1548
1515
1549
1516
local strive_plugin = Plugin .new ({
@@ -1668,7 +1635,7 @@ local function setup_auto_install()
1668
1635
end )
1669
1636
startuptime ()
1670
1637
end ,
1671
- once = true , -- Only trigger once to avoid recursion
1638
+ once = true ,
1672
1639
})
1673
1640
end
1674
1641
0 commit comments