python类ENCODED_POSITION的实例源码

tern.py 文件源码 项目:PhaserSublimePackage 作者: PhaserEditor2D 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def run(self, edit, **args):
    data = run_command(self.view, {"type": "definition", "lineCharPositions": True})
    if data is None: return
    file = data.get("file", None)
    if file is not None:
      # Found an actual definition
      row, col = self.view.rowcol(self.view.sel()[0].b)
      cur_pos = self.view.file_name() + ":" + str(row + 1) + ":" + str(col + 1)
      jump_stack.append(cur_pos)
      if len(jump_stack) > 50: jump_stack.pop(0)
      real_file = (os.path.join(get_pfile(self.view).project.dir, file) +
        ":" + str(data["start"]["line"] + 1) + ":" + str(data["start"]["ch"] + 1))
      sublime.active_window().open_file(real_file, sublime.ENCODED_POSITION)
    else:
      url = data.get("url", None)
      if url is None:
        sublime.error_message("Could not find a definition")
      else:
        webbrowser.open(url)
commands.py 文件源码 项目:KodiDevKit 作者: phil65 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def run(self, edit):
        for region in self.view.sel():
            if not region.empty():
                self.view.insert(edit, region.begin(), self.view.substr(region))
                continue
            line_contents = self.view.substr(self.view.line(region))
            match = re.search(r'File "(.*?)", line (\d*), in .*', line_contents)
            if match:
                sublime.active_window().open_file("{}:{}".format(os.path.realpath(match.group(1)),
                                                                 match.group(2)),
                                                  sublime.ENCODED_POSITION)
                return
            match = re.search(r"', \('(.*?)', (\d+), (\d+), ", line_contents)
            if match:
                sublime.active_window().open_file("{}:{}:{}".format(os.path.realpath(match.group(1)),
                                                                    match.group(2),
                                                                    match.group(3)),
                                                  sublime.ENCODED_POSITION)
                return
go_to_definition.py 文件源码 项目:FlowIDE 作者: tptee 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def run_async(self):
        result = None
        try:
            result = CLI(self.view).get_def()
        except InvalidContext:
            print('Invalid context')
            pass
        except Exception as e:
            display_unknown_error(self.view, e)
            return

        print(result)
        if not result or not result.get('path'):
            return

        sublime.active_window().open_file(
            result['path'] +
            ':' + str(result['line']) +
            ':' + str(result['start']),
            sublime.ENCODED_POSITION |
            sublime.TRANSIENT
        )
show_definition.py 文件源码 项目:Assembly-RGBDS 作者: michalisb 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def run(self, edit, event):
        if self.symbol_details:
            view_path = self.symbol_details[0]
            focus_region = self.symbol_details[1]
            # collapse the region to a single point, the region start
            focus_region = sublime.Region(focus_region.begin(), focus_region.begin())

            # get the view with this path
            view = sublime.active_window().find_open_file(view_path)
            if view:
                self.showSymbol(view, focus_region)
            else:
                # weird issue, but unless we open the file with 'ENCODED_POSITION' it won't scroll afterwards
                # https://github.com/SublimeTextIssues/Core/issues/538
                view = sublime.active_window().open_file("%s:%d:%d" % (view_path, 1, 0), sublime.ENCODED_POSITION)

                def viewLoadedTimeout():
                    # we can run methods only on loaded views
                    if not view.is_loading():
                        self.showSymbol(view, focus_region)
                    else:
                        sublime.set_timeout(viewLoadedTimeout, 100)

                # open is asynchronous, wait for a bit and then try to focus
                sublime.set_timeout(viewLoadedTimeout, 100)
EasyClangComplete.py 文件源码 项目:EasyClangComplete 作者: niosus 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def run(self, edit):
        """Run goto declaration command.

        Navigates to delcaration of entity located by current position
        of cursor.
        """
        if not Tools.is_valid_view(self.view):
            return
        config_manager = EasyClangComplete.view_config_manager
        if not config_manager:
            return
        location = config_manager.trigger_get_declaration_location(self.view)
        if location:
            loc = location.file.name
            loc += ":" + str(location.line)
            loc += ":" + str(location.column)
            log.debug("Navigating to declaration: %s", loc)
            sublime.active_window().open_file(loc, sublime.ENCODED_POSITION)
rename.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def rename(self, edit: sublime.Edit) -> None:
        """Rename in the buffer
        """

        data = self.data
        if data['success'] is True:
            for filename, data in data['renames'].items():
                for line in data:
                    view = sublime.active_window().open_file(
                        '{}:{}:0'.format(filename, line['lineno']),
                        sublime.ENCODED_POSITION
                    )
                    while view.is_loading():
                        time.sleep(0.01)

                    lines = view.lines(sublime.Region(0, view.size()))
                    view.replace(edit, lines[line['lineno']], line['line'])

        self.data = None
