MCPcopy
hub / github.com/davidhalter/jedi-vim / do_rename

Function do_rename

pythonx/jedi_vim.py:1064–1110  ·  view source on GitHub ↗
(replace, orig=None)

Source from the content-addressed store, hash-verified

1062
1063
1064def do_rename(replace, orig=None):
1065 if not len(replace):
1066 echo_highlight('No rename possible without name.')
1067 return
1068
1069 if orig is None:
1070 orig = vim_eval('s:jedi_replace_orig')
1071
1072 if orig == replace:
1073 echo_highlight('Jedi did 0 renames.')
1074 return
1075
1076 # Save original window / tab.
1077 saved_tab = int(vim_eval('tabpagenr()'))
1078 saved_win = int(vim_eval('winnr()'))
1079
1080 temp_rename = usages(visuals=False)
1081 # Sort the whole thing reverse (positions at the end of the line
1082 # must be first, because they move the stuff before the position).
1083 temp_rename = sorted(temp_rename, reverse=True,
1084 key=lambda x: (str(x.module_path), x.line, x.column))
1085 buffers = set()
1086 for r in temp_rename:
1087 if r.in_builtin_module():
1088 continue
1089
1090 result = set_buffer(r.module_path)
1091 if not result:
1092 echo_highlight('Failed to create buffer window for %s!' % (r.module_path))
1093 continue
1094
1095 buffers.add(vim.current.buffer.name)
1096
1097 # Replace original word.
1098 r_line = vim.current.buffer[r.line - 1]
1099 vim.current.buffer[r.line - 1] = (r_line[:r.column] + replace +
1100 r_line[r.column + len(orig):])
1101
1102 # Restore previous tab and window.
1103 vim_command('tabnext {0:d}'.format(saved_tab))
1104 vim_command('{0:d}wincmd w'.format(saved_win))
1105
1106 if len(buffers) > 1:
1107 echo_highlight('Jedi did {0:d} renames in {1:d} buffers!'.format(
1108 len(temp_rename), len(buffers)))
1109 else:
1110 echo_highlight('Jedi did {0:d} renames!'.format(len(temp_rename)))
1111
1112
1113@_check_jedi_availability(show_error=True)

Callers 2

renameFunction · 0.85
rename_visualFunction · 0.85

Calls 5

echo_highlightFunction · 0.85
vim_evalFunction · 0.85
usagesFunction · 0.85
set_bufferFunction · 0.85
vim_commandFunction · 0.85

Tested by

no test coverage detected