Completion Context Objects (found in xonsh.parsers.completion_context)

class xonsh.parsers.completion_context.CompletionContext(command: Optional[xonsh.parsers.completion_context.CommandContext] = None, python: Optional[xonsh.parsers.completion_context.PythonContext] = None)[source]

The object containing the current completion context.

Create new instance of CompletionContext(command, python)

command: Optional[xonsh.parsers.completion_context.CommandContext]

The current command. This will be None when we can’t be completing a command, e.g. echo @(<TAB>.

python: Optional[xonsh.parsers.completion_context.PythonContext]

The current python code. This will be None when we can’t be completing python, e.g. echo $(<TAB>.

class xonsh.parsers.completion_context.CommandContext(args: Tuple[xonsh.parsers.completion_context.CommandArg, ], arg_index: int, prefix: str = '', suffix: str = '', opening_quote: str = '', closing_quote: str = '', is_after_closing_quote: bool = False, subcmd_opening: str = '')[source]

The object containing the current command’s completion context.

Create new instance of CommandContext(args, arg_index, prefix, suffix, opening_quote, closing_quote, is_after_closing_quote, subcmd_opening)

completing_command(command: str) → bool[source]

Return whether this context is completing args for a command

arg_index: int

The current argument’s index

args: Tuple[xonsh.parsers.completion_context.CommandArg, ]

The arguments in the command

closing_quote: str

The current arg’s closing quote if it exists (e.g. ', ", ''')

is_after_closing_quote: bool

The cursor is appending to a closed string literal, i.e. cursor at the end of ls "/usr/". This affects the completion’s behaviour - see Completer.complete in xonsh/completer.py.

opening_quote: str

The current arg’s opening quote if it exists (e.g. ', r", ''')

prefix: str

The current string arg’s prefix

property raw_prefix

Prefix before the cursor, including quotes

subcmd_opening: str

If this command is inside a subproc expression (e.g. $(, ![)

suffix: str

The current string arg’s suffix

class xonsh.parsers.completion_context.CommandArg(value: str, opening_quote: str = '', closing_quote: str = '')[source]

An argument for a command

Create new instance of CommandArg(value, opening_quote, closing_quote)

closing_quote: str

The arg’s closing quote (if it exists)

opening_quote: str

The arg’s opening quote (if it exists)

property raw_value

The complete argument including quotes

value: str

The argument’s value

class xonsh.parsers.completion_context.PythonContext(multiline_code: str, cursor_index: int, is_sub_expression: bool = False, ctx: Optional[Dict[str, Any]] = None)[source]

The object containing the current python code completion context.

Create new instance of PythonContext(multiline_code, cursor_index, is_sub_expression, ctx)

ctx: Optional[Dict[str, Any]]

Objects in the current execution context

cursor_index: int

The cursor’s index in the multiline code

is_sub_expression: bool

Whether this is a sub expression (@(...))

multiline_code: str

The multi-line python code

property prefix

The code from the start to the cursor (may be multiline)