forked from VimPlug/jedi
34 lines
897 B
Python
34 lines
897 B
Python
"""
|
|
Helpers for the API
|
|
"""
|
|
import re
|
|
|
|
from jedi.evaluate import imports
|
|
|
|
|
|
def completion_parts(path_until_cursor):
|
|
"""
|
|
Returns the parts for the completion
|
|
:return: tuple - (path, dot, like)
|
|
"""
|
|
match = re.match(r'^(.*?)(\.|)(\w?[\w\d]*)$', path_until_cursor, flags=re.S)
|
|
return match.groups()
|
|
|
|
|
|
def sorted_definitions(defs):
|
|
# Note: `or ''` below is required because `module_path` could be
|
|
return sorted(defs, key=lambda x: (x.module_path or '', x.line or 0, x.column or 0))
|
|
|
|
|
|
def get_on_import_stmt(evaluator, user_context, user_stmt, is_like_search=False):
|
|
"""
|
|
Resolve the user statement, if it is an import. Only resolve the
|
|
parts until the user position.
|
|
"""
|
|
name = user_stmt.name_for_position(user_context.position)
|
|
if name is None:
|
|
raise NotImplementedError
|
|
|
|
i = imports.ImportWrapper(evaluator, name)
|
|
return i, name
|