Skip to content

Events

Event subscription system for monitoring VS Code state changes.

WindowEvents

WindowEvents

WindowEvents(client: VSCodeClient)

Event emitters for window-related VS Code events.

Provides VS Code-style event subscription with on_did_* methods.

Initialize window events.

Source code in vscode_sockpuppet/events/window.py
def __init__(self, client: VSCodeClient):
    """Initialize window events."""
    self._client = client

on_did_change_active_text_editor property

on_did_change_active_text_editor: Event

Event fired when the active text editor changes.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(editor): if editor: print(f"Active editor: {editor['fileName']}")

dispose = window.on_did_change_active_text_editor(handler)

on_did_change_text_editor_selection property

on_did_change_text_editor_selection: Event

Event fired when the selection in an editor changes.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(data): sel = data['selections'][0] print(f"Line {sel['start']['line']}")

dispose = window.on_did_change_text_editor_selection(handler)

on_did_change_visible_text_editors property

on_did_change_visible_text_editors: Event

Event fired when the visible text editors change.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(data): print(f"{data['count']} editors visible")

dispose = window.on_did_change_visible_text_editors(handler)

on_did_open_terminal property

on_did_open_terminal: Event

Event fired when a terminal is opened.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(terminal): print(f"Terminal opened: {terminal['name']}")

dispose = window.on_did_open_terminal(handler)

on_did_close_terminal property

on_did_close_terminal: Event

Event fired when a terminal is closed.

Returns:

Type Description
Event

Event that can be called with a handler

Example

dispose = window.on_did_close_terminal(handler)

on_did_change_terminal_state property

on_did_change_terminal_state: Event

Event fired when a terminal's state changes.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(data): print(f"Terminal {data['name']}: interacted = {data['isInteractedWith']}")

dispose = window.on_did_change_terminal_state(handler)

on_did_change_text_editor_visible_ranges property

on_did_change_text_editor_visible_ranges: Event

Event fired when visible ranges in an editor change (scrolling).

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(data): print(f"Visible in {data['uri']}: {len(data['visibleRanges'])} ranges")

dispose = window.on_did_change_text_editor_visible_ranges(handler)

on_did_change_text_editor_options property

on_did_change_text_editor_options: Event

Event fired when text editor options change.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(data): opts = data['options'] print(f"Tab size: {opts['tabSize']}")

dispose = window.on_did_change_text_editor_options(handler)

on_did_change_text_editor_view_column property

on_did_change_text_editor_view_column: Event

Event fired when an editor's view column changes.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(data): print(f"Editor moved to column {data['viewColumn']}")

dispose = window.on_did_change_text_editor_view_column(handler)

on_did_change_window_state property

on_did_change_window_state: Event

Event fired when the window state changes (focus).

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(data): if data['focused']: print("Window gained focus") else: print("Window lost focus")

dispose = window.on_did_change_window_state(handler)

WorkspaceEvents

WorkspaceEvents

WorkspaceEvents(client: VSCodeClient)

Event emitters for workspace-related VS Code events.

Provides VS Code-style event subscription with on_did_* methods.

Initialize workspace events.

Source code in vscode_sockpuppet/events/workspace.py
def __init__(self, client: VSCodeClient):
    """Initialize workspace events."""
    self._client = client

on_did_open_text_document property

on_did_open_text_document: Event

Event fired when a text document is opened.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(document): print(f"Opened: {document['fileName']}")

dispose = workspace.on_did_open_text_document(handler)

on_did_close_text_document property

on_did_close_text_document: Event

Event fired when a text document is closed.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(document): print(f"Closed: {document['fileName']}")

dispose = workspace.on_did_close_text_document(handler)

on_did_save_text_document property

on_did_save_text_document: Event

Event fired when a text document is saved.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(document): print(f"Saved: {document['fileName']}")

dispose = workspace.on_did_save_text_document(handler)

on_did_change_text_document property

on_did_change_text_document: Event

Event fired when a text document changes.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(event): print(f"Changed: {event['uri']}") for change in event['contentChanges']: print(f" Text: {change['text']}")

dispose = workspace.on_did_change_text_document(handler)

on_did_change_workspace_folders property

on_did_change_workspace_folders: Event

Event fired when workspace folders are added or removed.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(event): print(f"Added: {len(event['added'])}") print(f"Removed: {len(event['removed'])}")

dispose = workspace.on_did_change_workspace_folders(handler)

on_did_change_configuration property

on_did_change_configuration: Event

Event fired when the configuration changes.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(event): print("Configuration changed")

dispose = workspace.on_did_change_configuration(handler)

on_did_create_files property

on_did_create_files: Event

Event fired when files are created.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(data): for file in data['files']: print(f"Created: {file['uri']}")

dispose = workspace.on_did_create_files(handler)

on_did_delete_files property

on_did_delete_files: Event

Event fired when files are deleted.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(data): for file in data['files']: print(f"Deleted: {file['uri']}")

dispose = workspace.on_did_delete_files(handler)

on_did_rename_files property

on_did_rename_files: Event

Event fired when files are renamed or moved.

Returns:

Type Description
Event

Event that can be called with a handler

Example

def handler(data): for file in data['files']: print(f"Renamed: {file['oldUri']} -> {file['newUri']}")

dispose = workspace.on_did_rename_files(handler)