subl.py 文件源码 项目:SourceKittenSubl 作者: Dan2552 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def on_navigate(self, url):
        if self.view.is_popup_visible():
            self.view.hide_popup()
        filepath, line, offsets = url.split(":")
        column, length = offsets.split("-")
        new_view = self.view.window().open_file(url, sublime.ENCODED_POSITION)

        start_offset = int(column) - 1
        end_offset = start_offset + int(length)
        region = Region(start_offset, end_offset)

        # Add a highlight
        new_view.add_regions("highlight", [region], "comment")

        # Remove highlight after a second
        Timer(1.0, lambda: new_view.add_regions("highlight", [], "comment")).start()
kiwilime.py 文件源码 项目:kiwi 作者: alpha1e0 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def run(self, edit, **args):
        if not self._is_kiwilime_view:
            return

        point = current.point(self.view)

        file_name, lineno = get_file_location(self.view, point)
        if not file_name:
            return None

        if os.path.exists(file_name):
            file_loc = "{0}:{1}".format(file_name, lineno)
            self.view.window().open_file(file_loc, sublime.ENCODED_POSITION)
        else:
            show_error("File '{0}'' doses not exists.".format(
                file_name))
goto_definition.py 文件源码 项目:sublime-flowtype 作者: Pegase745 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def handle_process(self, returncode, stdout, error):
        """Handle the output from the threaded process."""
        if type(error) is bytes:
            error = error.decode('utf-8')

        if returncode != 0:
            logger.logger.error('get_def %s' % error)
            return

        logger.logger.debug(stdout)

        if stdout and stdout['path']:
            self.active_window.open_file(
                stdout['path'] +
                ':' + str(stdout['line']) +
                ':' + str(stdout['start']),
                sublime.ENCODED_POSITION |
                False
            )
        else:
            self.view.set_status('flow_type', 'Flow: no definition found')
ToolTipHelper.py 文件源码 项目:ToolTip-Helper 作者: doobleweb 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def on_navigate(self, href):
        """ open the link in a new tab on web browser """
        if '$$$' in href:
            try:
                arr = href.split('$$$')
                file_name = arr[0].strip()
                location = arr[1].split(',')
                row = int(location[0].strip())
                col = int(location[1].strip())
                sublime.active_window().open_file("%s:%s:%s" % 
                        (file_name, row, col),
                        sublime.ENCODED_POSITION)
            except Exception as e:
                # print(e)
                self.logger_msg += str(e) + '\n'
        else:
            try:
                webbrowser.open_new_tab(href)
            except Exception as e:
                # logging.error('cannot open link on web browser.')
                self.logger_msg += str(e) + '\n'
ex_actions.py 文件源码 项目:NeoVintageous 作者: NeoVintageous 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def open_file(self, file_name):
        flags = (FORCE_GROUP | ENCODED_POSITION)
        self.window.open_file(file_name, group=(self.window.num_groups() - 1), flags=flags)
vi_actions.py 文件源码 项目:NeoVintageous 作者: NeoVintageous 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def run(self, edit, mode=None, character=None, count=1):
        def f(view, s):
            if mode == modes.VISUAL:
                if s.a <= s.b:
                    if address.b < s.b:
                        return Region(s.a + 1, address.b)
                    else:
                        return Region(s.a, address.b)
                else:
                    return Region(s.a + 1, address.b)

            elif mode == modes.NORMAL:
                return address

            elif mode == modes.INTERNAL_NORMAL:
                if s.a < address.a:
                    return Region(view.full_line(s.b).a, view.line(address.b).b)
                return Region(view.full_line(s.b).b, view.line(address.b).a)

            return s

        state = self.state
        address = state.marks.get_as_encoded_address(character)

        if address is None:
            return

        if isinstance(address, str):
            if not address.startswith('<command'):
                self.view.window().open_file(address, ENCODED_POSITION)
            else:
                # We get a command in this form: <command _vi_double_quote>
                self.view.run_command(address.split(' ')[1][:-1])
            return

        regions_transformer(self.view, f)

        if not self.view.visible_region().intersects(address):
            self.view.show_at_center(address)
