mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-08 03:24:47 +08:00
Use relative paths when accessing a buffer
This commit is contained in:
@@ -4,12 +4,14 @@ The Python parts of the Jedi library for VIM. It is mostly about communicating
|
|||||||
with VIM.
|
with VIM.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
import traceback # for exception output
|
import traceback # for exception output
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from shlex import split as shsplit
|
from shlex import split as shsplit
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
from pathlib import Path
|
||||||
try:
|
try:
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -422,17 +424,15 @@ def _goto_specific_name(n, options=''):
|
|||||||
% (n.full_name or n.name))
|
% (n.full_name or n.name))
|
||||||
else:
|
else:
|
||||||
using_tagstack = int(vim_eval('g:jedi#use_tag_stack')) == 1
|
using_tagstack = int(vim_eval('g:jedi#use_tag_stack')) == 1
|
||||||
module_path = str(n.module_path or '')
|
result = set_buffer(n.module_path, options=options,
|
||||||
if module_path != vim.current.buffer.name:
|
|
||||||
result = new_buffer(module_path, options=options,
|
|
||||||
using_tagstack=using_tagstack)
|
using_tagstack=using_tagstack)
|
||||||
if not result:
|
if not result:
|
||||||
return []
|
return []
|
||||||
if (using_tagstack and module_path and
|
if (using_tagstack and n.module_path and
|
||||||
os.path.exists(module_path)):
|
n.module_path.exists()):
|
||||||
tagname = n.name
|
tagname = n.name
|
||||||
with tempfile('{0}\t{1}\t{2}'.format(
|
with tempfile('{0}\t{1}\t{2}'.format(
|
||||||
tagname, module_path, 'call cursor({0}, {1})'.format(
|
tagname, n.module_path, 'call cursor({0}, {1})'.format(
|
||||||
n.line, n.column + 1))) as f:
|
n.line, n.column + 1))) as f:
|
||||||
old_tags = vim.eval('&tags')
|
old_tags = vim.eval('&tags')
|
||||||
old_wildignore = vim.eval('&wildignore')
|
old_wildignore = vim.eval('&wildignore')
|
||||||
@@ -1050,13 +1050,9 @@ def do_rename(replace, orig=None):
|
|||||||
if r.in_builtin_module():
|
if r.in_builtin_module():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
module_path = r.module_path
|
result = set_buffer(r.module_path)
|
||||||
if os.path.abspath(vim.current.buffer.name) != str(module_path):
|
|
||||||
assert module_path is not None
|
|
||||||
result = new_buffer(module_path)
|
|
||||||
if not result:
|
if not result:
|
||||||
echo_highlight('Failed to create buffer window for %s!' % (
|
echo_highlight('Failed to create buffer window for %s!' % (r.module_path))
|
||||||
module_path))
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
buffers.add(vim.current.buffer.name)
|
buffers.add(vim.current.buffer.name)
|
||||||
@@ -1103,7 +1099,17 @@ def py_import_completions():
|
|||||||
|
|
||||||
|
|
||||||
@catch_and_print_exceptions
|
@catch_and_print_exceptions
|
||||||
def new_buffer(path, options='', using_tagstack=False):
|
def set_buffer(path: Optional[Path], options='', using_tagstack=False):
|
||||||
|
"""
|
||||||
|
Opens a new buffer if we have to or does nothing. Returns True in case of
|
||||||
|
success.
|
||||||
|
"""
|
||||||
|
path = str(path or '')
|
||||||
|
# Check both, because it might be an empty string
|
||||||
|
if path in (vim.current.buffer.name, os.path.abspath(vim.current.buffer.name)):
|
||||||
|
return True
|
||||||
|
|
||||||
|
path = os.path.relpath(path)
|
||||||
# options are what you can to edit the edit options
|
# options are what you can to edit the edit options
|
||||||
if int(vim_eval('g:jedi#use_tabs_not_buffers')) == 1:
|
if int(vim_eval('g:jedi#use_tabs_not_buffers')) == 1:
|
||||||
_tabnew(path, options)
|
_tabnew(path, options)
|
||||||
@@ -1151,7 +1157,6 @@ def _tabnew(path, options=''):
|
|||||||
|
|
||||||
:param options: `:tabnew` options, read vim help.
|
:param options: `:tabnew` options, read vim help.
|
||||||
"""
|
"""
|
||||||
path = os.path.abspath(path)
|
|
||||||
if int(vim_eval('has("gui")')) == 1:
|
if int(vim_eval('has("gui")')) == 1:
|
||||||
vim_command('tab drop %s %s' % (options, escape_file_path(path)))
|
vim_command('tab drop %s %s' % (options, escape_file_path(path)))
|
||||||
return
|
return
|
||||||
@@ -1166,7 +1171,7 @@ def _tabnew(path, options=''):
|
|||||||
# don't know why this happens :-)
|
# don't know why this happens :-)
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if buf_path == path:
|
if os.path.abspath(buf_path) == os.path.abspath(path):
|
||||||
# tab exists, just switch to that tab
|
# tab exists, just switch to that tab
|
||||||
vim_command('tabfirst | tabnext %i' % (tab_nr + 1))
|
vim_command('tabfirst | tabnext %i' % (tab_nr + 1))
|
||||||
# Goto the buffer's window.
|
# Goto the buffer's window.
|
||||||
|
|||||||
Reference in New Issue
Block a user