Python sublime.ENCODED_POSITION Examples

The following are 30 code examples of sublime.ENCODED_POSITION(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sublime , or try the search function .
Example #1
Source File: RustAutoComplete.py    From RustAutoComplete with MIT License 6 votes vote down vote up
def run(self, edit):
        # Get the buffer location in correct format for racer
        row, col = self.view.rowcol(self.view.sel()[0].begin())
        row += 1

        results = run_racer(self.view, ["find-definition", str(row), str(col)])

        if len(results) == 1:
            result = results[0]
            path = result.path
            # On Windows the racer will return the paths without the drive
            # letter and we need the letter for the open_file to work.
            if sublime.platform() == 'windows' and not re.compile('^\w\:').match(path):
                path = 'c:' + path
            encoded_path = "{0}:{1}:{2}".format(path, result.row, result.column)
            self.view.window().open_file(encoded_path, sublime.ENCODED_POSITION) 
Example #2
Source File: show_file_at_commit.py    From GitSavvy with MIT License 6 votes vote down vote up
def run(self, edit):
        # type: (...) -> None
        window = self.view.window()
        if not window:
            return

        settings = self.view.settings()
        commit_hash = settings.get("git_savvy.show_file_at_commit_view.commit")
        file_path = settings.get("git_savvy.file_path")
        assert commit_hash
        assert file_path

        full_path = os.path.join(self.repo_path, file_path)
        row, col = self.view.rowcol(self.view.sel()[0].begin())
        row = self.find_matching_lineno(commit_hash, None, row + 1, full_path)
        window.open_file(
            "{file}:{row}:{col}".format(file=full_path, row=row, col=col),
            sublime.ENCODED_POSITION
        ) 
Example #3
Source File: tern.py    From PhaserSublimePackage with MIT License 6 votes vote down vote up
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) 
Example #4
Source File: go_to_definition.py    From FlowIDE with MIT License 6 votes vote down vote up
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
        ) 
Example #5
Source File: diff.py    From GitSavvy with MIT License 6 votes vote down vote up
def load_file_at_line(self, commit_hash, filename, row, col):
        # type: (Optional[str], str, int, int) -> None
        """
        Show file at target commit if `git_savvy.diff_view.target_commit` is non-empty.
        Otherwise, open the file directly.
        """
        target_commit = commit_hash or self.view.settings().get("git_savvy.diff_view.target_commit")
        full_path = os.path.join(self.repo_path, filename)
        window = self.view.window()
        if not window:
            return

        if target_commit:
            window.run_command("gs_show_file_at_commit", {
                "commit_hash": target_commit,
                "filepath": full_path,
                "lineno": row,
            })
        else:
            window.open_file(
                "{file}:{row}:{col}".format(file=full_path, row=row, col=col),
                sublime.ENCODED_POSITION
            ) 
Example #6
Source File: EasyClangComplete.py    From EasyClangComplete with MIT License 6 votes vote down vote up
def run(self, edit):
        """Run goto declaration command.

        Navigates to delcaration of entity located by current position
        of cursor.
        """
        if not SublBridge.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) 
Example #7
Source File: find_usages.py    From omnisharp-sublime with MIT License 6 votes vote down vote up
def _show_usages(self, data):
        if data is None or data['QuickFixes'] is None:
            return

        usages = data["QuickFixes"]
        items = [[u["Text"].strip(), u["FileName"] + " Line : " + str(u["Line"])] for u in usages]
        window = sublime.active_window()

        def on_done(i):
            if i is not -1:
                window.open_file('{}:{}:{}'.format(usages[i]["FileName"], usages[i]["Line"] or 0, usages[i]["Column"] or 0), sublime.ENCODED_POSITION)

        def on_highlight(i):
            if i is not -1:
                window.open_file('{}:{}:{}'.format(usages[i]["FileName"], usages[i]["Line"] or 0, usages[i]["Column"] or 0), sublime.ENCODED_POSITION | sublime.TRANSIENT)

        window.show_quick_panel(items, on_done, on_highlight=on_highlight) 