vi_actions.py 文件源码 项目:NeoVintageous 作者: NeoVintageous 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def run(self, edit, count=1, mode=None, character=None):
        def f(view, s):
            if mode == modes.VISUAL:
                if s.a <= s.b:
                    if address.b < s.b:
                        return Region(s.a + 1, address.b)
                    else:
                        return Region(s.a, address.b)
                else:
                    return Region(s.a + 1, address.b)
            elif mode == modes.NORMAL:
                return address
            elif mode == modes.INTERNAL_NORMAL:
                return Region(s.a, address.b)

            return s

        state = self.state
        address = state.marks.get_as_encoded_address(character, exact=True)

        if address is None:
            return

        if isinstance(address, str):
            if not address.startswith('<command'):
                self.view.window().open_file(address, ENCODED_POSITION)
            return

        # This is a motion in a composite command.
        regions_transformer(self.view, f)
tern.py 文件源码 项目:PhaserSublimePackage 作者: PhaserEditor2D 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def run(self, edit, **args):
    if len(jump_stack) > 0:
      sublime.active_window().open_file(jump_stack.pop(), sublime.ENCODED_POSITION)
kodidevkit.py 文件源码 项目:KodiDevKit 作者: phil65 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def on_done(self, index):
        if index == -1:
            return None
        node = self.nodes[index]
        view = self.window.open_file("%s:%i" % (node["file"], node["line"]),
                                     sublime.ENCODED_POSITION)
        self.select_text(view, node)
kodidevkit.py 文件源码 项目:KodiDevKit 作者: phil65 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def show_preview(self, index):
        node = self.nodes[index]
        self.window.open_file("%s:%i" % (node["file"], node["line"]),
                              sublime.ENCODED_POSITION | sublime.TRANSIENT)
kodidevkit.py 文件源码 项目:KodiDevKit 作者: phil65 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def run(self):
        flags = sublime.CLASS_WORD_START | sublime.CLASS_WORD_END
        view = self.window.active_view()
        position = INFOS.go_to_tag(keyword=utils.get_node_content(view, flags),
                                   folder=view.file_name().split(os.sep)[-2])
        if position:
            self.window.open_file(position, sublime.ENCODED_POSITION)
kodidevkit.py 文件源码 项目:KodiDevKit 作者: phil65 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def on_done(self, index):
        if index == -1:
            return None
        node = self.nodes[index]
        self.window.open_file("%s:%i" % (node["file"], node["line"]),
                              sublime.ENCODED_POSITION)
type_hints.py 文件源码 项目:purescript-ide-sublime 作者: b123400 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def show_type_hint(self, view, point):
        project_path = find_project_dir(view)
        module_info = get_module_imports(project_path, view.file_name())
        module, word = module_word(view, point)
        if word == '':
            return
        if word[0] == '(' and word[-1] == ')':
            word = word[1:-1]

        # TODO: use module from module_word to improve accuracy
        type_info = get_type(
            project_path,
            module_info['moduleName'],
            word,
            [m['module'] for m in module_info['imports']]
        )
        if len(type_info) == 0:
            return

        first_result = type_info[0]

        def on_navigate(string):
            view.window().open_file(string, sublime.ENCODED_POSITION)

        #file_path:row:col
        link_url = first_result['definedAt']['name'] + ':' + \
            str(first_result['definedAt']['start'][0]) + ':' + \
            str(first_result['definedAt']['start'][1])

        view.show_popup('''
            <p>From: <a href="%s">%s</a> </p>
            <p>Type: %s </p>
        ''' % ( link_url,
                ",".join(first_result['exportedFrom']),
                first_result['type']),
        sublime.HIDE_ON_MOUSE_MOVE_AWAY,
        point,
        500,    # max width
        500,    # max height
        on_navigate)
HighlightBuildErrors.py 文件源码 项目:SublimeRemoteGDB 作者: summerwinter 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def select(self, row):
        if row >= len(self.error_lines):
            return
        errorline = self.error_lines[row]
        sublime.active_window().open_file("%s:%d" % (errorline.file_name, errorline.line), sublime.ENCODED_POSITION)
goGuru.py 文件源码 项目:GoGuru 作者: alvarolm 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def on_selection_modified(self, view):
        if view.name() == "GoGuru Output":
            if len(view.sel()) != 1:
                return
            if view.sel()[0].size() == 0:
                return

            lines = view.lines(view.sel()[0])
            if len(lines) != 1:
                return

            line = view.full_line(lines[0])
            text = view.substr(line)

            # format = get_setting("guru_format")

            # "filename:line:col" pattern for json
            m = re.search("\"([^\"]+):([0-9]+):([0-9]+)\"", text)

            # >filename:line:col< pattern for xml
            if m is None:
                m = re.search(">([^<]+):([0-9]+):([0-9]+)<", text)

            # filename:line.col-line.col: pattern for plain
            if m is None:
                m = re.search("^(.+\.go):([0-9]+).([0-9]+)[-: ]", text)

            if m:
                w = view.window()
                new_view = w.open_file(m.group(1) + ':' + m.group(2) + ':' + m.group(3), sublime.ENCODED_POSITION)
                group, index = w.get_view_index(new_view)
                if group != -1:
                    w.focus_group(group)
