in nubia/internal/completion.py [0:0]
def get_completions(self) -> Iterable[Completion]:
"""
Returns a
"""
logger = logging.getLogger(f"{type(self).__name__}.get_completions")
remaining = None
try:
parsed = parser.parse(
self.doc.text, expect_subcommand=self.cmd.super_command
)
except parser.CommandParseError as e:
parsed = e.partial_result
remaining = e.remaining
# This is a funky but reliable way to figure that last token we are
# interested in manually parsing, This will return the last key=value
# including if the value is a 'value', [list], or {dict} or combination
# of these. This also matches positional arguments.
if self.doc.char_before_cursor in " ]}":
last_token = ""
else:
last_space = self.doc.find_backwards(" ", in_current_line=True) or -1
last_token = self.doc.text[(last_space + 1) :] # noqa
# We pick the bigger match here. The reason we want to look into
# remaining is to capture the state that we are in an open list,
# dictionary, or any other value that may have spaces in it but fails
# parsing (yet).
if remaining and len(remaining) > len(last_token):
last_token = remaining
try:
return self._prepare_args_completions(
parsed_command=parsed, last_token=last_token
)
except Exception as e:
logger.exception(str(e))
return []