本文整理匯總了Python中jedi.Interpreter方法的典型用法代碼示例。如果您正苦於以下問題:Python jedi.Interpreter方法的具體用法?Python jedi.Interpreter怎麽用?Python jedi.Interpreter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jedi
的用法示例。
在下文中一共展示了jedi.Interpreter方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_completions
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Interpreter [as 別名]
def get_completions(code, cursor=None, namespaces=None):
"""
Get code autocompletion candidates.
"""
import jedi
import __main__
if namespaces is None:
namespaces = [__main__.__dict__]
if cursor is None:
cursor = len(code)
code = code[:cursor]
interp = jedi.Interpreter(source=code, namespaces=namespaces)
completions = interp.completions()
return [x.name for x in completions]
示例2: _cmd_shell_autocomplete
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Interpreter [as 別名]
def _cmd_shell_autocomplete(self, cmd):
error = None
try:
import jedi
except ImportError:
completions = []
error = "Could not import jedi"
else:
try:
# with warnings.catch_warnings():
interpreter = jedi.Interpreter(cmd.source, [__main__.__dict__])
completions = self._export_completions(interpreter.completions())
except Exception as e:
completions = []
error = "Autocomplete error: " + str(e)
return InlineResponse(
"shell_autocomplete", source=cmd.source, completions=completions, error=error
)
示例3: get_completions
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Interpreter [as 別名]
def get_completions(self, line):
"""Get completions. Used by the ``autocomplete`` extension."""
script = jedi.Interpreter(line, [self.interpreter.locals])
return [comp.name for comp in script.completions()]
示例4: get_completions
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Interpreter [as 別名]
def get_completions(self, info):
'''Get Python completions'''
# https://github.com/davidhalter/jedi/blob/master/jedi/utils.py
if jedi is None:
return []
text = info['code']
position = (info['line_num'], info['column'])
interpreter = Interpreter(text, [self.env])
if jedi.__version__ >= LooseVersion('0.12.0'):
lines = split_lines(text)
name = get_on_completion_name(
interpreter._module_node,
lines,
position
)
before = text[:len(text) - len(name)]
elif jedi.__version__ >= LooseVersion('0.10.0'):
lines = split_lines(text)
name = get_on_completion_name(
interpreter._get_module_node(),
lines,
position
)
before = text[:len(text) - len(name)]
else:
path = UserContext(text, position).get_path_until_cursor()
path, dot, like = completion_parts(path)
before = text[:len(text) - len(like)]
completions = interpreter.completions()
completions = [before + c.name_with_symbols for c in completions]
self.kernel.log.error(completions)
return [c[info['start']:] for c in completions]