Skip to content

Tabs

Tab and tab group management.

Tab

Tab(data: dict)

Represents a tab within a tab group.

Initialize a Tab from VS Code data.

Parameters:

Name Type Description Default
data dict

Tab data from VS Code

required
Source code in vscode_sockpuppet/tabs.py
def __init__(self, data: dict):
    """
    Initialize a Tab from VS Code data.

    Args:
        data: Tab data from VS Code
    """
    self.label = data.get("label", "")
    self.is_active = data.get("isActive", False)
    self.is_dirty = data.get("isDirty", False)
    self.is_pinned = data.get("isPinned", False)
    self.is_preview = data.get("isPreview", False)
    self.group_id = data.get("groupId", 0)
    self.input = data.get("input")

__repr__

__repr__() -> str

String representation of the tab.

Source code in vscode_sockpuppet/tabs.py
def __repr__(self) -> str:
    """String representation of the tab."""
    flags = []
    if self.is_active:
        flags.append("active")
    if self.is_dirty:
        flags.append("dirty")
    if self.is_pinned:
        flags.append("pinned")
    if self.is_preview:
        flags.append("preview")
    flag_str = f" [{', '.join(flags)}]" if flags else ""
    return f"Tab({self.label!r}{flag_str})"

TabGroup

TabGroup

TabGroup(data: dict)

Represents a group of tabs.

Initialize a TabGroup from VS Code data.

Parameters:

Name Type Description Default
data dict

Tab group data from VS Code

required
Source code in vscode_sockpuppet/tabs.py
def __init__(self, data: dict):
    """
    Initialize a TabGroup from VS Code data.

    Args:
        data: Tab group data from VS Code
    """
    self.is_active = data.get("isActive", False)
    self.view_column = data.get("viewColumn", 1)
    self.group_id = data.get("groupId", 0)
    self.tabs = [Tab(tab_data) for tab_data in data.get("tabs", [])]

active_tab property

active_tab: Optional[Tab]

Get the active tab in this group.

__repr__

__repr__() -> str

String representation of the tab group.

Source code in vscode_sockpuppet/tabs.py
def __repr__(self) -> str:
    """String representation of the tab group."""
    active_str = " (active)" if self.is_active else ""
    return f"TabGroup(column={self.view_column}, tabs={len(self.tabs)}{active_str})"

TabGroups

TabGroups

TabGroups(client: VSCodeClient)

Manages tab groups in VS Code.

Initialize TabGroups.

Parameters:

Name Type Description Default
client VSCodeClient

The VSCodeClient instance

required
Source code in vscode_sockpuppet/tabs.py
def __init__(self, client: "VSCodeClient"):
    """
    Initialize TabGroups.

    Args:
        client: The VSCodeClient instance
    """
    self.client = client

get_all

get_all() -> list[TabGroup]

Get all tab groups.

Returns:

Type Description
list[TabGroup]

List of all TabGroup instances

Example

tab_groups = window.tab_groups.get_all() for group in tab_groups: print(f"Group {group.view_column}: {len(group.tabs)} tabs")

Source code in vscode_sockpuppet/tabs.py
def get_all(self) -> list[TabGroup]:
    """
    Get all tab groups.

    Returns:
        List of all TabGroup instances

    Example:
        tab_groups = window.tab_groups.get_all()
        for group in tab_groups:
            print(f"Group {group.view_column}: {len(group.tabs)} tabs")
    """
    result = self.client._send_request("window.tabGroups.all")
    return [TabGroup(group_data) for group_data in result.get("groups", [])]

get_active_tab_group

get_active_tab_group() -> Optional[TabGroup]

Get the currently active tab group.

Returns:

Type Description
Optional[TabGroup]

The active TabGroup or None

Example

active_group = window.tab_groups.get_active_tab_group() if active_group: print(f"Active group has {len(active_group.tabs)} tabs")

Source code in vscode_sockpuppet/tabs.py
def get_active_tab_group(self) -> Optional[TabGroup]:
    """
    Get the currently active tab group.

    Returns:
        The active TabGroup or None

    Example:
        active_group = window.tab_groups.get_active_tab_group()
        if active_group:
            print(f"Active group has {len(active_group.tabs)} tabs")
    """
    result = self.client._send_request("window.tabGroups.activeTabGroup")
    group_data = result.get("group")
    return TabGroup(group_data) if group_data else None

close_tab

close_tab(tab: Tab, preserve_focus: bool = False) -> bool

Close a specific tab.

Parameters:

Name Type Description Default
tab Tab

The tab to close

required
preserve_focus bool

Whether to preserve focus

False

Returns:

Type Description
bool

True if successful

Example

groups = window.tab_groups.get_all() for group in groups: for tab in group.tabs: if "test" in tab.label.lower(): window.tab_groups.close_tab(tab)

