From 1f7bc2a0fb9f0a455c0658a6b29463206317c47c Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 29 Jan 2020 19:20:12 +0100 Subject: [PATCH 1/2] Fix "goto" with multiple results E.g. with `os.path`. --- pythonx/jedi_vim.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index a7f7c7e..1e7bf74 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -434,6 +434,8 @@ def show_goto_multi_results(definitions, mode): """Create (or reuse) a quickfix list for multiple definitions.""" global _current_definitions + for_usages = mode == "usages" + lst = [] (row, col) = vim.current.window.cursor current_idx = None @@ -450,9 +452,10 @@ def show_goto_multi_results(definitions, mode): text=PythonToVimStr(text))) # Select current/nearest entry via :cc later. + # Only done for "usages", but current_def is also used for "goto". if d.line == row and d.column <= col: if (current_idx is None - or (abs(lst[current_idx].column - col) + or (abs(lst[current_idx]["col"] - col) > abs(d.column - col))): current_idx = len(lst) current_def = d @@ -472,10 +475,10 @@ def show_goto_multi_results(definitions, mode): VimCompat.setqflist_title(qf_title) else: VimCompat.setqflist(lst, title=qf_title, context=qf_context) - for_usages = mode == "usages" vim_eval('jedi#add_goto_window(%d, %d)' % (for_usages, len(lst))) - vim_command('%dcc' % select_entry) + if for_usages: + vim_command('%dcc' % select_entry) def _same_definitions(a, b): From b689409a2a4bcf3b973ae20331fb26cb24d24d96 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 2 Feb 2020 07:20:41 +0100 Subject: [PATCH 2/2] Do not use :cc, but only select the line in the qf window Ref: https://github.com/davidhalter/jedi-vim/pull/990#issuecomment-580163737 --- pythonx/jedi_vim.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index 1e7bf74..d60219d 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -434,8 +434,6 @@ def show_goto_multi_results(definitions, mode): """Create (or reuse) a quickfix list for multiple definitions.""" global _current_definitions - for_usages = mode == "usages" - lst = [] (row, col) = vim.current.window.cursor current_idx = None @@ -452,7 +450,6 @@ def show_goto_multi_results(definitions, mode): text=PythonToVimStr(text))) # Select current/nearest entry via :cc later. - # Only done for "usages", but current_def is also used for "goto". if d.line == row and d.column <= col: if (current_idx is None or (abs(lst[current_idx]["col"] - col) @@ -475,10 +472,10 @@ def show_goto_multi_results(definitions, mode): VimCompat.setqflist_title(qf_title) else: VimCompat.setqflist(lst, title=qf_title, context=qf_context) + for_usages = mode == "usages" vim_eval('jedi#add_goto_window(%d, %d)' % (for_usages, len(lst))) - if for_usages: - vim_command('%dcc' % select_entry) + vim_command('%d' % select_entry) def _same_definitions(a, b):