quick_panel_handler.py 文件源码 项目:EasyClangComplete 作者: niosus 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def on_done(self, idx):
        """Pick this error to navigate to a file."""
        log.debug("Picked idx: %s", idx)
        if idx < 0:
            return
        picked_entry = self.errors[idx]
        file_str = "{file}:{row}:{col}".format(file=picked_entry['file'],
                                               row=picked_entry['row'],
                                               col=picked_entry['col'])
        self.view.window().open_file(file_str, sublime.ENCODED_POSITION)
EasyClangComplete.py 文件源码 项目:EasyClangComplete 作者: niosus 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def on_open_declaration(location):
        """Call this callback when link to type is clicked in info popup.

        Opens location with type declaration

        """
        sublime.active_window().open_file(location, sublime.ENCODED_POSITION)
definition.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def handle_response(self, response, position):
        window = sublime.active_window()
        if response:
            location = response if isinstance(response, dict) else response[0]
            file_path = uri_to_filename(location.get("uri"))
            start = Point.from_lsp(location['range']['start'])
            file_location = "{}:{}:{}".format(file_path, start.row + 1, start.col + 1)
            debug("opening location", location)
            window.open_file(file_location, sublime.ENCODED_POSITION)
            # TODO: can add region here.
        else:
            window.run_command("goto_definition")
explore_panel.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def jump(self, transient: bool=False) -> None:
        """Jump to the selection
        """

        flags = sublime.ENCODED_POSITION
        if transient is True:
            flags |= sublime.TRANSIENT

        get_jump_history_for_view(self.view).push_selection(self.view)
        sublime.active_window().open_file(self.position, flags)
        if not transient:
            self._toggle_indicator()
jediusages.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _jump(self, filename: Union[int, str], lineno: int =None,
              columno: int =None, transient: bool =False) -> None:
        """Jump to a window
        """

        # process jumps from options window
        if type(filename) is int:
            if filename == -1:
                # restore view
                view = self.text.view
                point = self.point

                sublime.active_window().focus_view(view)
                view.show(point)

                if view.sel()[0] != point:
                    view.sel().clear()
                    view.sel().add(point)

                return

        opts = self.options[filename]
        if len(self.options[filename]) == 4:
            opts = opts[1:]

        filename, lineno, columno = opts
        flags = sublime.ENCODED_POSITION
        if transient:
            flags |= sublime.TRANSIENT

        sublime.active_window().open_file(
            '{}:{}:{}'.format(filename, lineno or 0, columno or 0),
            flags
        )

        self._toggle_indicator(lineno, columno)
chromium_x_refs.py 文件源码 项目:ChromiumXRefs 作者: karlinjf 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def goToLocation(cmd, src_path, caller, view):
  line = caller['line'];
  path = src_path + caller['filename']

  # Open the file and jump to the line
  new_view = view.window().open_file(path + ":%d:0" % line, sublime.ENCODED_POSITION)
  if new_view.is_loading():
    global g_open_callbacks_on_load
    g_open_callbacks_on_load[path] = lambda: finishGoingToLocation(caller, new_view)
    return

  finishGoingToLocation(caller, new_view)
build.py 文件源码 项目:SublimeAnarchy 作者: AnarchyTools 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def on_selection_modified(self, view):
        if not self.enable(view):
            return
        if len(list(view.sel())) == 0:
            return
        cursor = view.sel()[0].begin()
        if "filename" in view.scope_name(cursor):
            line = view.substr(view.line(cursor))
            parts = [p.strip() for p in line.split(":", maxsplit=5)]

            filename = os.path.join(os.path.dirname(view.window().project_file_name()), parts[0])
            view.window().open_file(filename + ":" + parts[1] + ":" + parts[2], sublime.ENCODED_POSITION)
vhdl_navigation.py 文件源码 项目:SmartVHDL 作者: TheClams 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def on_navigate(self, href):
        href_s = href.split('@')
        pos = sublime.Region(0,0)
        v = self.view.window().open_file(href_s[1], sublime.ENCODED_POSITION)


############################################################################
# Helper function to retrieve current module name based on cursor position #
ex_commands.py 文件源码 项目:VintageousPlus 作者: trishume 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def open_file(self, file_name):
        flags = (sublime.FORCE_GROUP | sublime.ENCODED_POSITION)
        self.window.open_file(file_name, group=(self.window.num_groups() - 1),
                              flags=flags)


问题


面经


文章

微信
公众号

扫码关注公众号