Exemple #1
0
    def on_select_global(self, choice):
        def loc_to_str(loc):
            resource, line = loc
            return "%s:%s" % (resource.path, line)

        if choice is not -1:
            selected_global = self.names[choice]
            with ropemate.RopeContext(self.view) as context:
                self.locs = context.importer.get_name_locations(
                    selected_global)
                self.locs = map(loc_to_str, self.locs)

                if not self.locs:
                    return
                if len(self.locs) == 1:
                    self.on_select_location(0)
                else:
                    self.view.window().show_quick_panel(
                        self.locs, self.on_select_location,
                        sublime.MONOSPACE_FONT)
Exemple #2
0
    def on_select_global(self, choice):
        if choice is not -1:
            name, module = self.candidates[choice]
            with ropemate.RopeContext(self.view) as context:
                # check whether adding an import is necessary, and where
                all_lines = self.view.lines(sublime.Region(
                    0, self.view.size()))
                line_no = context.importer.find_insertion_line(context.input)
                insert_import_str = "from %s import %s\n" % (module, name)
                existing_imports_str = self.view.substr(
                    sublime.Region(all_lines[0].a, all_lines[line_no - 1].b))
                do_insert_import = insert_import_str not in existing_imports_str
                insert_import_point = all_lines[line_no].a

                # the word prefix that is replaced
                original_word = self.view.word(self.offset)

                # replace the prefix, add the import if necessary
                e = self.view.begin_edit()
                self.view.replace(e, original_word, name)
                if do_insert_import:
                    self.view.insert(e, insert_import_point, insert_import_str)
                self.view.end_edit(e)
Exemple #3
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,
                                         maxfixes=3)
                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)
Exemple #4
0
 def run(self, edit):
     with ropemate.RopeContext(self.view) as context:
         context.importer.clear_cache()
         context.build_cache()
Exemple #5
0
 def on_post_save(self, view):
     if not "Python" in view.settings().get('syntax'):
         return
     with ropemate.RopeContext(view) as context:
         context.importer.generate_cache(resources=[context.resource])
Exemple #6
0
 def run(self, edit):
     with ropemate.RopeContext(self.view) as context:
         self.names = list(context.importer.get_all_names())
         self.view.window().show_quick_panel(self.names,
                                             self.on_select_global,
                                             sublime.MONOSPACE_FONT)