@@ -307,6 +307,16 @@ function Async.scandir(dir)
307307 end
308308end
309309
310+ function Async .safe_schedule (callback )
311+ if vim .in_fast_event () then
312+ vim .schedule (function ()
313+ callback ()
314+ end )
315+ else
316+ callback ()
317+ end
318+ end
319+
310320-- =====================================================================
311321-- 3. Task Queue
312322-- =====================================================================
@@ -643,17 +653,6 @@ local function load_opts(opt)
643653 return type (opt ) == ' string' and vim .cmd (opt ) or opt ()
644654end
645655
646- function Plugin :packadd ()
647- -- If it's a lazy-loaded plugin, add it
648- if self .is_lazy then
649- if not self .is_local then
650- vim .cmd .packadd (self .plugin_name )
651- else
652- vim .opt .rtp :append (self :get_path ())
653- end
654- end
655- end
656-
657656-- Load a plugin and its dependencies
658657function Plugin :load (opts )
659658 if self .loaded then
@@ -674,7 +673,21 @@ function Plugin:load(opts)
674673 load_opts (self .init_opts )
675674 end
676675
677- self :packadd ()
676+ if self .is_local then
677+ -- For local plugins, add directly to runtimepath
678+ local plugin_path = self :get_path ()
679+ vim .opt .rtp :append (plugin_path )
680+
681+ -- Also check for and add the 'after' directory
682+ local after_path = vim .fs .joinpath (plugin_path , ' after' )
683+ if isdir (after_path ) then
684+ vim .opt .rtp :append (after_path )
685+ end
686+ elseif self .is_lazy then
687+ -- For non-local lazy plugins, use packadd
688+ vim .cmd .packadd (self .plugin_name )
689+ end
690+
678691 self :load_scripts ((opts and opts .script_cb ) and opts .script_cb or nil )
679692 self :call_setup ()
680693
@@ -813,7 +826,7 @@ function Plugin:load_scripts(callback)
813826 end
814827
815828 if # scripts > 0 then
816- vim . schedule (function ()
829+ Async . safe_schedule (function ()
817830 for _ , file_path in ipairs (scripts ) do
818831 vim .cmd .source (vim .fn .fnameescape (file_path ))
819832 end
0 commit comments