@kkdev92/vscode-ext-kit - v4.1.1
    Preparing search index...

    Class SimpleTreeDataProvider<T>

    A simple tree data provider backed by an in-memory item tree.

    Maintains its own id → item / id → parent / id → children indices, so every lookup (findItem, getParentOf, and the mutators below) is O(1) plus the size of the affected subtree — never a full-tree walk. Mutators refresh only the affected node (see BaseTreeDataProvider.refresh), so unrelated parts of the tree keep their scroll position and expand/collapse state.

    Treat items returned by this provider as read-only and mutate through its methods. The provider exposes stored objects to satisfy the platform contract; external mutation would bypass indices and refresh events.

    const provider = new SimpleTreeDataProvider([
    { id: '1', label: 'Item 1', children: [{ id: '1.1', label: 'Child 1' }] },
    { id: '2', label: 'Item 2' },
    ]);

    module.treeViews.add({ id: 'myext.tree', resolveProvider: () => provider });

    provider.addItem({ id: '1.2', label: 'Child 2' }, '1');
    provider.updateItem('1.1', { label: 'Renamed' });
    provider.removeItem('1.1');

    Type Parameters

    Hierarchy (View Summary)

    Index
    _disposed: boolean = false
    _onDidChangeTreeData: Emitter<T | undefined> = ...

    Emits invalidation requests consumed by the adapter. Protected so a specialized provider can expose richer refresh methods without replacing the public event contract.

    onDidChangeCheckboxState: (
        listener: (changes: TreeCheckboxChange<T>[]) => void,
    ) => PlatformRegistration = ...

    Fires when the user (un)checks a checkbox in the tree. The host bridges the native event for any view declared with module.treeViews.add, so there is nothing to wire up.

    onDidChangeTreeData: (
        listener: (element: T | undefined) => void,
    ) => PlatformRegistration = ...

    Event the platform subscribes to; emit through refresh.

    • Adds an item under the root, or under an existing item when parentId is given. Only the affected parent (or the whole tree, for a new root) is refreshed — sibling nodes keep their expand/collapse and selection state.

      Parameters

      • item: T

        Item to add (may itself carry nested children)

      • OptionalparentId: string

        Existing item id to nest under; omit to add at the root

      Returns boolean

      false if parentId was given but doesn't refer to a known item

    • Adds an item at a chosen position, rather than at the end.

      This is the way to introduce a group that has to stay on top — a "Favorites" node, say — without going through setItems, which rebuilds the tree and collapses all of it.

      Parameters

      • item: T

        Item to add (may itself carry nested children)

      • options: AddItemOptions

        parentId to nest under (omit for the root) and index to insert at; index is clamped to the sibling list, so 0 always means first and anything past the end appends

      Returns boolean

      false if parentId was given but doesn't refer to a known item

      // Keep the favorites group pinned above everything else.
      provider.addItem({ id: 'favorites', label: 'Favorites', children }, { index: 0 });
    • Finds an item by id anywhere in the tree.

      Parameters

      • id: string

        Item id

      Returns T | undefined

      The provider-owned normalized item, or undefined. It is a shallow copy of the object originally supplied.

    • Renders one element.

      An element already is the row's data, so this normalises rather than builds: it fills in the collapsible state and hands back plain data the adapter turns into the platform's TreeItem. Override it to render an element differently from how it is stored.

      Parameters

      • element: T

        Tree item data

      Returns TreeItemLike

    • Refreshes the tree view.

      Passing a specific element (rather than undefined) is the partial-update path: VS Code only re-fetches that element's own getTreeItem() rendering and its children, leaving the rest of the tree's scroll position, selection, and expand/collapse state untouched.

      Parameters

      • Optionalelement: T

        Specific element to refresh, or undefined for the entire tree

      Returns void

    • Removes an item by id, searching the entire tree (not just the root level). Only the removed item's former parent (or the whole tree, for a removed root) is refreshed.

      Parameters

      • id: string

        Item id to remove

      Returns boolean

      false if id doesn't refer to a known item

    • Notifies listeners that the given items' checkbox state changed. The host calls this; an application normally only listens.

      Parameters

      • changes: readonly { checked: boolean; element: T }[]

        The items that were checked or unchecked

      Returns void

    • Replaces the children of parentId (or the roots, when parentId is undefined) wholesale. Only parentId's subtree is refreshed.

      Parameters

      • parentId: string | undefined

        Parent whose children to replace, or undefined for the roots

      • children: T[]

        The new children

      Returns boolean

      false if parentId doesn't refer to a known item

    • Updates an existing item's own display fields in place (not its position or children — use setChildren for that). Refreshes just that item.

      Parameters

      • id: string

        Item id to update

      • patch: Partial<Omit<T, "id" | "children">>

        Fields to merge into the existing item

      Returns boolean

      false if id doesn't refer to a known item