def run(self, edit, **args): history_list.get_jump_history_for_view(self.view).push_selection( self.view) symbol = self.view.substr(self.view.word(self.view.sel()[0])) locs = self.view.window().lookup_symbol_in_index(symbol) locs = [l for l in locs if l[1].endswith(".rs")] if len(locs) > 0: import_path = extract_path(locs[0], symbol) else: import_path = find_common_path(symbol) if import_path is None: return existing_insert_pt = self._existing_insert_point(import_path, edit) if existing_insert_pt is not None: new_import = ", {}".format(import_path[-1]) self.view.insert(edit, existing_insert_pt, new_import) sel_i = existing_insert_pt + 2 else: # insert the new use statement insert_pt = self._new_insert_point(import_path) new_import = "use {};\n".format("::".join(import_path)) self.view.insert(edit, insert_pt, new_import) sel_i = insert_pt + len(new_import) - 2 - len(import_path[-1]) # Select just after the end of the statement sel = self.view.sel() sel.clear() sel.add(sublime.Region(sel_i, sel_i)) # scroll t show it self.view.show(sel_i)
def open_view(location, current_view, flags=sublime.ENCODED_POSITION, force_open=False): ''' Opens a view with the cursor at the specified location. ''' window = sublime.active_window() file_path, _rel_file_path, row_col = location new_row, new_col = row_col # save to jump back history if not current_view.settings().get('is_widget'): get_jump_history_for_view(current_view).push_selection(current_view) v = window.find_open_file(file_path) # force_open fixes freeze when goto definition is triggered # so don't touch it :D if v is not None and not force_open: window.focus_view(v) point = v.text_point(new_row - 1, new_col - 1) sel = v.sel() sel.clear() sel.add(point) v.show_at_center(point) else: window.open_file("{}:{}:{}".format(file_path, new_row, new_col), flags)
def handle_response(self, response: 'Optional[Any]', position: int) -> None: window = sublime.active_window() if response: # Save to jump back history. get_jump_history_for_view(self.view).push_selection(self.view) # TODO: DocumentLink support. location = response if isinstance(response, dict) else response[0] if "targetUri" in location: # TODO: Do something clever with originSelectionRange and targetRange. file_path = uri_to_filename(location["targetUri"]) start = Point.from_lsp( location["targetSelectionRange"]["start"]) else: file_path = uri_to_filename(location["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: sublime.status_message( "Empty response from language server, " "reverting to Sublime's built-in Goto Definition") window.run_command("goto_definition")
def handle_response(self, response: Any) -> None: window = self.view.window() view = self.view if window is None: return if response: # Save to jump back history. get_jump_history_for_view(view).push_selection(view) # TODO: DocumentLink support. if isinstance(response, dict): locations = [location_to_encoded_filename(response)] else: locations = process_response_list(response) if len(locations) == 1: open_location(window, locations[0]) elif len(locations) > 1: window.show_quick_panel(items=locations, on_select=lambda x: select_entry( window, locations, x, view), on_highlight=lambda x: highlight_entry( window, locations, x), flags=sublime.KEEP_OPEN_ON_FOCUS_LOST) # TODO: can add region here. else: sublime.status_message( "Empty response from language server, " "reverting to Sublime's built-in Goto Definition") window.run_command("goto_definition")
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()
def handle_response(self, response: 'Optional[Any]', position) -> None: window = sublime.active_window() if response: # save to jump back history get_jump_history_for_view(self.view).push_selection(self.view) 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")
def run(self, edit, **args): history_list.get_jump_history_for_view(self.view).push_selection( self.view) symbol = self.view.substr(self.view.word(self.view.sel()[0])) # Check exist_point = self._check_exists(edit, symbol) if exist_point: self._select(edit, exist_point) return # Lookup for <Symbol> import_path = self._lookup_symbol(edit, symbol) # Get insert point if import_path: self._insert(edit, import_path, symbol)
def run(self, edit, **args): history_list.get_jump_history_for_view(self.view).push_selection( self.view) # Check exist_point = self._check_exists(edit) if exist_point: self._select(exist_point) return # Get Name name = self._get_module_name() if name: inserted = self._at_top(edit, name) # Select inserted if inserted is not None: self._select(inserted)
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 not file: sublime.status_message("TERN: COULD NOT FIND DEFINITION") return get_jump_history_for_view(self.view).push_selection(self.view) 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)
def handle_response(self, response: Optional[Any], position: int) -> None: def process_response_list( responses: list) -> List[Tuple[str, str, Tuple[int, int]]]: return [process_response(x) for x in responses] def process_response( response: dict) -> Tuple[str, str, Tuple[int, int]]: if "targetUri" in response: # TODO: Do something clever with originSelectionRange and targetRange. file_path = uri_to_filename(response["targetUri"]) start = Point.from_lsp( response["targetSelectionRange"]["start"]) else: file_path = uri_to_filename(response["uri"]) start = Point.from_lsp(response["range"]["start"]) row = start.row + 1 col = start.col + 1 file_path_and_row_col = "{}:{}:{}".format(file_path, row, col) return file_path, file_path_and_row_col, (row, col) 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 select_entry(window: sublime.Window, locations: List[Tuple[str, str, Tuple[int, int]]], idx: int, orig_view: sublime.View) -> None: if idx >= 0: open_location(window, locations[idx]) else: if orig_view: window.focus_view(orig_view) 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) window = sublime.active_window() view = self.view if response: # Save to jump back history. get_jump_history_for_view(view).push_selection(view) # TODO: DocumentLink support. if isinstance(response, dict): locations = [process_response(response)] else: locations = process_response_list(response) if len(locations) == 1: open_location(window, locations[0]) elif len(locations) > 1: window.show_quick_panel(items=[ display_name for file_path, display_name, rowcol in locations ], on_select=lambda x: select_entry( window, locations, x, view), on_highlight=lambda x: highlight_entry( window, locations, x), flags=sublime.KEEP_OPEN_ON_FOCUS_LOST) # TODO: can add region here. else: sublime.status_message( "Empty response from language server, " "reverting to Sublime's built-in Goto Definition") window.run_command("goto_definition")
def add_selection_to_jump_history(view): history_list.get_jump_history_for_view(view).push_selection(view)
def move_to(view, point): # type: (sublime.View, int) -> None history_list.get_jump_history_for_view(view).push_selection(view) view.run_command('_sublime_linter_move_cursor', {'point': point})
def save_position_for_jump_history(view): jump_history = history_list_plugin.get_jump_history_for_view(view) jump_history.push_selection(view)
def push_to_jump_history(view): get_jump_history_for_view(view).push_selection(view)