def run(self, edit): cxt = op.edit_cxt_for[self.view] reg = op.edit_region_for[self.view] if cxt.adding_new: with op.quitting_edit_mode(self.view): self.view.erase(edit, end_plus_1(reg)) return body = op.module_body(self.view) entry = body.entry_under_edit() if entry.is_def_under_edit(): defn = comm.op('getDefinition', { 'module': op.view_module_name(self.view), 'name': entry.name() }) with op.quitting_edit_mode(self.view): self.view.replace(edit, reg, defn) elif entry.is_name_under_edit(): name = comm.op('getNameAt', { 'module': op.view_module_name(self.view), 'at': entry.myindex }) with op.quitting_edit_mode(self.view): self.view.replace(edit, reg, name) else: raise RuntimeError
def run(self, edit): remove = sublime.ok_cancel_dialog( "Remove module '{}'?".format(op.view_module_name(self.view)) ) if not remove: return res = comm.op('removeModule', { 'module': op.view_module_name(self.view), 'force': False }) if res is not True: remove = sublime.ok_cancel_dialog( "Module '{}' is connected with these modules: {}. Force removal?".format( op.view_module_name(self.view), ', '.join(res) ) ) if not remove: return res = comm.op('removeModule', { 'module': op.view_module_name(self.view), 'force': True }) if res is not True: sublime.error_message("Could not delete module, returned: {}".format(res)) return file_name = self.view.file_name() self.view.close() os.unlink(file_name)
def proceed(src_view, dest_view, other_views): with exc_recorded() as exc_src: call_with_edit(src_view, partial(process_source, src_view)) with exc_recorded() as exc_dest: call_with_edit(dest_view, partial(process_destination, dest_view)) exc_others = [exc_recorded() for view in other_views] for exc, view, module_data in zip(exc_others, other_views, res['modifiedModules']): with exc: call_with_edit(view, partial(process_other, view, module_data)) fmodules = { op.view_module_name(view) for exc, view in zip(exc_others, other_views) if exc } if exc_src: fmodules.add(op.view_module_name(src_view)) if exc_dest: fmodules.add(op.view_module_name(dest_view)) if fmodules: sublime.error_message( "The following modules failed to update (you may consider refreshing " "them from the image): {}".format(', '.join(fmodules))) if exc_src: print("Source updating failed:") traceback.print_exception(type(exc_src.exc), exc_src.exc, None) if exc_dest: print("Dest updating failed:") traceback.print_exception(type(exc_dest.exc), exc_dest.exc, None) for view, exc in zip(other_views, exc_others): if not exc: continue print("Modified module \"{}\" updating failed:".format( op.view_module_name(view))) traceback.print_exception(type(exc.exc), exc.exc, None) elif res['danglingRefs']: sublime.message_dialog( "These references appear to be dangling: {}".format( ','.join('$.' + r for r in res['danglingRefs']))) else: sublime.status_message("Move succeeded!")
def __init__(self, view, args, chain_tail): super().__init__(view, chain_tail) res = comm.op('getImportables', {'recp': op.view_module_name(view)}) self.items = [ ("{} ({})".format(entry or '*', module), [module, entry]) for module, entry in res ]
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, module_name): comm.op('renameModule', { 'module': op.view_module_name(self.view), 'newName': module_name }) new_file_name = op.module_filename(module_name, op.view_lang(self.view)) os.rename(self.view.file_name(), new_file_name) self.view.retarget(new_file_name)
def run(self, edit): loc = op.sel_cursor_location(self.view, require_fully_selected=True) run_command_thru_palette( self.view.window(), 'poli_move', { 'src_module_entry': [op.view_module_name(self.view), loc.entry.name()], })
def run(self, edit): if regedit.is_active_in(self.view): ok = sublime.ok_cancel_dialog("Unsaved changes would be lost. Continue?") if not ok: return op.terminate_edit_mode(self.view) comm.op('refreshModule', {'module': op.view_module_name(self.view)})
def run(self, edit, before): loc = op.sel_cursor_location(self.view, require_fully_selected=True) run_command_thru_palette( self.view.window(), 'poli_move', { 'dest_module': op.view_module_name(self.view), 'anchor': loc.entry.name(), 'before': before })
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, entry, alias): module_name, entry_name = entry comm.op('import', { 'recp': op.view_module_name(self.view), 'donor': module_name, 'name': entry_name, 'alias': alias, })
def run(self, edit, direction): body = op.module_body(self.view) loc = body.cursor_location_or_stop(single_selected_region(self.view), require_fully_selected=True) comm.op( 'moveBy1', { 'module': op.view_module_name(self.view), 'name': loc.entry.name(), 'direction': direction })
def run(self, edit): reg = single_selected_region(self.view) mtch = op.reference_at(self.view, reg) if mtch is None: star = None name = op.word_at(self.view, reg) else: star, name = mtch.group('star', 'name') res = comm.op('findReferences', { 'module': op.view_module_name(self.view), 'star': star, 'name': name }) if res is None: sublime.status_message("Unknown reference at point: \"{}\"".format( mtch.group())) return with active_view_preserved(self.view.window()): all_views = [ self.view.window().open_file(op.module_filename(module_name)) for module_name, entry_name in res ] def make_location(view, entry_defn_name, reg): row, col = view.rowcol(reg.begin()) return (view.file_name(), "{}.{}".format(op.view_module_name(view), entry_defn_name), (row + 1, col + 1)) def proceed(): locations = [] for view, (module_name, entry_name) in zip(all_views, res): # We also track to which definition occurences belong. We do this by # determining what is the key region with max index which is still fully # before the occurence region. regkeys = op.name_regions(view) k = 0 entry_defn_name = "(unknown)" regs = view.find_all(r'(?<![\w$])\$\.{}\b'.format(entry_name)) for reg in regs: while k < len(regkeys) and regkeys[k].end() < reg.begin(): k += 1 entry_defn_name = view.substr(regkeys[k - 1]) locations.append(make_location(view, entry_defn_name, reg)) navigate_to_symbol(sublime.active_window().active_view(), name, locations) on_all_views_load(all_views, proceed)
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 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 run(self, edit): edit_region = op.edit_region_for[self.view] cxt = op.edit_cxt_for[self.view] body = op.module_body(self.view) if cxt.adding_new: index = body.remove_ephemeral_entry() templ = op.RE_FULL_ENTRY[op.view_lang(self.view)] mtch = re.search(templ, self.view.substr(edit_region), re.DOTALL) if mtch is None: sublime.status_message("Invalid entry definition") return if mtch.group('def').isspace(): sublime.status_message("Empty definition not allowed") return comm.op( 'addEntry', { 'module': op.view_module_name(self.view), 'name': mtch.group('name'), 'def': mtch.group('def'), 'index': index }, committing_module_name=op.view_module_name(self.view) ) return entry = body.entry_under_edit() if entry.is_def_under_edit(): res = comm.op( 'editEntry', { 'module': op.view_module_name(self.view), 'name': entry.name(), 'newDef': self.view.substr(edit_region) }, committing_module_name=op.view_module_name(self.view) ) elif entry.is_name_under_edit(): comm.op( 'renameEntry', { 'module': op.view_module_name(self.view), 'index': entry.myindex, 'newName': self.view.substr(edit_region) }, committing_module_name=op.view_module_name(self.view) ) else: raise RuntimeError
def on_query_completions(self, prefix, locations): if not config.enabled: return None if len(locations) != 1: return None [pt] = locations linereg = self.view.line(pt) str_prec = self.view.substr(sublime.Region(linereg.begin(), pt)) mtch = re.search(r'^.*?\$(?:\.(?P<star>\w+))?\.(?P<prefix>\w+)$', str_prec) if mtch is None: return None entries = comm.op( 'getCompletions', { 'module': op.view_module_name(self.view), 'star': mtch.group('star'), 'prefix': mtch.group('prefix') }) return ([(x, x) for x in entries], sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
def make_location(view, entry_defn_name, reg): row, col = view.rowcol(reg.begin()) return (view.file_name(), "{}.{}".format(op.view_module_name(view), entry_defn_name), (row + 1, col + 1))
def __init__(self, view, args, chain_tail): module_name, entry = args['entry'] disallowed_names = comm.op('getModuleNames', { 'module': op.view_module_name(view) }) super().__init__(view, chain_tail, entry, disallowed_names)
def run(self, edit, donor_module): comm.op('convertImportsToStar', { 'recp': op.view_module_name(self.view), 'donor': donor_module })
def input(self, args): return NameInputHandler(op.view_module_name(self.view))
def run(self, edit): run_command_thru_palette( self.view.window(), 'poli_move', {'dest_module': op.view_module_name(self.view)})