Example #8
Source File: focus_editor.py    From Fuse.SublimePlugin with MIT License 6 votes vote down vote up
def tryHandle(self, request):
		if request.name != "FocusEditor":
			return False
		fileName = request.arguments["File"]
		line = request.arguments["Line"]
		column = request.arguments["Column"]
		if not os.path.isfile(fileName):
			self._returnFailure("File '{}' does not exist".format(fileName), request.id)
			return True
		window = self._tryGetWindowFor(request.arguments["Project"])
		if window:
			try:
				window.open_file( "{}:{}:{}".format(fileName, line, column), sublime.ENCODED_POSITION)
				if sublime.platform() == "osx":
					self._focusWindowOSX()
					self.msgManager.sendResponse(self.interop, request.id, "Success")
					return True
				elif sublime.platform() == "windows":
					self.msgManager.sendResponse(self.interop, request.id, "Success", {"FocusHwnd":window.hwnd()})
					return True
			except Exception as e:
				self._returnFailure(str(e), request.id)
				return True
		return False 
Example #9
Source File: navigate_to_method.py    From sublimetext-cfml with MIT License 6 votes vote down vote up
def run(self, file_path, href):

        if len(file_path) > 0:
            index_locations = self.window.lookup_symbol_in_index(href)

            for full_path, project_path, rowcol in index_locations:
                if utils.format_lookup_file_path(full_path) == file_path:
                    row, col = rowcol
                    self.window.open_file(full_path + ":" + str(row) + ":" + str(col), sublime.ENCODED_POSITION | sublime.FORCE_GROUP)
                    break
            else:
                # might be a setter, so for now just open the file
                self.window.open_file(file_path)
        else:
            # this symbol should be in active view
            view = self.window.active_view()
            functions = view.find_by_selector("meta.function.declaration.cfml entity.name.function.cfml")
            for funct_region in functions:
                if view.substr(funct_region).lower() == href.lower():
                    view.sel().clear()
                    r = sublime.Region(funct_region.begin())
                    view.sel().add(r)
                    view.show(r)
                    break 
Example #10
Source File: goto_cfml_file.py    From sublimetext-cfml with MIT License 6 votes vote down vote up
def open_file_at_symbol(view, file_path, symbol):
    index_locations = view.window().lookup_symbol_in_index(symbol)
    if file_path[1] == ":":
        file_path = "/" + file_path[0] + file_path[2:]

    for full_path, project_path, rowcol in index_locations:
        if utils.format_lookup_file_path(full_path) == file_path:
            row, col = rowcol
            view.window().open_file(
                full_path + ":" + str(row) + ":" + str(col),
                sublime.ENCODED_POSITION | sublime.FORCE_GROUP,
            )
            break
    else:
        # if symbol can't be found in the index, go ahead and open the file
        view.window().open_file(file_path) 
Example #11
Source File: goto_definition.py    From sublime-flowtype with MIT License 6 votes vote down vote up
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") 
Example #12
Source File: find_results.py    From BetterFindBuffer with MIT License 5 votes vote down vote up
def run(self, edit):
        view = self.view
        if view.name() == "Find Results":
            for file_name in self.get_files():
                view.window().open_file(file_name, sublime.ENCODED_POSITION) 
Example #13
Source File: find_results.py    From BetterFindBuffer with MIT License 5 votes vote down vote up
def run(self, edit):
        view = self.view
        for sel in view.sel():
            line_no = self.get_line_no(sel)
            file_name = self.get_file(sel)
            if line_no and file_name:
                file_loc = "%s:%s" % (file_name, line_no)
                view.window().open_file(file_loc, sublime.ENCODED_POSITION)
            elif file_name:
                view.window().open_file(file_name) 
Example #14
Source File: go_to_definition.py    From omnisharp-sublime with MIT License 5 votes vote down vote up
def _handle_gotodefinition(self, data):
        if data is None or data['FileName'] is None:
            return

        filename = data['FileName']
        line = data['Line']
        column = data['Column']

        sublime.active_window().open_file(
            '{}:{}:{}'.format(filename, line or 0, column or 0),
            sublime.ENCODED_POSITION) 
