Protected_Protected Readonly_Emits invalidation requests consumed by the adapter. Protected so a specialized provider can expose richer refresh methods without replacing the public event contract.
ReadonlyonFires 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.
ReadonlyonEvent 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.
Item to add (may itself carry nested children)
OptionalparentId: string
Existing item id to nest under; omit to add at the root
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.
Item to add (may itself carry nested children)
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
false if parentId was given but doesn't refer to a known item
Clears the internal child cache without emitting an invalidation event. Call refresh when the platform must immediately query again.
Releases emitters and cached data. Idempotent through the emitter implementation; subsequent child reads return an empty list.
Finds an item by id anywhere in the tree.
Item id
The provider-owned normalized item, or undefined. It is a shallow copy of the object originally supplied.
Returns children directly from the internal index — bypassing BaseTreeDataProvider's cache, which would otherwise duplicate data this class already indexes in O(1) lookups.
Optionalelement: TGets the root elements of the tree. Override this method to provide root items.
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.
Tree item data
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.
Optionalelement: T
Specific element to refresh, or undefined for the entire tree
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.
Item id to remove
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.
The items that were checked or unchecked
Replaces the children of parentId (or the roots, when parentId is
undefined) wholesale. Only parentId's subtree is refreshed.
Parent whose children to replace, or undefined for the roots
The new children
false if parentId doesn't refer to a known item
Replaces the entire tree and refreshes it in full — there is no single element to scope a partial refresh to when every root is being replaced. Use setChildren, addItem, updateItem, or removeItem for localized changes.
New tree items
Updates an existing item's own display fields in place (not its
position or children — use setChildren for that). Refreshes
just that item.
Item id to update
Fields to merge into the existing item
false if id doesn't refer to a known item
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.
Example