Example #1
0
def start_window_config(window: sublime.Window, project_path: str, config: ClientConfig,
                        on_created: 'Callable'):
    args, env = get_window_env(window, config)
    config.binary_args = args
    session = create_session(config, project_path, env, settings,
                             on_created=on_created,
                             on_ended=lambda: on_session_ended(window, config.name))
    clients_by_window.setdefault(window.id(), {})[config.name] = session
    debug("{} client registered for window {}".format(config.name, window.id()))
Example #2
0
def update_file_diagnostics(window: sublime.Window, file_path: str,
                            source: str, diagnostics: 'List[Diagnostic]'):
    if diagnostics:
        window_file_diagnostics.setdefault(window.id(), dict()).setdefault(
            file_path, dict())[source] = diagnostics
    else:
        if window.id() in window_file_diagnostics:
            file_diagnostics = window_file_diagnostics[window.id()]
            if file_path in file_diagnostics:
                if source in file_diagnostics[file_path]:
                    del file_diagnostics[file_path][source]
                if not file_diagnostics[file_path]:
                    del file_diagnostics[file_path]
Example #3
0
	def for_window(window: sublime.Window, create: bool = False) -> 'Optional[Debugger]':
		global instances
		instance = Debugger.instances.get(window.id())
		if not instance and create:
			try:
				main = Debugger(window)
				Debugger.instances[window.id()] = main
				return main
			except dap.Error as e:
				core.log_exception()
		if instance and create:
			instance.show()
		return instance
Example #4
0
def start_window_config(window: sublime.Window, project_path: str,
                        config: ClientConfig, on_created: 'Callable'):
    args, env = get_window_env(window, config)
    config.binary_args = args
    session = create_session(
        config,
        project_path,
        env,
        settings,
        on_created=on_created,
        on_ended=lambda: on_session_ended(window, config.name))
    clients_by_window.setdefault(window.id(), {})[config.name] = session
    debug("{} client registered for window {}".format(config.name,
                                                      window.id()))
Example #5
0
    def get(window: sublime.Window, create: bool = False) -> Debugger | None:
        global instances
        id = window.id()
        instance = Debugger.instances.get(id)

        if not instance and create:
            if Debugger.creating.get(id):
                raise core.Error(
                    "We shouldn't be creating another debugger instance for this window..."
                )

            Debugger.creating[id] = True
            try:
                instance = Debugger(window)
                Debugger.instances[id] = instance

            except core.Error as _:
                core.exception()

            Debugger.creating[id] = False

        if instance and create:
            instance.interface.open()

        return instance
Example #6
0
def set_config_ready(window: sublime.Window, project_path: str,
                     config_name: str, client: 'Client'):
    window_configs(window)[config_name] = ConfigState(project_path,
                                                      ClientStates.READY,
                                                      client)
    debug("{} client registered for window {}".format(config_name,
                                                      window.id()))
Example #7
0
def on_session_ended(window: sublime.Window, config_name: str):
    configs = window_configs(window)
    del configs[config_name]
    if not configs:
        debug("all clients unloaded")
        if clients_unloaded_handler:
            clients_unloaded_handler(window.id())
Example #8
0
    def get(window: sublime.Window,
            create: bool = False) -> 'Optional[Debugger]':
        global instances
        id = window.id()
        instance = Debugger.instances.get(id)

        if not instance and create:
            if Debugger.creating.get(id):
                raise core.Error(
                    "We shouldn't be creating another debugger instance for this window..."
                )

            Debugger.creating[id] = True
            try:
                instance = Debugger(window)
                Debugger.instances[id] = instance

            except dap.Error as e:
                core.log_exception()

            Debugger.creating[id] = False

        if instance and create:
            instance.show()

        return instance
Example #9
0
def on_session_ended(window: sublime.Window, config_name: str):
    configs = window_configs(window)
    del configs[config_name]
    if not configs:
        debug("all clients unloaded")
        if clients_unloaded_handler:
            clients_unloaded_handler(window.id())
Example #10
0
def set_create_input_handler(
    window: sublime.Window, create: Callable[[
        sublime.Window, str, str, Callable[[str],
                                           None], Callable[[Optional[str]],
                                                           None]
    ], InputHandler]
) -> None:
    global _create_input_handlers_for_window
    _create_input_handlers_for_window[window.id()] = create
Example #11
0
def update_file_diagnostics(window: sublime.Window, file_path: str, source: str,
                            diagnostics: 'List[Diagnostic]') -> bool:
    updated = False
    if diagnostics:
        file_diagnostics = global_diagnostics.setdefault(window.id(), dict()).setdefault(
            file_path, dict())
        file_diagnostics[source] = diagnostics
        updated = True
    else:
        if window.id() in global_diagnostics:
            window_diagnostics = global_diagnostics[window.id()]
            if file_path in window_diagnostics:
                if source in window_diagnostics[file_path]:
                    updated = True
                    del window_diagnostics[file_path][source]
                if not window_diagnostics[file_path]:
                    del window_diagnostics[file_path]
    return updated
Example #12
0
def create_input_handler_for_window(
        window: sublime.Window, label: str, text: str,
        on_change: Callable[[str],
                            None], on_done: Callable[[Optional[str]],
                                                     None]) -> InputHandler:
    create = _create_input_handlers_for_window.get(window.id())
    if create:
        return create(window, label, text, on_change, on_done)
    return DefaultInputHandler(window, label, text, on_change, on_done)
