Ejemplo n.º 1
0
 def new_name_entered(self, new_name):
     with ropemate.ropecontext(self.view) as context:
         if new_name is None or new_name == self.rename.old_name:
             return
         changes = self.rename.get_changes(new_name, in_hierarchy=True)
         self.handle = TaskHandle(name="rename_handle")
         self.handle.add_observer(self.refactoring_done)
         context.project.do(changes, task_handle=self.handle)
Ejemplo n.º 2
0
 def new_name_entered(self, new_name):
     with ropemate.ropecontext(self.view) as context:
         if new_name is None or new_name == self.rename.old_name:
             return
         changes = self.rename.get_changes(new_name, in_hierarchy=True)
         self.handle = TaskHandle(name="rename_handle")
         self.handle.add_observer(self.refactoring_done)
         context.project.do(changes, task_handle=self.handle)
Ejemplo n.º 3
0
 def new_name_entered(self, new_name):
     with ropemate.ropecontext(self.view) as context:
         if new_name is None:
             return
         changes = self.extract.get_changes(new_name)
         print changes
         self.handle = TaskHandle(name="extract_handle")
         self.handle.add_observer(self.refactoring_done)
         context.project.do(changes, task_handle=self.handle)
Ejemplo n.º 4
0
 def new_name_entered(self, new_name):
     with ropemate.ropecontext(self.view) as context:
         if new_name is None:
             return
         changes = self.extract.get_changes(new_name)
         print changes
         self.handle = TaskHandle(name="extract_handle")
         self.handle.add_observer(self.refactoring_done)
         context.project.do(changes, task_handle=self.handle)
Ejemplo n.º 5
0
    def run(self, edit, block=False):
        self.view.run_command("save")
        self.original_loc = self.view.rowcol(self.view.sel()[0].a)
        with ropemate.ropecontext(self.view) as context:
            self.sel = self.view.sel()[0]
            word = self.view.substr(self.view.word(self.sel.b))

            self.rename = Rename(context.project, context.resource, self.sel.b)
            self.view.window().show_input_panel(
                "New name", word, self.new_name_entered, None, None)
Ejemplo n.º 6
0
    def run(self, edit, block=False):
        self.view.run_command("save")
        self.original_loc = self.view.rowcol(self.view.sel()[0].a)
        with ropemate.ropecontext(self.view) as context:
            self.sel = self.view.sel()[0]
            word = self.view.substr(self.view.word(self.sel.b))

            self.rename = Rename(context.project, context.resource, self.sel.b)
            self.view.window().show_input_panel(
                "New name", word, self.new_name_entered, None, None)
Ejemplo n.º 7
0
 def run(self, edit, block=False):
     with ropemate.ropecontext(self.view) as context:
         offset = self.view.sel()[0].a
         found_resource, line = None, None
         try:
             found_resource, line = codeassist.get_definition_location(
                 context.project, context.input, offset, context.resource)
         except rope.base.exceptions.BadIdentifierError, e:
             # fail silently -> the user selected empty space etc
             pass
         except Exception, e:
             print e
Ejemplo n.º 8
0
 def run(self, edit, block=False):
     with ropemate.ropecontext(self.view) as context:
         offset = self.view.sel()[0].a
         found_resource, line = None, None
         try:
             found_resource, line = codeassist.get_definition_location(
                 context.project, context.input, offset, context.resource)
         except rope.base.exceptions.BadIdentifierError, e:
             # fail silently -> the user selected empty space etc
             pass
         except Exception, e:
             print e
Ejemplo n.º 9
0
    def run(self, edit):
        with ropemate.ropecontext(self.view) as context:
            if not context.project_dir:
                # no project dir known
                return
            file_name = self.view.file_name()
            cprefix = os.path.commonprefix([context.project_dir, file_name])
            if not cprefix == context.project_dir:
                # current file not beneath the project dir
                return

            relpath = os.path.relpath(file_name, context.project_dir)
            module_name = relpath.replace(os.sep, ".")\
                .replace(".py", "").replace(".__init__", "")

            mod = context.project.pycore.find_module(module_name)
            print mod, mod.path
            context.project.pycore.analyze_module(mod)
