|
9 | 9 |
|
10 | 10 |
|
11 | 11 | @hookimpl
|
12 |
| -def pylsp_rename(config, workspace, document, position, new_name): # pylint: disable=unused-argument,too-many-locals |
13 |
| - with workspace.report_progress("rename", percentage=0) as report_progress: |
14 |
| - log.debug('Executing rename of %s to %s', document.word_at_position(position), new_name) |
15 |
| - kwargs = _utils.position_to_jedi_linecolumn(document, position) |
16 |
| - kwargs['new_name'] = new_name |
17 |
| - report_progress("refactoring") |
18 |
| - try: |
19 |
| - refactoring = document.jedi_script().rename(**kwargs) |
20 |
| - except NotImplementedError as exc: |
21 |
| - raise Exception('No support for renaming in Python 2/3.5 with Jedi. ' |
22 |
| - 'Consider using the rope_rename plugin instead') from exc |
23 |
| - log.debug('Finished rename: %s', refactoring.get_diff()) |
24 |
| - changes = [] |
25 |
| - |
26 |
| - changed_files = refactoring.get_changed_files() |
27 |
| - for n, (file_path, changed_file) in enumerate(changed_files.items()): |
28 |
| - report_progress(changed_file, percentage=n/len(changed_files)*100) |
29 |
| - uri = uris.from_fs_path(str(file_path)) |
30 |
| - doc = workspace.get_maybe_document(uri) |
31 |
| - changes.append({ |
32 |
| - 'textDocument': { |
33 |
| - 'uri': uri, |
34 |
| - 'version': doc.version if doc else None |
35 |
| - }, |
36 |
| - 'edits': [ |
37 |
| - { |
38 |
| - 'range': { |
39 |
| - 'start': {'line': 0, 'character': 0}, |
40 |
| - 'end': { |
41 |
| - 'line': _num_lines(changed_file.get_new_code()), |
42 |
| - 'character': 0, |
43 |
| - }, |
| 12 | +def pylsp_rename(config, workspace, document, position, new_name): # pylint: disable=unused-argument |
| 13 | + log.debug('Executing rename of %s to %s', document.word_at_position(position), new_name) |
| 14 | + kwargs = _utils.position_to_jedi_linecolumn(document, position) |
| 15 | + kwargs['new_name'] = new_name |
| 16 | + try: |
| 17 | + refactoring = document.jedi_script().rename(**kwargs) |
| 18 | + except NotImplementedError as exc: |
| 19 | + # pylint: disable=broad-exception-raised |
| 20 | + raise Exception('No support for renaming in Python 2/3.5 with Jedi. ' |
| 21 | + 'Consider using the rope_rename plugin instead') from exc |
| 22 | + log.debug('Finished rename: %s', refactoring.get_diff()) |
| 23 | + changes = [] |
| 24 | + |
| 25 | + changed_files = refactoring.get_changed_files() |
| 26 | + for file_path, changed_file in changed_files.items(): |
| 27 | + uri = uris.from_fs_path(str(file_path)) |
| 28 | + doc = workspace.get_maybe_document(uri) |
| 29 | + changes.append({ |
| 30 | + 'textDocument': { |
| 31 | + 'uri': uri, |
| 32 | + 'version': doc.version if doc else None |
| 33 | + }, |
| 34 | + 'edits': [ |
| 35 | + { |
| 36 | + 'range': { |
| 37 | + 'start': {'line': 0, 'character': 0}, |
| 38 | + 'end': { |
| 39 | + 'line': _num_lines(changed_file.get_new_code()), |
| 40 | + 'character': 0, |
44 | 41 | },
|
45 |
| - 'newText': changed_file.get_new_code(), |
46 |
| - } |
47 |
| - ], |
48 |
| - }) |
49 |
| - return {'documentChanges': changes} |
| 42 | + }, |
| 43 | + 'newText': changed_file.get_new_code(), |
| 44 | + } |
| 45 | + ], |
| 46 | + }) |
| 47 | + return {'documentChanges': changes} |
50 | 48 |
|
51 | 49 |
|
52 | 50 | def _num_lines(file_contents):
|
|
0 commit comments