diff --git a/functions.py b/functions.py index ba4c73c1..8149ef25 100644 --- a/functions.py +++ b/functions.py @@ -70,25 +70,12 @@ class Definition(object): self.module_path = str(self.definition.get_parent_until().path) - def get_name(self): - try: - # is a func / class - return self.definition.name - except AttributeError: - try: - # is an array - return self.definition.type - except AttributeError: - # is a statement - return self.definition.get_code() - @property def module_name(self): path = self.module_path - try: - return path[path.rindex(os.path.sep) + 1:] - except ValueError: - return path + sep = os.path.sep + p = re.sub(r'^.*?([\w\d]+)(%s__init__)?.py$' % sep, r'\1', path) + return p def in_builtin_module(self): return not self.module_path.endswith('.py') @@ -109,16 +96,15 @@ class Definition(object): if isinstance(d, evaluate.parsing.Name): d = d.parent() - if isinstance(d, (evaluate.Class, evaluate.Instance)): + if isinstance(d, evaluate.Array): + d = 'class ' + d.type + elif isinstance(d, (evaluate.Class, evaluate.Instance)): d = 'class ' + str(d.name) elif isinstance(d, (evaluate.Function, evaluate.parsing.Function)): d = 'def ' + str(d.name) elif isinstance(d, evaluate.parsing.Module): - p = str(d.path) # only show module name - sep = os.path.sep - p = re.sub(r'^.*?([\w\d]+)(%s__init__)?.py$' % sep, r'\1', p) - d = 'module ' + p + d = 'module %s' % self.module_name else: d = d.get_code().replace('\n', '') return d @@ -130,14 +116,15 @@ class Definition(object): except AttributeError: return '' - - def __str__(self): - if self.module_path[0] == os.path.sep: + @property + def desc_with_module(self): + if self.module_path.endswith('.py') \ + and not isinstance(self.definition, parsing.Module): position = '@%s' % (self.line_nr) else: - # no path - is a builtin + # is a builtin or module position = '' - return "%s:%s%s" % (self.module_name, self.get_name(), position) + return "%s:%s%s" % (self.module_name, self.description, position) def __repr__(self): return "<%s %s>" % (self.__class__.__name__, self.definition) diff --git a/plugin/jedi.vim b/plugin/jedi.vim index 5371a04b..5d8692ab 100644 --- a/plugin/jedi.vim +++ b/plugin/jedi.vim @@ -109,7 +109,7 @@ if 1: vim.command('normal! K') vim.command('return') else: - docs = ['|Docstring for %s|\n%s' % (d, d.doc) if d.doc + docs = ['Docstring for %s\n%s\n%s' % (d.desc_with_module, '='*40, d.doc) if d.doc else '|No Docstring for %s|' % d for d in definitions] text = ('\n' + '-' * 79 + '\n').join(docs) vim.command('let l:doc = %s' % repr(PythonToVimStr(text))) @@ -130,6 +130,7 @@ PYTHONEOF silent normal! 1Gdd setlocal nomodifiable setlocal nomodified + setlocal filetype=rst if l:doc_lines > 20 " max 20 lines for plugin let l:doc_lines = 20 @@ -137,8 +138,8 @@ PYTHONEOF execute "resize ".l:doc_lines " TODO more highlightings - highlight jedi_doc ctermbg=green guibg=green - match jedi_doc /^|.*|\n/ + "highlight jedi_doc ctermbg=green guibg=green + "match jedi_doc /^|.*|\n/ endfunction " ------------------------------------------------------------------------ diff --git a/test/run.py b/test/run.py index 5bee2f55..0f56d76f 100755 --- a/test/run.py +++ b/test/run.py @@ -72,8 +72,8 @@ def run_definition_test(correct, source, line_nr, index, line, correct_start, if print_debug: functions.set_debug_function(debug.print_to_stdout) # because the objects have different ids, `repr` it, then compare it. - should_str = sorted(str(r) for r in should_be) - is_str = sorted(set(str(r) for r in result)) + should_str = set(r.desc_with_module for r in should_be) + is_str = set(r.desc_with_module for r in result) if is_str != should_str: print('Solution @%s not right, received %s, wanted %s' \ % (line_nr - 1, is_str, should_str))