Example #13
0
def unload_old_clients(window: sublime.Window):
    project_path = get_project_path(window)
    configs = window_configs(window)
    clients_to_unload = {}
    for config_name, state in configs.items():
        if state.client and state.state == ClientStates.READY and state.project_path != project_path:
            debug('unload', config_name, 'project path changed from',
                  state.project_path, 'to', project_path)
            clients_to_unload[config_name] = state.client

    for config_name, client in clients_to_unload.items():
        set_config_stopping(window, config_name)
        unload_client(client, window.id(), config_name)
Example #14
0
def log_server_message(window: sublime.Window, prefix: str,
                       message: str) -> None:
    window_id = window.id()
    if not window.is_valid(
    ) or window_id not in WindowPanelListener.server_log_map:
        return
    WindowPanelListener.server_log_map[window_id].append((prefix, message))
    list_len = len(WindowPanelListener.server_log_map[window_id])
    if list_len >= SERVER_PANEL_MAX_LINES:
        # Trim leading items in the list, leaving only the max allowed count.
        del WindowPanelListener.server_log_map[
            window_id][:list_len - SERVER_PANEL_MAX_LINES]
    panel = ensure_server_panel(window)
    if is_server_panel_open(window) and panel:
        update_server_panel(panel, window_id)
Example #15
0
 def on_new_window(self, window: sublime.Window) -> None:
     self.server_log_map[window.id()] = []
Example #16
0
 def on_pre_close_window(self, window: sublime.Window) -> None:
     self.server_log_map.pop(window.id())
 def create_for_window(window: sublime.Window):
     id = window.id()
     if id in Autocomplete._for_window:
         return Autocomplete._for_window[id]
     r = Autocomplete(id)
     return r
Example #18
0
def remove_window_client(window: sublime.Window, config_name: str):
    del clients_by_window[window.id()][config_name]
Example #19
0
 def maybe_update_server_panel(self, window: sublime.Window) -> None:
     if is_server_panel_open(window):
         panel = ensure_server_panel(window)
         if panel:
             update_server_panel(panel, window.id())
Example #20
0
def clear_document_states(window: sublime.Window):
    if window.id() in document_states:
        del document_states[window.id()]
Example #21
0
def has_document_state(window: sublime.Window, path: str):
    window_id = window.id()
    if window_id not in document_states:
        return False
    return path in document_states[window_id]
Example #22
0
File: clients.py Project: nidev/LSP
def set_config_starting(window: sublime.Window, config_name: str):
    clients_by_window.setdefault(window.id(), {})[config_name] = ConfigState()
Example #23
0
def get_document_state(window: sublime.Window, path: str) -> DocumentState:
    window_document_states = document_states.setdefault(window.id(), {})
    if path not in window_document_states:
        window_document_states[path] = DocumentState(path)
    return window_document_states[path]
Example #24
0
def window_configs(window: sublime.Window) -> 'Dict[str, Session]':
    if window.id() in clients_by_window:
        return clients_by_window[window.id()]
    else:
        # debug("no configs found for window", window.id())
        return {}
Example #25
0
def window_clients(window: sublime.Window) -> 'Dict[str, Client]':
    if window.id() in clients_by_window:
        return clients_by_window[window.id()]
    else:
        # debug("no clients found for window", window.id())
        return {}
Example #26
0
def has_document_state(window: sublime.Window, path: str):
    window_id = window.id()
    if window_id not in document_states:
        return False
    return path in document_states[window_id]
Example #27
0
def window_configs(window: sublime.Window) -> 'Dict[str, Session]':
    if window.id() in clients_by_window:
        return clients_by_window[window.id()]
    else:
        # debug("no configs found for window", window.id())
        return {}
Example #28
0
File: clients.py Project: nidev/LSP
def remove_window_client(window: sublime.Window, config_name: str):
    del clients_by_window[window.id()][config_name]
Example #29
0
def clear_document_state(window: sublime.Window, path: str):
    window_id = window.id()
    if window_id in document_states:
        del document_states[window_id][path]
Example #30
0
def get_window_diagnostics(window: sublime.Window) -> 'Optional[Dict[str, Dict[str, List[Diagnostic]]]]':
    return global_diagnostics.get(window.id())
Example #31
0
def clear_document_states(window: sublime.Window):
    if window.id() in document_states:
        del document_states[window.id()]
Example #32
0
def get_document_state(window: sublime.Window, path: str) -> DocumentState:
    window_document_states = document_states.setdefault(window.id(), {})
    if path not in window_document_states:
        window_document_states[path] = DocumentState(path)
    return window_document_states[path]
Example #33
0
def restart_window_clients(window: sublime.Window):
    clear_document_states(window)
    restarting_window_ids.add(window.id())
    unload_window_clients(window.id())
Example #34
0
def clear_document_state(window: sublime.Window, path: str):
    window_id = window.id()
    if window_id in document_states:
        del document_states[window_id][path]
Example #35
0
def restart_window_clients(window: sublime.Window):
    debug('Restarting clients for window {}'.format(window.id()))
    clear_document_states(window)
    restarting_window_ids.add(window.id())
    unload_window_sessions(window.id())
	def for_window(window: sublime.Window) -> 'Optional[OutputPhantomsPanel]':
		return OutputPhantomsPanel.panels.get(window.id())
Example #37
0
	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)
Example #38
0
def add_window_client(window: sublime.Window, config_name: str, client: 'Client'):
    global clients_by_window
    clients_by_window.setdefault(window.id(), {})[config_name] = client
    debug("{} client registered for window {}".format(config_name, window.id()))
 def for_window(window: sublime.Window):
     id = window.id()
     if id in Autocomplete._for_window:
         return Autocomplete._for_window[id]
     return None