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)
|
f = open(path)
|
||||||
code = f.read()
|
code = f.read()
|
||||||
for i in range(1):
|
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)
|
#completions = functions.complete(code, 42, 200, path)
|
||||||
|
|
||||||
print '\n', ', '.join(sorted(str(c) for c in completions))
|
print '\n', ', '.join(sorted(str(c) for c in completions))
|
||||||
|
|||||||
20
functions.py
20
functions.py
@@ -82,7 +82,12 @@ class Definition(object):
|
|||||||
par = par.parent
|
par = par.parent
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
return par.path
|
|
||||||
|
path = str(par.path)
|
||||||
|
try:
|
||||||
|
return path[path.rindex('/')+1:]
|
||||||
|
except ValueError:
|
||||||
|
return path
|
||||||
|
|
||||||
def get_line(self):
|
def get_line(self):
|
||||||
return self.scope.line_nr
|
return self.scope.line_nr
|
||||||
@@ -97,8 +102,7 @@ class Definition(object):
|
|||||||
else:
|
else:
|
||||||
# no path - is a builtin
|
# no path - is a builtin
|
||||||
position = ''
|
position = ''
|
||||||
|
return "%s:%s%s" % (module, self.get_name(), position)
|
||||||
return "%s.%s%s" % (module, self.get_name(), position)
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s %s>" % (self.__class__.__name__, self)
|
return "<%s %s>" % (self.__class__.__name__, self)
|
||||||
@@ -177,10 +181,16 @@ def prepare_goto(source, row, column, source_path, is_like_search):
|
|||||||
try:
|
try:
|
||||||
stmt = r.top.statements[0]
|
stmt = r.top.statements[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
path_tuple = path, dot, like
|
if is_like_search:
|
||||||
|
path_tuple = path, dot, like
|
||||||
|
else:
|
||||||
|
path_tuple = ()
|
||||||
raise NotFoundError(scope, path_tuple)
|
raise NotFoundError(scope, path_tuple)
|
||||||
else:
|
else:
|
||||||
stmt.line_nr = row
|
if is_like_search:
|
||||||
|
stmt.line_nr = row
|
||||||
|
else:
|
||||||
|
stmt.line_nr = row+1
|
||||||
stmt.indent = column
|
stmt.indent = column
|
||||||
stmt.parent = scope
|
stmt.parent = scope
|
||||||
scopes = evaluate.follow_statement(stmt, scope=scope)
|
scopes = evaluate.follow_statement(stmt, scope=scope)
|
||||||
|
|||||||
@@ -177,4 +177,5 @@ def nexti(iterator, default=list):
|
|||||||
|
|
||||||
#exe[0].
|
#exe[0].
|
||||||
#exe[4]['d']
|
#exe[4]['d']
|
||||||
next(gen_exe).
|
a = next(gen_exe)
|
||||||
|
a
|
||||||
|
|||||||
@@ -51,6 +51,34 @@ PYTHONEOF
|
|||||||
endfunction
|
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
|
" Initialization of Jedi
|
||||||
" ------------------------------------------------------------------------
|
" ------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user