Example #15
Source File: inline_diff.py    From GitSavvy with MIT License 5 votes vote down vote up
def open_file(self, window, file_path, line_no, col_no):
        # type: (sublime.Window, str, LineNo, ColNo) -> None
        window.open_file(
            "{file}:{line_no}:{col_no}".format(
                file=file_path,
                line_no=line_no,
                col_no=col_no
            ),
            sublime.ENCODED_POSITION
        ) 
Example #16
Source File: panels.py    From anaconda_go with GNU General Public License v3.0 5 votes vote down vote up
def _jump(self, filename: str, line: int =None,
              col: int =None, transient: bool =False) -> None:
        """Jump to the given destination
        """

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

        sublime.active_window().open_file(
            '{}:{}:{}'.format(filename, line or 0, col or 0), flags)
        self._toggle_indicator(line, col) 
Example #17
Source File: rename.py    From omnisharp-sublime with MIT License 5 votes vote down vote up
def _process_rename(self, edit):
        data = self.data
        for item in data['Changes']:
            filename = item['FileName']
            text = item['Buffer']
            view = sublime.active_window().open_file(
                '{}:0:0'.format(filename),
                sublime.ENCODED_POSITION
            )
            sublime.active_window().run_command("omni_sharp_replace_file",{"args":{'text':item['Buffer'],'filename':filename}})
            
        self.data = None 
Example #18
Source File: open_file_encoded.py    From SublimeScraps with MIT License 5 votes vote down vote up
def run(self, file):
        self.window.open_file(file, sublime.ENCODED_POSITION) 
Example #19
Source File: EasyClangComplete.py    From EasyClangComplete with MIT License 5 votes vote down vote up
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) 
Example #20
Source File: quick_panel_handler.py    From EasyClangComplete with MIT License 5 votes vote down vote up
def on_done(self, idx):
        """Pick this error to navigate to a file."""
        log.debug("Picked idx: %s", idx)
        if idx < 0 or idx >= len(self.errors):
            return None
        return self.view.window().open_file(self.__get_formatted_location(idx),
                                            sublime.ENCODED_POSITION) 
Example #21
Source File: SocketThread.py    From CodeAtlasSublime with Eclipse Public License 1.0 5 votes vote down vote up
def goToPage(self, param):
		print('go to page', param)
		import sublime
		window = sublime.active_window()
		for win in sublime.windows():
			if win.id() == self.windowID:
				window = win
		if window:
			window.open_file('%s:%s:%s'% (param[0], param[1], param[2]+1), sublime.ENCODED_POSITION) 
Example #22
Source File: Completion.py    From YcmdCompletion with MIT License 5 votes vote down vote up
def _completer_cb(self, data, command):
        try:
            jsonResp = loads(data)
        except:
            print(NOTIFY_ERROR_MSG.format("json '{}'".format(data)))
            return
        if command == 'GoTo':
            row = jsonResp.get('line_num', 1)
            col = jsonResp.get('column_num', 1)
            filepath = get_file_path(jsonResp.get('filepath', self.view.file_name()), reverse=True)
            print("[Ycmd][GoTo] file: {}, row: {}, col: {}".format(filepath, row, col))
            sublime.active_window().open_file('{}:{}:{}'.format(filepath, row, col),
                                              sublime.ENCODED_POSITION)
        else:
            print_status("[Ycmd][{}]: {}".format(command, jsonResp.get('message', ''))) 
Example #23
Source File: tern.py    From PhaserSublimePackage with MIT License 5 votes vote down vote up
def run(self, edit, **args):
    if len(jump_stack) > 0:
      sublime.active_window().open_file(jump_stack.pop(), sublime.ENCODED_POSITION) 
Example #24
Source File: plugin.py    From sublime-phpunit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def switch(self):
        def _on_switchable(switchable):
            self.window.open_file(switchable.file_encoded_position(self.view), ENCODED_POSITION)
            put_views_side_by_side(self.view, self.window.active_view())

        find_switchable(self.view, on_select=_on_switchable) 
