diff --git a/ftest.py b/ftest.py index 49766318..4a3b9cd6 100755 --- a/ftest.py +++ b/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)) diff --git a/functions.py b/functions.py index e2dff185..8a726427 100644 --- a/functions.py +++ b/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: - path_tuple = path, dot, like + if is_like_search: + path_tuple = path, dot, like + else: + path_tuple = () raise NotFoundError(scope, path_tuple) else: - stmt.line_nr = row + 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) diff --git a/parsetest.py b/parsetest.py index dbd5d8a0..2405de1b 100644 --- a/parsetest.py +++ b/parsetest.py @@ -177,4 +177,5 @@ def nexti(iterator, default=list): #exe[0]. #exe[4]['d'] -next(gen_exe). +a = next(gen_exe) +a diff --git a/plugin/jedi.vim b/plugin/jedi.vim index 9e420465..8b77c55e 100644 --- a/plugin/jedi.vim +++ b/plugin/jedi.vim @@ -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 " ------------------------------------------------------------------------