import { TreeDataProvider, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { PijulChannel, Repository } from '../pijul';
/**
* The Channels provider class is a Treedata provider which provides
* TreeData for the `pijul.views.channels` TreeView
*/
export class ChannelsViewProvider implements TreeDataProvider<PijulChannel> {
/**
* Create a new Changelog provider instance
* @param repository
*/
constructor (
private readonly repository: Repository
) {}
/**
* Convert a PijulChannel into a TreeItem
* @param element
*/
getTreeItem (element: PijulChannel): TreeItem | Thenable<TreeItem> {
return {
id: element.name,
label: element.name,
description: element.isCurrent ? 'Current' : undefined,
collapsibleState: TreeItemCollapsibleState.None,
contextValue: 'pijulChannel'
};
}
/**
* Get the children of the element or the root if no element is passed
* @param element An optional element to get the children of
*/
async getChildren (element?: PijulChannel): Promise<PijulChannel[] | null | undefined> {
if (element) {
// Channels don't have children
// TODO: Show the changes in this channel as children
return null;
} else {
return await this.repository.getChannels();
}
}
}