本文整理匯總了Python中jedi.Script方法的典型用法代碼示例。如果您正苦於以下問題:Python jedi.Script方法的具體用法?Python jedi.Script怎麽用?Python jedi.Script使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jedi
的用法示例。
在下文中一共展示了jedi.Script方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_completions
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def _get_completions(source, func, line=None, column=None):
try:
num_lines = len(source.split('\n'))
if line is None:
line = num_lines
s = Script(source, line=line, column=column)
completions = s.completions()
# print('### input:')
# print(source)
# print('### completions:')
# print('\n'.join([c.name for c in completions]))
except:
print('Exception in completions thread')
traceback.print_exc()
completions = []
mainthread(WrappablePartial(func, [c for c in completions]))()
示例2: _get_defs
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def _get_defs(source, func, line=None, column=None):
error = None
try:
num_lines = len(source.split('\n'))
if line is None:
line = num_lines
s = Script(source, line=line, column=column)
defs = s.goto_definitions()
sigs = s.call_signatures()
except:
print('Exception in defs thread')
traceback.print_exc()
defs = []
sigs = []
error = 'Could not retrieve docstring'
mainthread(WrappablePartial(func, defs, sigs, error=error))()
示例3: goto_assignments
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def goto_assignments(request_data):
"""
Go to assignements worker.
"""
code = request_data['code']
line = request_data['line'] + 1
column = request_data['column']
path = request_data['path']
# encoding = request_data['encoding']
encoding = 'utf-8'
script = jedi.Script(code, line, column, path, encoding)
try:
definitions = script.goto_assignments()
except jedi.NotFoundError:
pass
else:
ret_val = [(d.module_path, d.line - 1 if d.line else None,
d.column, d.full_name)
for d in definitions]
return ret_val
示例4: quick_doc
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def quick_doc(request_data):
"""
Worker that returns the documentation of the symbol under cursor.
"""
code = request_data['code']
line = request_data['line'] + 1
column = request_data['column']
path = request_data['path']
# encoding = 'utf-8'
encoding = 'utf-8'
script = jedi.Script(code, line, column, path, encoding)
try:
definitions = script.goto_definitions()
except jedi.NotFoundError:
return []
else:
ret_val = [d.doc for d in definitions]
return ret_val
示例5: complete
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def complete(code, line, column, path, encoding, prefix):
"""
Completes python code using `jedi`_.
:returns: a list of completion.
"""
ret_val = []
try:
script = jedi.Script(code, line + 1, column, path, encoding)
completions = script.completions()
print('completions: %r' % completions)
except jedi.NotFoundError:
completions = []
for completion in completions:
ret_val.append({
'name': completion.name,
'icon': icon_from_typename(
completion.name, completion.type),
'tooltip': completion.description})
return ret_val
示例6: goto_definition
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def goto_definition(event):
if not control_is_pressed(event.state):
return
assert isinstance(event.widget, tk.Text)
text = event.widget
source = text.get("1.0", "end")
index = text.index("insert")
index_parts = index.split(".")
line, column = int(index_parts[0]), int(index_parts[1])
# TODO: find current editor filename
from jedi import Script
script = Script(source, line=line, column=column, path="")
defs = script.goto_definitions()
if len(defs) > 0:
module_path = defs[0].module_path
module_name = defs[0].module_name
line = defs[0].line
if module_path and line is not None:
get_workbench().get_editor_notebook().show_file(module_path, line)
elif module_name == "" and line is not None: # current editor
get_workbench().get_editor_notebook().get_current_editor().select_range(line)
示例7: finddocstring
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def finddocstring(self):
''' find the docstring at current cursor location
'''
import StringIO
from jedi import Script
i=editor.get_selection()
t=editor.get_text()
(line,txt)=[(line,n) for (line,n) in enumerate(StringIO.StringIO(editor.get_text()[:i[1]]))][-1]
script = Script(t, line+1, len(txt))
dfn = script.goto_definitions()
if dfn:
doc=dfn[0].doc
import ui
v=ui.TextView()
v.width=100
v.height=50
v.text=doc
editor._set_toolbar(v)
示例8: getJediScript
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def getJediScript(code, srcPath):
"""Provides the jedi Script object considering the current project"""
if not os.path.isabs(srcPath):
# Pretend it is in the user home dir
srcPath = os.path.realpath(QDir.homePath()) + os.path.sep + srcPath
return jedi.Script(code=code, path=srcPath, project=getJediProject())
示例9: __init__
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def __init__(self, area, *args, **kwargs):
source = area.get('1.0', 'end')
line, col = area.indexref()
script = Script(source, line, col, area.filename)
completions = script.completions()
CompletionWindow.__init__(self, area, completions, *args, **kwargs)
示例10: parseText
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def parseText(self):
if self.completer:
text = self.toPlainText()
self.moveCompleter()
if text:
tc = self.textCursor()
context_completer = False
pos = tc.position()
if managers.context in managers.contextCompleters:
line = text[:pos].split('\n')[-1]
comp, extra = managers.contextCompleters[managers.context ](line)
if comp or extra:
context_completer = True
self.completer.updateCompleteList(comp, extra)
if not context_completer:
if re.match('[a-zA-Z0-9.]', text[pos-1]):
offs = 0
if managers.context in managers.autoImport:
autoImp = managers.autoImport.get(managers.context, '')
text = autoImp + text
offs = len(autoImp.split('\n'))-1
bl = tc.blockNumber() + 1 + offs
col = tc.columnNumber()
script = jedi.Script(text, bl, col, '')
try:
# curframe = inspect.currentframe()
# print inspect.getouterframes(curframe, 2)[1][3]
self.completer.updateCompleteList(script.completions())
except:
self.completer.updateCompleteList()
return
else:
self.completer.updateCompleteList()
else:
self.completer.updateCompleteList()
示例11: _get_jedi_script
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def _get_jedi_script(request_data):
return jedi.Script(request_data['source'],
request_data['line'],
request_data['col'],
request_data['source_path'])
示例12: calltips
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def calltips(request_data):
"""
Worker that returns a list of calltips.
A calltips is a tuple made of the following parts:
- module_name: name of the module of the function invoked
- call_name: name of the function that is being called
- params: the list of parameter names.
- index: index of the current parameter
- bracket_start
:returns tuple(module_name, call_name, params)
"""
code = request_data['code']
line = request_data['line'] + 1
column = request_data['column']
path = request_data['path']
# encoding = request_data['encoding']
encoding = 'utf-8'
# use jedi to get call signatures
script = jedi.Script(code, line, column, path, encoding)
signatures = script.call_signatures()
for sig in signatures:
results = (str(sig.module_name), str(sig.name),
[p.description for p in sig.params], sig.index,
sig.bracket_start, column)
# todo: add support for multiple signatures, for that we need a custom
# widget for showing calltips.
return results
return []
示例13: _start_linter
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def _start_linter():
"""
This is a pre-alpha API. You're not supposed to use it at all, except for
testing. It will very likely change.
"""
import jedi
if '--debug' in sys.argv:
jedi.set_debug_function()
for path in sys.argv[2:]:
if path.startswith('--'):
continue
if isdir(path):
import fnmatch
import os
paths = []
for root, dirnames, filenames in os.walk(path):
for filename in fnmatch.filter(filenames, '*.py'):
paths.append(os.path.join(root, filename))
else:
paths = [path]
try:
for path in paths:
for error in jedi.Script(path=path)._analysis():
print(error)
except Exception:
if '--pdb' in sys.argv:
import traceback
traceback.print_exc()
import pdb
pdb.post_mortem()
else:
raise
示例14: parse_source
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def parse_source(source):
try:
import parso
return parso.parse(source)
except ImportError:
import jedi
script = jedi.Script(source)
return get_module_node(script)
示例15: _cmd_editor_autocomplete
# 需要導入模塊: import jedi [as 別名]
# 或者: from jedi import Script [as 別名]
def _cmd_editor_autocomplete(self, cmd):
error = None
try:
import jedi
self._debug(jedi.__file__, sys.path)
with warnings.catch_warnings():
script = jedi.Script(cmd.source, cmd.row, cmd.column, cmd.filename)
completions = self._export_completions(script.completions())
except ImportError:
completions = []
error = "Could not import jedi"
except Exception as e:
completions = []
error = "Autocomplete error: " + str(e)
return InlineResponse(
"editor_autocomplete",
source=cmd.source,
row=cmd.row,
column=cmd.column,
filename=cmd.filename,
completions=completions,
error=error,
)