From 8e077adb2f319e7edfdd6ac260bf10b8ca60e277 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 8 Jul 2018 16:16:21 +0200 Subject: [PATCH] show_goto_multi_results: use relpath This helps Vim to display the path for unlisted buffers relative to cwd in the quickfix list. --- pythonx/jedi_vim.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index ca5e274..ccafc74 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -340,6 +340,14 @@ def goto(mode="goto"): return definitions +def relpath(path): + """Make path relative to cwd if it is below.""" + abspath = os.path.abspath(path) + if abspath.startswith(os.getcwd()): + return os.path.relpath(path) + return path + + def show_goto_multi_results(definitions): """Create a quickfix list for multiple definitions.""" lst = [] @@ -352,7 +360,8 @@ def show_goto_multi_results(definitions): 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), + filename = relpath(d.module_path) + lst.append(dict(filename=PythonToVimStr(filename), lnum=d.line, col=d.column + 1, text=PythonToVimStr(text))) vim_eval('setqflist(%s)' % repr(lst))