forked from VimPlug/jedi
show_definition added to vim interface
This commit is contained in:
3
ftest.py
3
ftest.py
@@ -15,7 +15,8 @@ path = os.path.join(os.getcwd(), f_name)
|
||||
f = open(path)
|
||||
code = f.read()
|
||||
for i in range(1):
|
||||
completions = functions.get_definitions(code, 180, 200, path)
|
||||
completions = functions.complete(code, 180, 200, path)
|
||||
#completions = functions.get_definitions(code, 181, 2, path)
|
||||
#completions = functions.complete(code, 42, 200, path)
|
||||
|
||||
print '\n', ', '.join(sorted(str(c) for c in completions))
|
||||
|
||||
16
functions.py
16
functions.py
@@ -82,7 +82,12 @@ class Definition(object):
|
||||
par = par.parent
|
||||
else:
|
||||
break
|
||||
return par.path
|
||||
|
||||
path = str(par.path)
|
||||
try:
|
||||
return path[path.rindex('/')+1:]
|
||||
except ValueError:
|
||||
return path
|
||||
|
||||
def get_line(self):
|
||||
return self.scope.line_nr
|
||||
@@ -97,8 +102,7 @@ class Definition(object):
|
||||
else:
|
||||
# no path - is a builtin
|
||||
position = ''
|
||||
|
||||
return "%s.%s%s" % (module, self.get_name(), position)
|
||||
return "%s:%s%s" % (module, self.get_name(), position)
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s %s>" % (self.__class__.__name__, self)
|
||||
@@ -177,10 +181,16 @@ def prepare_goto(source, row, column, source_path, is_like_search):
|
||||
try:
|
||||
stmt = r.top.statements[0]
|
||||
except IndexError:
|
||||
if is_like_search:
|
||||
path_tuple = path, dot, like
|
||||
else:
|
||||
path_tuple = ()
|
||||
raise NotFoundError(scope, path_tuple)
|
||||
else:
|
||||
if is_like_search:
|
||||
stmt.line_nr = row
|
||||
else:
|
||||
stmt.line_nr = row+1
|
||||
stmt.indent = column
|
||||
stmt.parent = scope
|
||||
scopes = evaluate.follow_statement(stmt, scope=scope)
|
||||
|
||||
@@ -177,4 +177,5 @@ def nexti(iterator, default=list):
|
||||
|
||||
#exe[0].
|
||||
#exe[4]['d']
|
||||
next(gen_exe).
|
||||
a = next(gen_exe)
|
||||
a
|
||||
|
||||
@@ -51,6 +51,34 @@ PYTHONEOF
|
||||
endfunction
|
||||
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" get_definition
|
||||
" ------------------------------------------------------------------------
|
||||
"
|
||||
function! jedi#show_definition()
|
||||
python << PYTHONEOF
|
||||
if 1:
|
||||
row, column = vim.current.window.cursor
|
||||
buf_path = vim.current.buffer.name
|
||||
source = '\n'.join(vim.current.buffer)
|
||||
try:
|
||||
definitions = functions.get_definitions(source, row, column, buf_path)
|
||||
except functions.NotFoundError:
|
||||
msg = 'There is no useful expression under the cursor'
|
||||
except Exception:
|
||||
# print to stdout, will be in :messages
|
||||
print(traceback.format_exc())
|
||||
msg = "Some different eror, this shouldn't happen"
|
||||
else:
|
||||
msg = ', '.join(sorted(str(d) for d in definitions))
|
||||
if not msg:
|
||||
msg = "No definitions found!"
|
||||
vim.command('''echomsg "%s"''' % msg)
|
||||
|
||||
#print 'end', strout
|
||||
PYTHONEOF
|
||||
endfunction
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" Initialization of Jedi
|
||||
" ------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user