Add tree view for channels

[?]
Jan 5, 2021, 12:52 AM
VT237HUJI7DE5XLXAR4JARCOFOGC2WRGQWB3RJYAGGWNM36UDP3QC

Dependencies

  • [2] L3VOQYAF Add changelog view to the source control panel
  • [*] B4SKYP3Y Add repository model and add steps to initialize it
  • [*] ZGMIJNFV Create pijul.ts for executing commands using the Pijul CLI
  • [*] L44OILGK Add reset command to resource state context menu
  • [*] NCBEWRYE Initialize Repository

Change contents

  • file addition: channels.ts (-xw-x--x--)
    [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 children
    return null;
    } else {
    return await this.repository.getChannels();
    }
    }
    }
  • edit in src/repository.ts at line 8
    [2.1326]
    [4.229]
    import { ChannelsViewProvider } from './views/channels';
  • edit in src/repository.ts at line 110
    [2.1450]
    [2.1450]
    this.disposables.push(window.registerTreeDataProvider('pijul.views.channels', new ChannelsViewProvider(this.repository)));
  • edit in src/pijul.ts at line 339
    [2.2277]
    [6.763]
    }
    /**
    * 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 changes
    const 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
    [2.2512]
    [2.2512]
    * @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
    [2.2785]
    [2.2785]
    "contextualTitle": "Pijul",
    "visibility": "visible"
    },
    {
    "id": "pijul.views.channels",
    "name": "Channels",