Beispiel #1
0
    def run(self, edit):
        reg = single_selected_region(self.view)
        rec = op.parse_import_section(self.view).record_at_or_stop(reg)

        run_command_thru_palette(self.view.window(), 'poli_rename_import', {
            'imported_as': rec.imported_as
        })
Beispiel #2
0
    def run(self, edit, force):
        reg = single_selected_region(self.view)
        rec = op.parse_import_section(self.view).record_at_or_stop(reg)

        self.view.run_command('poli_remove_import', {
            'imported_as': rec.imported_as,
            'force': force
        })
Beispiel #3
0
 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
         })
Beispiel #4
0
    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)
Beispiel #5
0
    def run(self, edit, forward):
        reg = single_selected_region(self.view)
        warnings = op.get_warnings(self.view)
        if forward:
            idx = index_where(warnings, lambda w: w.begin() > reg.end())
        else:
            idx = last_index_where(warnings, lambda w: w.end() < reg.begin())

        if idx is None:
            sublime.status_message("No warning found")
        else:
            jump(self.view, warnings[idx].begin())
Beispiel #6
0
    def run(self, edit):
        reg = single_selected_region(self.view)
        if op.reg_import_section(self.view).contains(reg):
            raise NotImplementedError
            # TODO: implement import rename
            self.view.run_command('poli_rename_this_import')
            return

        loc = op.sel_cursor_location(self.view)
        if not loc.is_name_targeted:
            sublime.status_message("Cursor is not placed over entry name")
            return

        op.enter_edit_mode(self.view, loc.entry.reg_name, adding_new=False)
Beispiel #7
0
    def run(self, edit):
        reg = single_selected_region(self.view)

        if op.reg_import_section(self.view).contains(reg):
            impsec = op.parse_import_section(self.view)
            rec = impsec.record_at_or_stop(reg)
            op.goto_module_entry(self.view.window(), rec.module_name, rec.name)
        else:
            mtch = op.reference_at(self.view, reg)
            if mtch is None:
                sublime.status_message("No name under cursor")
                return

            star, name = mtch.group('star', 'name')
            op.goto_ref(self.view, star, name)
Beispiel #8
0
    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)
Beispiel #9
0
def sel_cursor_location(view, require_fully_selected=False):
    reg = single_selected_region(view)
    return module_body(view).cursor_location_or_stop(
        reg, require_fully_selected=require_fully_selected
    )