def select_configuration( window: sublime.Window, index: int) -> core.awaitable[Optional[Configuration]]: try: configs = all_configurations(window) except Exception as e: core.display(e) show_settings(window) done = core.main_loop.create_future() names = list(map(lambda x: x.name, configs)) + ["-" ] + ["Add configuration"] index = yield from core.sublime_show_quick_panel_async( window, names, index) if index < 0: return None if index >= len(configs): project = window.project_file_name() if project: sublime.run_command("new_window") window = sublime.active_window() window.open_file(project) else: window.run_command( 'edit_settings', {"base_file": "${packages}/sublime_db/debug.sublime-settings"}) return None return configs[index]
def open_location(window: sublime.Window, location: Tuple[str, str, Tuple[int, int]]) -> None: fname, file_path_and_row_col, rowcol = location row, col = rowcol debug("opening location", file_path_and_row_col) window.open_file(file_path_and_row_col, sublime.ENCODED_POSITION | sublime.FORCE_GROUP)
def highlight_entry(window: sublime.Window, locations: List[Tuple[str, str, Tuple[int, int]]], idx: int) -> None: fname, file_path_and_row_col, rowcol = locations[idx] row, col = rowcol window.open_file(file_path_and_row_col, group=window.active_group(), flags=sublime.TRANSIENT | sublime.ENCODED_POSITION | sublime.FORCE_GROUP)
def open_file(window: sublime.Window, file_path: str, flags: int = 0, group: int = -1) -> Promise[Optional[sublime.View]]: """Open a file asynchronously. It is only safe to call this function from the UI thread.""" # window.open_file brings the file to focus if it's already opened, which we don't want. # So we first check if there's already a view for that file. view = window.find_open_file(file_path) if view: return Promise.resolve(view) view = window.open_file(file_path, flags, group) if not view.is_loading(): # It's already loaded. Possibly already open in a tab. return Promise.resolve(view) # Is the view opening right now? Then return the associated unresolved promise for fn, value in opening_files.items(): if fn == file_path or os.path.samefile(fn, file_path): # Return the unresolved promise. A future on_load event will resolve the promise. return value[0] # Prepare a new promise to be resolved by a future on_load event (see the event listener in main.py) def fullfill(resolve: ResolveFunc[Optional[sublime.View]]) -> None: global opening_files # Save the promise in the first element of the tuple -- except we cannot yet do that here opening_files[file_path] = (None, resolve) # type: ignore promise = Promise(fullfill) tup = opening_files[file_path] # Save the promise in the first element of the tuple so that the for-loop above can return it opening_files[file_path] = (promise, tup[1]) return promise
async def sublime_open_file_async(window: sublime.Window, file: str, line: Optional[int] = None) -> sublime.View: view = window.open_file(file) await wait_for_view_to_load(view) if line is None: return view view.show(view.text_point(line, 0), True) return view
async def sublime_open_file_async(window: sublime.Window, file: str, line: int | None = None, column: int | None = None) -> sublime.View: if line: file += f':{line}' if column: file += f':{column}' view = window.open_file(file, sublime.ENCODED_POSITION) await wait_for_view_to_load(view) return view
def agenda_meta_info_get_or_create_view(window: sublime.Window, meta_info: Agenda.AgendaItemMetaInfo): if meta_info.file_name is not None: view = window.find_open_file(meta_info.file_name) if view is not None: return view return window.open_file(meta_info.file_name) for view in window.views(): if view.id() == meta_info.view_id: return view raise ZorgmodeError("Cannot find file for this item")
def sublime_open_file_async(window: sublime.Window, file: str, line: int) -> awaitable[sublime.View]: from sublime_db import ui view = window.open_file(file) if view.is_loading(): future = main_loop.create_future() # FIXME this is terrible handle = ui.Handle(ui.view_loaded, None) #type: ignore def loaded_view(v: sublime.View) -> None: if view == v: future.set_result(view) handle.dispose() handle.callback = loaded_view ui.view_loaded.add_handle(handle) yield from future assert not view.is_loading(), "?? why is this view still loading?" view.show(view.text_point(line, 0), True) return view
def open_location(window: sublime.Window, location: str) -> None: debug("opening location", location) window.open_file(location, sublime.ENCODED_POSITION)
def open_location(window: sublime.Window, location: Location) -> None: uri = location['uri'] r = location['range'] (_, path) = parse_uri(uri) pos = r["start"] if r else {"line": 0, "character": 0} window.open_file(to_encoded_filename(path, pos), sublime.ENCODED_POSITION)