def run(self, edit, imported_as, new_alias): data = comm.op('renameImport', { 'module': op.view_module_name(self.view), 'importedAs': imported_as, 'newAlias': new_alias }) op.modify_module(self.view, edit, data) op.save_module(self.view)
def run(self, edit, name, new_name): res = comm.op( 'replaceUsages', { 'module': op.view_module_name(self.view), 'name': name, 'newName': new_name }) op.modify_module(self.view, edit, res) op.save_module(self.view)
def run(self, edit): res = comm.op('removeUnusedImports', { 'module': op.view_module_name(self.view) }) new_import_section = res['importSection'] removed_count = res['removedCount'] if removed_count > 0: op.replace_import_section(self.view, edit, new_import_section) op.save_module(self.view) sublime.status_message("Removed {} unused imports".format(removed_count)) else: sublime.status_message("There are no unused imports in this module")
def process_destination(view, edit): with regedit.region_editing_suppressed(view): if anchor is None: insert_at = op.reg_body(view).begin() else: mcont = op.module_body(view) if anchor is False: insert_at = mcont.entries[0].reg_entry_nl.begin() elif anchor is True: insert_at = mcont.entries[-1].reg_entry_nl.end() else: entry_obj = op.module_body(view).entry_by_name(anchor) if before: insert_at = entry_obj.reg_entry_nl.begin() else: insert_at = entry_obj.reg_entry_nl.end() view.insert(edit, insert_at, '{} ::= {}\n'.format(entry, res['newCode'])) op.save_module(view)
def run(self, edit): reg = single_selected_region(self.view) if op.reg_import_section(self.view).contains(reg): self.view.run_command('poli_remove_this_import', { 'force': False }) return loc = op.module_body(self.view).cursor_location_or_stop( reg, require_fully_selected=True ) res = comm.op('removeEntry', { 'module': op.view_module_name(self.view), 'entry': loc.entry.name(), 'force': False }) if not res['removed']: remove_anyway = sublime.ok_cancel_dialog( "Entry \"{}\" is being referred to. Remove it anyway?".format( loc.entry.name() ) ) if not remove_anyway: return res = comm.op('removeEntry', { 'module': op.view_module_name(self.view), 'entry': loc.entry.name(), 'force': True }) if not res['removed']: raise RuntimeError with read_only_set_to(self.view, False): self.view.erase(edit, loc.entry.reg_entry_nl) op.save_module(self.view)
def run(self, edit, imported_as, force): res = comm.op('removeImport', { 'module': op.view_module_name(self.view), 'importedAs': imported_as, 'force': force }) if not res['removed']: assert not force # otherwise it would have removed the import remove_anyway = sublime.ok_cancel_dialog( "The import \"{}\" is being used. Remove it anyway?".format(imported_as), "Remove" ) if not remove_anyway: return res = comm.op('removeImport', { 'module': op.view_module_name(self.view), 'importedAs': imported_as, 'force': True }) op.replace_import_section(self.view, edit, res['importSection']) op.save_module(self.view)
def process_other(view, module_data, edit): op.modify_module(view, edit, module_data) op.save_module(view)
def process_source(view, edit): with regedit.region_editing_suppressed(view): entry_obj = op.module_body(view).entry_by_name(entry) view.erase(edit, entry_obj.reg_entry_nl) op.save_module(view)