Example #25
Source File: build_results.py    From Fuse.SublimePlugin with MIT License 5 votes vote down vote up
def run(self, edit):
		view = self.view
		window = view.window()
		sel = view.sel()[0]
		scope = view.scope_name(sel.a)

		if scope.find(".name.") > -1:
			scope = view.extract_scope(sel.a)
			filePath = self.getPath(scope)
			if filePath[0] == '':
				return
				
			window.open_file(filePath[0]+":"+str(filePath[1]), sublime.ENCODED_POSITION)
		else:
			self.openBasedOnNumericLine(window, view, sel) 
Example #26
Source File: build_results.py    From Fuse.SublimePlugin with MIT License 5 votes vote down vote up
def openBasedOnNumericLine(self, window, view, sel):
			foundSelLoc = self.findSelectionLocation(view, sel)
			if foundSelLoc == None:
				return

			if foundRegion != None:
				nameRegions = NameRegions(view)
				for region in nameRegions:
					if region.intersects(foundRegion):
						scope = view.extract_scope(region.a+1)			
						filePath = self.getPath(scope)[0]
						line = view.substr(foundSelLoc)						
						window.open_file(filePath+":" + line, sublime.ENCODED_POSITION)
						break 
Example #27
Source File: go_to_definition.py    From Fuse.SublimePlugin with MIT License 5 votes vote down vote up
def gotoDefinition(data):
	window = sublime.active_window()
	path = data["Path"]
	
	caretPos = data["CaretPosition"]
	line = int(caretPos["Line"])
	column = int(caretPos["Character"])
	openCommand = data["Path"] + ":" + str(line) + ":" + str(column)

	view = window.open_file(openCommand, sublime.ENCODED_POSITION | sublime.TRANSIENT) 
Example #28
Source File: show_commit.py    From GitSavvy with MIT License 5 votes vote down vote up
def load_file_at_line(self, commit_hash, filename, row, col):
        # type: (Optional[str], str, int, int) -> None
        if not commit_hash:
            print("Could not parse commit for its commit hash")
            return
        window = self.view.window()
        if not window:
            return

        full_path = os.path.join(self.repo_path, filename)
        row = self.find_matching_lineno(commit_hash, None, row, full_path)
        window.open_file(
            "{file}:{row}:{col}".format(file=full_path, row=row, col=col),
            sublime.ENCODED_POSITION
        ) 
Example #29
Source File: gotools_goto_def.py    From GoTools with MIT License 5 votes vote down vote up
def godef(self, event):
    # Find and store the current filename and byte offset at the
    # cursor or mouse event location.
    if event:
      filename, row, col, offset = Buffers.location_for_event(self.view, event)
    else:
      filename, row, col, offset, offset_end = Buffers.location_at_cursor(self.view)

    backend = GoToolsSettings.get().goto_def_backend if GoToolsSettings.get().goto_def_backend else ""
    try:
      if backend == "oracle":
        file, row, col = self.get_oracle_location(filename, offset)
      elif backend == "godef":
        file, row, col = self.get_godef_location(filename, offset)
      else:
        Logger.log("Invalid godef backend '" + backend + "' (supported: godef, oracle)")
        Logger.status("Invalid godef configuration; see console log for details")
        return
    except Exception as e:
     Logger.status(str(e))
     return
    
    if not os.path.isfile(file):
      Logger.log("WARN: file indicated by godef not found: " + file)
      Logger.status("godef failed: Please enable debugging and check console log")
      return
    
    Logger.log("opening definition at " + file + ":" + str(row) + ":" + str(col))
    w = self.view.window()
    new_view = w.open_file(file + ':' + str(row) + ':' + str(col), sublime.ENCODED_POSITION)
    group, index = w.get_view_index(new_view)
    if group != -1:
        w.focus_group(group) 
Example #30
Source File: Godef.py    From Godef with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run(self):
        if not self.buf:
            print("[GodefPrev]ERROR: GodefPrev buffer empty")
            return

        filename, startrow, startcol = self.buf.pop()
        path = "{0}:{1}:{2}".format(filename, startrow +1, startcol + 1)
        self.window.open_file(path, sublime.ENCODED_POSITION)
        print("[GodefPrev]INFO: jump prev definition at %s" % path)