"""Base completer for xonsh."""importcollections.abcascabcfromxonsh.completers.commandsimportcomplete_commandfromxonsh.completers.pathimportcontextual_complete_pathfromxonsh.completers.pythonimportcomplete_pythonfromxonsh.completers.toolsimportapply_lprefix,contextual_completerfromxonsh.parsers.completion_contextimportCompletionContext
[docs]@contextual_completerdefcomplete_base(context:CompletionContext):"""If the line is empty, complete based on valid commands, python names, and paths."""# If we are completing the first argument, complete based on# valid commands and python names.ifcontext.commandisNoneorcontext.command.arg_index!=0:# don't do unnecessary completionsreturn# get and unpack python completionspython_comps=complete_python(context)orset()ifisinstance(python_comps,cabc.Sequence):python_comps,python_comps_len=python_comps# type: ignoreyield fromapply_lprefix(python_comps,python_comps_len)else:yield frompython_comps# add command completionsyield fromcomplete_command(context.command)# add paths, if neededifnotcontext.command.prefix:path_comps,path_comp_len=contextual_complete_path(context.command,cdpath=False)yield fromapply_lprefix(path_comps,path_comp_len)