def _project_configurations(window: sublime.Window) -> List[Configuration]: configs = get_setting(window.active_view(), 'configurations') if not configs: return [] assert isinstance(configs, list), 'expected [] for debug.configurations' return _get_configurations(configs)
def get_project_path(window: sublime.Window) -> 'Optional[str]': """ Returns the common root of all open folders in the window """ if len(window.folders()): folder_paths = window.folders() return folder_paths[0] else: view = window.active_view() if view: filename = view.file_name() if filename: project_path = os.path.dirname(filename) debug( "Couldn't determine project directory since no folders are open!", "Using", project_path, "as a fallback.") return project_path else: debug( "Couldn't determine project directory since no folders are open", "and the current file isn't saved on the disk.") return None else: debug("No view is active in current window") return None # https://github.com/tomv564/LSP/issues/219
def __init__(self, window: sublime.Window, on_changed: Callable[[], None]): self.window = window self.settings_changed_callback = None self.on_changed = on_changed self.on_view_updated = ui.view_activated.add( self.on_update_settings_view) view = window.active_view() if view: self.update(view)
def on_start(cls, window: sublime.Window) -> bool: if cls.manages_server(): server = cls.get_server() if server is None or server.get_status() != ServerStatus.READY: log_and_show_message('{}: Server not ready'.format(cls.get_displayed_name())) return False startup_view = window.active_view() workspace_folders = [WorkspaceFolder.from_path(folder) for folder in window.folders()] message = cls.is_allowed_to_start(window, startup_view, workspace_folders) if message: log_and_show_message('{}: {}'.format(cls.get_displayed_name(), message)) return False return True
def _handle_open_rule_description(self, session: Session, window: sublime.Window, args: List[str], done: Callable[[], None]) -> bool: view = window.active_view() file_name = view.file_name() language_id = "text" if file_name: uri = filename_to_uri(file_name) sb = session.get_session_buffer_for_uri_async(uri) if sb: language_id = sb.language_id parser = HTMLParser(language_id) parser.feed("<p><i>{}</i></p>{}".format(args[1], args[2])) mdpopups.new_html_sheet(window=window, name=args[0], contents=parser.result, css=css().sheets, wrapper_class=css().sheets_classname, flags=sublime.ADD_TO_SELECTION_SEMI_TRANSIENT) done() return True
def __init__(self, window: sublime.Window) -> None: self.window = window try: self.__data = window.project_data()["settings"]["cmake"] except Exception: default = get_setting(window.active_view(), "default_build_folder", "$folder/build") self.__data = {"build_folder": default} self.unexpanded_build_folder = self.__get_val( "build_folder") # type: str self.__data = expand(window, self.__data) self.build_folder = self.__get_val("build_folder") # type: str self.working_dir = self.__get_val("root_folder") # type: str if self.working_dir: self.working_dir = realpath(self.working_dir) else: try: self.working_dir = window.extract_variables()["folder"] except KeyError: self.working_dir = "" if not isfile(join(self.working_dir, "CMakeLists.txt")): raise FileNotFoundError()
def get_project_path(window: sublime.Window) -> 'Optional[str]': """ Returns the common root of all open folders in the window """ if len(window.folders()): folder_paths = window.folders() return folder_paths[0] else: view = window.active_view() if view: filename = view.file_name() if filename: project_path = os.path.dirname(filename) debug("Couldn't determine project directory since no folders are open!", "Using", project_path, "as a fallback.") return project_path else: debug("Couldn't determine project directory since no folders are open", "and the current file isn't saved on the disk.") return None else: debug("No view is active in current window") return None # https://github.com/tomv564/LSP/issues/219
def sample_one_error(window: sublime.Window) -> "Optional[str]": # Samples one error for the nice help message for the TextInputHandler. # We take the store in `sublime_linter` bc that's the one that only holds # *filtered* errors. We do the sorting to *prioritize* errors from the # active view or at least current window. view = window.active_view() top_filename = canonical_filename(view) if view else '' other_filenames = {canonical_filename(view) for view in window.views()} def key_fn(filename_errors): filename, _ = filename_errors return ('a' if filename == top_filename else 'b' if filename in other_filenames else 'c') for filename, errors in sorted(persist.file_errors.items(), key=key_fn): if not errors: continue error = errors[0] return format_error(error) else: return None
def __init__(self, window: sublime.Window) -> None: print('new Main for window', window.id()) self.window = window self.disposeables = [] #type: List[Any] self.breakpoints = Breakpoints() self.view = None #type: Optional[sublime.View] self.eventLog = EventLogComponent() self.variablesComponent = VariablesComponent() self.callstackComponent = CallStackComponent() self.debuggerComponent = DebuggerComponent(self.breakpoints, self) self.debugAdapterClient = None #type: Optional[DebugAdapterClient] self.selectedFrameComponent = None #type: Optional[ui.Phantom] self.breakpointInformation = None #type: Optional[ui.Phantom] self.pausedWithError = False self.process = None #type: Optional[Process] self.disconnecting = False self.project_name = window.project_file_name() or "user" data = config.persisted_for_project(self.project_name) config_name = data.get('config_name') config_maybe_at_index = data.get('config_maybe_at_index') for bp in data.get('breakpoints', []): self.breakpoints.add(Breakpoint.from_json(bp)) if config_name: self.configuration = get_configuration_for_name(window, config_name, config_maybe_at_index) else: self.configuration = None if self.configuration: self.debuggerComponent.set_name(self.configuration.name) else: self.debuggerComponent.set_name('select config') self.stopped_reason = '' self.path = window.project_file_name() if self.path: self.path = os.path.dirname(self.path) self.eventLog.Add('Opened In Workspace: {}'.format(self.path)) else: self.eventLog.AddStderr('warning: debugger opened in a window that is not part of a project') print('Creating a window: h') self.disposeables.extend([ ui.view_gutter_hovered.add(self.on_gutter_hovered), ui.view_text_hovered.add(self.on_text_hovered), ui.view_drag_select.add(self.on_drag_select), ]) mode = get_setting(window.active_view(), 'display') if mode == 'window': sublime.run_command("new_window") new_window = sublime.active_window() output = new_window.new_file() new_window.set_minimap_visible(False) new_window.set_sidebar_visible(False) new_window.set_tabs_visible(False) new_window.set_menu_visible(False) new_window.set_status_bar_visible(False) elif mode == 'view': output = self.window.new_file() elif mode == 'output': output = self.window.create_output_panel('debugger') self.window.run_command('show_panel', { 'panel': 'output.debugger' }) else: core.display('expected setting "mode" to be one of "window", "view" or "output", found "{}"'.format(mode)) return output.run_command('insert', { 'characters': " " }) output.set_scratch(True) output.set_read_only(True) output.set_name('Debugger') view_settings = output.settings() view_settings.set("is_widget", True) view_settings.set("gutter", False) view_settings.set("margin", 0) view_settings.set("always_show_minimap_viewport", False) self.view = output self.disposeables.extend([ ui.Phantom(self.debuggerComponent, output, sublime.Region(1, 1), sublime.LAYOUT_INLINE), ui.Phantom(self.callstackComponent, output, sublime.Region(1, 2), sublime.LAYOUT_INLINE), ui.Phantom(self.variablesComponent, output, sublime.Region(1, 3), sublime.LAYOUT_INLINE), ui.Phantom(self.eventLog, output, sublime.Region(1, 4), sublime.LAYOUT_INLINE) ]) self.breakpoints.onRemovedBreakpoint.add(lambda b: self.clearBreakpointInformation()) self.breakpoints.onChangedBreakpoint.add(self.onChangedBreakpoint) self.breakpoints.onChangedFilter.add(self.onChangedFilter) self.breakpoints.onSelectedBreakpoint.add(self.onSelectedBreakpoint)
def on_post_window_command(self, window: sublime.Window, command_name: str, args: Optional[Dict[str, Any]]) -> None: if command_name in ("next_result", "prev_result"): view = window.active_view() if view: view.run_command("lsp_hover", {"only_diagnostics": True})