Source code in vscode_sockpuppet/tabs.py
def close_tab(
    self,
    tab: Tab,
    preserve_focus: bool = False,
) -> bool:
    """
    Close a specific tab.

    Args:
        tab: The tab to close
        preserve_focus: Whether to preserve focus

    Returns:
        True if successful

    Example:
        groups = window.tab_groups.get_all()
        for group in groups:
            for tab in group.tabs:
                if "test" in tab.label.lower():
                    window.tab_groups.close_tab(tab)
    """
    result = self.client._send_request(
        "window.tabGroups.closeTab",
        {
            "groupId": tab.group_id,
            "tabLabel": tab.label,
            "preserveFocus": preserve_focus,
        },
    )
    return result.get("success", False)

close_group

close_group(group: TabGroup, preserve_focus: bool = False) -> bool

Close all tabs in a tab group.

Parameters:

Name Type Description Default
group TabGroup

The tab group to close

required
preserve_focus bool

Whether to preserve focus

False

Returns:

Type Description
bool

True if successful

Example

groups = window.tab_groups.get_all()

Close all groups except the active one

for group in groups: if not group.is_active: window.tab_groups.close_group(group)

Source code in vscode_sockpuppet/tabs.py
def close_group(
    self,
    group: TabGroup,
    preserve_focus: bool = False,
) -> bool:
    """
    Close all tabs in a tab group.

    Args:
        group: The tab group to close
        preserve_focus: Whether to preserve focus

    Returns:
        True if successful

    Example:
        groups = window.tab_groups.get_all()
        # Close all groups except the active one
        for group in groups:
            if not group.is_active:
                window.tab_groups.close_group(group)
    """
    result = self.client._send_request(
        "window.tabGroups.closeGroup",
        {
            "groupId": group.group_id,
            "preserveFocus": preserve_focus,
        },
    )
    return result.get("success", False)

on_did_change_tab_groups

on_did_change_tab_groups(handler: Callable[[TabGroupsChangeEvent], None]) -> Callable[[], None]

Subscribe to tab group changes.

Parameters:

Name Type Description Default
handler Callable[[TabGroupsChangeEvent], None]

Callback function for tab group changes

required

Returns:

Type Description
Callable[[], None]

Dispose function to unsubscribe

Example

def on_groups_changed(data): print("Tab groups changed!") groups = window.tab_groups.get_all() print(f"Now have {len(groups)} groups")

dispose = window.tab_groups.on_did_change_tab_groups( on_groups_changed )

Later: dispose()

Source code in vscode_sockpuppet/tabs.py
def on_did_change_tab_groups(
    self,
    handler: Callable[[TabGroupsChangeEvent], None],
) -> Callable[[], None]:
    """
    Subscribe to tab group changes.

    Args:
        handler: Callback function for tab group changes

    Returns:
        Dispose function to unsubscribe

    Example:
        def on_groups_changed(data):
            print("Tab groups changed!")
            groups = window.tab_groups.get_all()
            print(f"Now have {len(groups)} groups")

        dispose = window.tab_groups.on_did_change_tab_groups(
            on_groups_changed
        )
        # Later: dispose()
    """
    event_name = "window.onDidChangeTabGroups"
    unsubscribe = self.client.add_event_listener(event_name, handler)
    return unsubscribe

on_did_change_tabs

on_did_change_tabs(handler: Callable[[TabsChangeEvent], None]) -> Callable[[], None]

Subscribe to tab changes.

Parameters:

Name Type Description Default
handler Callable[[TabsChangeEvent], None]

Callback function for tab changes

required

Returns:

Type Description
Callable[[], None]

Dispose function to unsubscribe

Example

def on_tabs_changed(data): print("Tabs changed!") active = window.tab_groups.get_active_tab_group() if active and active.active_tab: print(f"Active tab: {active.active_tab.label}")

dispose = window.tab_groups.on_did_change_tabs(on_tabs_changed)

Later: dispose()

Source code in vscode_sockpuppet/tabs.py
def on_did_change_tabs(
    self,
    handler: Callable[[TabsChangeEvent], None],
) -> Callable[[], None]:
    """
    Subscribe to tab changes.

    Args:
        handler: Callback function for tab changes

    Returns:
        Dispose function to unsubscribe

    Example:
        def on_tabs_changed(data):
            print("Tabs changed!")
            active = window.tab_groups.get_active_tab_group()
            if active and active.active_tab:
                print(f"Active tab: {active.active_tab.label}")

        dispose = window.tab_groups.on_did_change_tabs(on_tabs_changed)
        # Later: dispose()
    """
    event_name = "window.onDidChangeTabs"
    unsubscribe = self.client.add_event_listener(event_name, handler)
    return unsubscribe