Esempio n. 1
0
 def refactoring_context(self):
     project_path = root_folder_for(self.view)
     file_path = file_or_buffer_name(self.view)
     start = self.sel.a
     end = self.sel.b
     source = self.view.substr(sublime.Region(0, self.view.size()))
     return project_path, file_path, start, end, source
    def run(self, *args):
        view = self.window.active_view()
        row, col = view.rowcol(view.sel()[0].a)
        offset = view.text_point(row, col)
        path = file_or_buffer_name(view)
        source = view.substr(sublime.Region(0, view.size()))
        if view.substr(offset) in [u'(', u')']:
            offset = view.text_point(row, col - 1)

        proxy = proxy_for(view)
        if not proxy:
            return
        def_result = proxy.definition_location(
            source, root_folder_for(view), path, offset)

        if not def_result or def_result == [None, None]:
            return

        target_path, target_lineno = def_result
        current_rowcol = view.rowcol(view.sel()[0].end())
        current_lineno = current_rowcol[0] + 1
        current_colno = current_rowcol[1] + 1

        if None not in (path, target_path, target_lineno):
            self.save_pos(file_or_buffer_name(view), current_lineno, current_colno)
            path = target_path + ":" + str(target_lineno)
            self.window.open_file(path, sublime.ENCODED_POSITION)
        elif target_lineno is not None:
            self.save_pos(file_or_buffer_name(view), current_lineno, current_colno)
            path = file_or_buffer_name(view) + ":" + str(target_lineno)
            self.window.open_file(path, sublime.ENCODED_POSITION)
        else:
            # fail silently (user selected whitespace, etc)
            pass
    def run(self, *args):
        view = self.window.active_view()
        row, col = view.rowcol(view.sel()[0].a)
        offset = view.text_point(row, col)
        path = file_or_buffer_name(view)
        source = view.substr(sublime.Region(0, view.size()))
        if view.substr(offset) in [u'(', u')']:
            offset = view.text_point(row, col - 1)

        proxy = proxy_for(view)
        if not proxy:
            return
        def_result = proxy.definition_location(
            source, root_folder_for(view), path, offset)

        if not def_result or def_result == [None, None]:
            return

        target_path, target_lineno = def_result
        current_lineno = view.rowcol(view.sel()[0].end())[0] + 1

        if None not in (path, target_path, target_lineno):
            self.save_pos(file_or_buffer_name(view), current_lineno)
            path = target_path + ":" + str(target_lineno)
            self.window.open_file(path, sublime.ENCODED_POSITION)
        elif target_lineno is not None:
            self.save_pos(file_or_buffer_name(view), current_lineno)
            path = file_or_buffer_name(view) + ":" + str(target_lineno)
            self.window.open_file(path, sublime.ENCODED_POSITION)
        else:
            # fail silently (user selected whitespace, etc)
            pass
Esempio n. 4
0
    def run(self, edit):
        if self.view.is_dirty():
            self.view.run_command("save")
        if self.view.file_name():
            row, col = self.view.rowcol(self.view.sel()[0].a)
            path = file_or_buffer_name(self.view)
            all_view = sublime.Region(0, self.view.size())
            source = self.view.substr(all_view)

            proxy = proxy_for(self.view)
            if not proxy:
                return
            organized_source = proxy.organize_imports(source, root_folder_for(self.view), path)
            self.view.replace(edit, all_view, organized_source)
            # end with a saved view to be compatible with the other refactorings
            self.view.run_command("save")
 def on_query_completions(self, view, prefix, locations):
     path = file_or_buffer_name(view)
     source = view.substr(sublime.Region(0, view.size()))
     loc = view.rowcol(locations[0])
     # t0 = time.time()
     proxy = proxy_for(view)
     if not proxy:
         return []
     proposals = proxy.completions(source, root_folder_for(view), path, loc)
     # proposals = (
     #   proxy.profile_completions(source, root_folder_for(view), path, loc)
     # )
     # print("+++", time.time() - t0)
     if proposals:
         completion_flags = (sublime.INHIBIT_WORD_COMPLETIONS
                             | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
         return (proposals, completion_flags)
     return proposals
 def on_query_completions(self, view, prefix, locations):
     path = file_or_buffer_name(view)
     source = view.substr(sublime.Region(0, view.size()))
     loc = view.rowcol(locations[0])
     # t0 = time.time()
     proxy = proxy_for(view)
     if not proxy:
         return []
     proposals = proxy.completions(source, root_folder_for(view), path, loc)
     # proposals = (
     #   proxy.profile_completions(source, root_folder_for(view), path, loc)
     # )
     # print("+++", time.time() - t0)
     if proposals:
         completion_flags = (
             sublime.INHIBIT_WORD_COMPLETIONS |
             sublime.INHIBIT_EXPLICIT_COMPLETIONS
         )
         return (proposals, completion_flags)
     return proposals
    def run(self):
        view = self.window.active_view()
        row, col = view.rowcol(view.sel()[0].a)
        offset = view.text_point(row, col)
        path = file_or_buffer_name(view)
        source = view.substr(sublime.Region(0, view.size()))
        if view.substr(offset) in [u'(', u')']:
            offset = view.text_point(row, col - 1)

        proxy = proxy_for(view)
        if not proxy:
            return
        doc = proxy.documentation(source, root_folder_for(view), path, offset)
        if doc:
            open_pydoc_in_view = get_setting("open_pydoc_in_view")
            if open_pydoc_in_view:
                self.display_docs_in_view(doc)
            else:
                self.display_docs_in_panel(view, doc)
        else:
            word = view.substr(view.word(offset))
            self.notify_no_documentation(view, word)
    def run(self):
        view = self.window.active_view()
        row, col = view.rowcol(view.sel()[0].a)
        offset = view.text_point(row, col)
        path = file_or_buffer_name(view)
        source = view.substr(sublime.Region(0, view.size()))
        if view.substr(offset) in [u'(', u')']:
            offset = view.text_point(row, col - 1)

        proxy = proxy_for(view)
        if not proxy:
            return
        doc = proxy.documentation(source, root_folder_for(view), path, offset)
        if doc:
            open_pydoc_in_view = get_setting("open_pydoc_in_view")
            if open_pydoc_in_view:
                self.display_docs_in_view(doc)
            else:
                self.display_docs_in_panel(view, doc)
        else:
            word = view.substr(view.word(offset))
            self.notify_no_documentation(view, word)
 def on_post_save_async(self, view, *args):
     proxy = proxy_for(view)
     if not proxy:
         return
     path = file_or_buffer_name(view)
     proxy.report_changed(root_folder_for(view), path)
 def on_post_save_async(self, view, *args):
     proxy = proxy_for(view)
     if not proxy:
         return
     path = file_or_buffer_name(view)
     proxy.report_changed(root_folder_for(view), path)