@@ -218,10 +218,15 @@ def _create_stub_commands_for_completion(self, command_names):
218218 :param command_names: List of command names to create stubs for
219219 """
220220 from azure .cli .core .commands import AzCliCommand
221+
222+ def _stub_handler (* args , ** kwargs ):
223+ """Stub command handler used only for argument completion."""
224+ return None
225+
221226 for cmd_name in command_names :
222227 if cmd_name not in self .command_table :
223- # Create stub with no-op handler - never invoked during completion
224- self .command_table [cmd_name ] = AzCliCommand (self , cmd_name , lambda : None )
228+ # Stub commands only need names for argcomplete parser construction.
229+ self .command_table [cmd_name ] = AzCliCommand (self , cmd_name , _stub_handler )
225230
226231 def _update_command_definitions (self ):
227232 for cmd_name in self .command_table :
@@ -452,6 +457,7 @@ def _get_extension_suppressions(mod_loaders):
452457
453458 if index_modules == TOP_LEVEL_COMPLETION_MARKER :
454459 self ._create_stub_commands_for_completion (index_extensions )
460+ _update_command_table_from_extensions ([], ALWAYS_LOADED_EXTENSIONS )
455461 return self .command_table
456462
457463 # Always load modules and extensions, because some of them (like those in
@@ -604,10 +610,14 @@ def _get_top_level_completion_commands(self):
604610 """Get all command names for top-level completion optimization.
605611
606612 Returns marker and command list for creating stub commands without module loading.
613+ Returns None if index is empty, triggering fallback to full module loading.
607614
608- :return: tuple of (TOP_LEVEL_COMPLETION_MARKER, list of command names)
615+ :return: tuple of (TOP_LEVEL_COMPLETION_MARKER, list of command names) or None
609616 """
610- index = self .INDEX [self ._COMMAND_INDEX ]
617+ index = self .INDEX .get (self ._COMMAND_INDEX ) or {}
618+ if not index :
619+ logger .debug ("Command index is empty, will fall back to loading all modules" )
620+ return None
611621 all_commands = list (index .keys ())
612622 logger .debug ("Top-level completion: %d commands available" , len (all_commands ))
613623 return TOP_LEVEL_COMPLETION_MARKER , all_commands
0 commit comments