Add tree view for channels
[?]
Jan 5, 2021, 12:52 AM
VT237HUJI7DE5XLXAR4JARCOFOGC2WRGQWB3RJYAGGWNM36UDP3QCDependencies
- [2]
L3VOQYAFAdd changelog view to the source control panel - [*]
B4SKYP3YAdd repository model and add steps to initialize it - [*]
ZGMIJNFVCreate pijul.ts for executing commands using the Pijul CLI - [*]
L44OILGKAdd reset command to resource state context menu - [*]
NCBEWRYEInitialize Repository
Change contents
- file addition: channels.ts[2.8]
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 childrenreturn null;} else {return await this.repository.getChannels();}}} - edit in src/repository.ts at line 8
import { ChannelsViewProvider } from './views/channels'; - edit in src/repository.ts at line 110
this.disposables.push(window.registerTreeDataProvider('pijul.views.channels', new ChannelsViewProvider(this.repository))); - edit in src/pijul.ts at line 339
}/*** Use the `pijul channel` command and parse the results* to generate the list of channels in this repository.*/async getChannels (): Promise<PijulChannel[]> {// TODO: Test how this scales to repositories with thousands or hundreds of thousands of changesconst result = await this._pijul.exec(this.repositoryRoot, ['channel']);const lines = result.stdout.split(/\r?\n/);const channels = lines.map((line) => {return new PijulChannel(line.substring(2), line.startsWith('*'));});return channels; - edit in src/pijul.ts at line 459
* @param author The author of the change* @param date The date the change was made - edit in src/pijul.ts at line 501[5.7481]
/*** Class representing a channel in the repository.*/export class PijulChannel {/*** Create a new instance of a Pijul change object.* @param name The change hash* @param isCurrent Indicates if the channel is the default channel*/constructor (public readonly name: string,public readonly isCurrent: boolean) {}} - edit in package.json at line 286
"contextualTitle": "Pijul","visibility": "visible"},{"id": "pijul.views.channels","name": "Channels",