|
5 | 5 |
|
6 | 6 |
|
7 | 7 | class TypescriptRenameCommand(TypeScriptBaseTextCommand): |
8 | | - """Rename command""" |
| 8 | + """ |
| 9 | + Command to rename identifier |
| 10 | + """ |
9 | 11 | def run(self, text): |
10 | 12 | check_update_view(self.view) |
| 13 | + |
11 | 14 | rename_response = cli.service.rename(self.view.file_name(), get_location_from_view(self.view)) |
12 | | - if rename_response["success"]: |
13 | | - info_locations = rename_response["body"] |
14 | | - # Todo: handle error when the symbol cannot be renamed (with 'localizedErrorMessage' property) |
15 | | - log.debug(info_locations["info"]) |
16 | | - display_name = info_locations["info"]["fullDisplayName"] |
17 | | - outer_locations = info_locations["locs"] |
| 15 | + if not rename_response['success']: |
| 16 | + return |
18 | 17 |
|
19 | | - def on_cancel(): |
20 | | - return |
| 18 | + body = rename_response['body'] |
21 | 19 |
|
22 | | - def on_done(new_name): |
23 | | - args = {"newName": new_name, "outerLocs": outer_locations} |
24 | | - args_json_str = json_helpers.encode(args) |
25 | | - self.view.run_command('typescript_finish_rename', {"args_json": args_json_str}) |
| 20 | + info = body['info'] |
| 21 | + if not info['canRename']: |
| 22 | + self.view.set_status('typescript_error', info['localizedErrorMessage']) |
| 23 | + return |
26 | 24 |
|
27 | | - if len(outer_locations) > 0: |
28 | | - sublime.active_window().show_input_panel( |
29 | | - "New name for {0}: ".format(display_name), |
30 | | - info_locations["info"]["displayName"], |
31 | | - on_done, None, on_cancel |
32 | | - ) |
| 25 | + display_name = info['fullDisplayName'] |
| 26 | + outer_locations = body['locs'] |
| 27 | + |
| 28 | + def on_done(new_name): |
| 29 | + args = {'newName': new_name, 'outerLocs': outer_locations} |
| 30 | + args_json_str = json_helpers.encode(args) |
| 31 | + self.view.run_command('typescript_finish_rename', {'args_json': args_json_str}) |
| 32 | + |
| 33 | + if len(outer_locations) > 0: |
| 34 | + sublime.active_window().show_input_panel( |
| 35 | + 'New name for {0}: '.format(display_name), |
| 36 | + info['displayName'], # initial text |
| 37 | + on_done, |
| 38 | + None, # on_change |
| 39 | + None # on_cancel |
| 40 | + ) |
33 | 41 |
|
34 | 42 |
|
35 | 43 | class TypescriptFinishRenameCommand(TypeScriptBaseTextCommand): |
|
0 commit comments