diff --git a/after/syntax/python.vim b/after/syntax/python.vim index a5fdcd5..f6b595b 100644 --- a/after/syntax/python.vim +++ b/after/syntax/python.vim @@ -30,3 +30,5 @@ if g:jedi#show_call_signatures > 0 && has('conceal') hi def jediFat term=bold,underline cterm=bold,underline gui=bold,underline ctermbg=0 guibg=#555555 endif endif + +hi jediUsage term=NONE cterm=NONE ctermfg=None guifg=None gui=NONE ctermbg=3 guibg=Yellow diff --git a/autoload/jedi.vim b/autoload/jedi.vim index 0c7ae16..5659911 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -270,7 +270,16 @@ function! jedi#goto_definitions() abort endfunction function! jedi#usages() abort - PythonJedi jedi_vim.goto(mode="related_name") + call jedi#remove_usages() + PythonJedi jedi_vim.usages() +endfunction + +function! jedi#remove_usages() abort + for match in getmatches() + if stridx(match['group'], 'jediUsage') == 0 + call matchdelete(match['id']) + endif + endfor endfunction function! jedi#rename(...) abort diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index 067a444..8973757 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -286,15 +286,13 @@ def tempfile(content): @catch_and_print_exceptions def goto(mode="goto", no_output=False): """ - :param str mode: "related_name", "definition", "assignment", "auto" + :param str mode: "definition", "assignment", "goto" :return: list of definitions/assignments :rtype: list """ script = get_script() if mode == "goto": definitions = script.goto_assignments(follow_imports=True) - elif mode == "related_name": - definitions = script.usages() elif mode == "definition": definitions = script.goto_definitions() elif mode == "assignment": @@ -340,24 +338,47 @@ def goto(mode="goto", no_output=False): repr(PythonToVimStr(old_wildignore))) vim.current.window.cursor = d.line, d.column else: - # multiple solutions - lst = [] - for d in definitions: - if d.in_builtin_module(): - lst.append(dict(text=PythonToVimStr('Builtin ' + d.description))) - elif d.module_path is None: - # Typically a namespace, in the future maybe other things as - # well. - lst.append(dict(text=PythonToVimStr(d.description))) - else: - lst.append(dict(filename=PythonToVimStr(d.module_path), - lnum=d.line, col=d.column + 1, - text=PythonToVimStr(d.description))) - vim_eval('setqflist(%s)' % repr(lst)) - vim_eval('jedi#add_goto_window(' + str(len(lst)) + ')') + show_goto_multi_results() return definitions +def show_goto_multi_results(definitions): + """Create a quickfix list for multiple definitions.""" + lst = [] + for d in definitions: + if d.in_builtin_module(): + lst.append(dict(text=PythonToVimStr('Builtin ' + d.description))) + elif d.module_path is None: + # Typically a namespace, in the future maybe other things as + # well. + lst.append(dict(text=PythonToVimStr(d.description))) + else: + text = '[%s] %s' % (d.description, d.get_line_code().strip()) + lst.append(dict(filename=PythonToVimStr(d.module_path), + lnum=d.line, col=d.column + 1, + text=PythonToVimStr(text))) + vim_eval('setqflist(%s)' % repr(lst)) + vim_eval('jedi#add_goto_window(' + str(len(lst)) + ')') + + +@catch_and_print_exceptions +def usages(): + script = get_script() + definitions = script.usages() + if not definitions: + echo_highlight("No usages found here.") + return + for definition in definitions: + # Only color the current module/buffer. + if (definition.module_path or '') == vim.current.buffer.name: + # mathaddpos needs a list of positions where a position is a list + # of (line, column, length). + # The column starts with 1 and not 0. + positions = [[definition.line, definition.column + 1, len(definition.name)]] + vim_eval("matchaddpos('jediUsage', %s)" % repr(positions)) + + show_goto_multi_results(definitions) + @_check_jedi_availability(show_error=True) @catch_and_print_exceptions def show_documentation():