Ejemplo n.º 10
0
    def run(self, edit):
        with ropemate.ropecontext(self.view) as context:
            if not context.project_dir:
                # no project dir known
                return
            file_name = self.view.file_name()
            cprefix = os.path.commonprefix(
                [context.project_dir, file_name])
            if not cprefix == context.project_dir:
                # current file not beneath the project dir
                return

            relpath = os.path.relpath(file_name, context.project_dir)
            module_name = relpath.replace(os.sep, ".")\
                .replace(".py", "").replace(".__init__", "")

            mod = context.project.pycore.find_module(module_name)
            print mod, mod.path
            context.project.pycore.analyze_module(mod)
Ejemplo n.º 11
0
    def run(self, edit):
        view = self.view
        row, col = view.rowcol(view.sel()[0].a)
        offset = view.text_point(row, col)
        with ropemate.ropecontext(view) as context:
            try:
                doc = codeassist.get_doc(
                    context.project, context.input, offset, context.resource)
                if not doc:
                    raise rope.base.exceptions.BadIdentifierError
                self.output(doc)
            except rope.base.exceptions.BadIdentifierError:
                word = self.view.substr(self.view.word(offset))
                self.view.set_status(
                    "rope_documentation_error", "No documentation found for %s" % word)

                def clear_status_callback():
                    self.view.erase_status("rope_documentation_error")
                sublime.set_timeout(clear_status_callback, 5000)
Ejemplo n.º 12
0
    def run(self, edit):
        view = self.view
        row, col = view.rowcol(view.sel()[0].a)
        offset = view.text_point(row, col)
        with ropemate.ropecontext(view) as context:
            try:
                doc = codeassist.get_doc(
                    context.project, context.input, offset, context.resource)
                if not doc:
                    raise rope.base.exceptions.BadIdentifierError
                self.output(doc)
            except rope.base.exceptions.BadIdentifierError:
                word = self.view.substr(self.view.word(offset))
                self.view.set_status(
                    "rope_documentation_error", "No documentation found for %s" % word)

                def clear_status_callback():
                    self.view.erase_status("rope_documentation_error")
                sublime.set_timeout(clear_status_callback, 5000)
Ejemplo n.º 13
0
    def on_query_completions(self, view, prefix, locations):
        if not view.match_selector(locations[0], "source.python"):
            return []
        loc = locations[0]
        line = view.substr(view.line(loc))

        with ropemate.ropecontext(view) as context:
            try:
                raw_proposals = codeassist.code_assist(
                    context.project, context.input, loc, context.resource)
            except ModuleSyntaxError:
                raw_proposals = []
            if len(raw_proposals) > 0:
                sorted_proposals = codeassist.sorted_proposals(raw_proposals)
            else:
                # try the simple hackish completion
                identifier = line[:view.rowcol(loc)[1] - 1].strip()
                raw_proposals = self.simple_module_completion(view, identifier)
                sorted_proposals = sorted(raw_proposals, key=lambda x: x.name)

        proposals = filter(lambda p: p.name != "self=", sorted_proposals)
        return [(str(p), p.name) for p in proposals]
Ejemplo n.º 14
0
    def on_query_completions(self, view, prefix, locations):
        if not view.match_selector(locations[0], "source.python"):
            return []

        with ropemate.ropecontext(view) as context:
            loc = locations[0]
            try:
                raw_proposals = codeassist.code_assist(
                    context.project, context.input, loc, context.resource)
            except ModuleSyntaxError:
                raw_proposals = []
            if len(raw_proposals) <= 0:
                # try the simple hackish completion
                line = view.substr(view.line(loc))
                identifier = line[:view.rowcol(loc)[1]].strip(' .')
                if ' ' in identifier:
                    identifier = identifier.split(' ')[-1]
                raw_proposals = self.simple_module_completion(view, identifier)

        sorted_proposals = codeassist.sorted_proposals(raw_proposals)
        proposals = filter(lambda p: p.name != "self=", sorted_proposals)
        return [(str(p), p.name) for p in proposals]