First pass of file decorations

[?]
Dec 28, 2020, 5:26 AM
6ONRFFRGQKTVXAV3URSA2QGMZYSEZBJ7BVMGVWW5M55MY57WFMQQC

Dependencies

  • [2] HWRWO63P Add logging of pijul CLI commands
  • [3] BIEL6Z5J Update resource groups to use custom interface
  • [4] B4SKYP3Y Add repository model and add steps to initialize it
  • [5] EJYTCVNQ Add stderr to error message when pijul CLI command fails
  • [6] IBRKAWNM Moved utility modules into their own folder
  • [7] YUVLBWV3 Populate resource groups for unrecorded and untracked changes
  • [8] ILH3GIVT Add command centre and refresh/init commands
  • [9] ZGMIJNFV Create pijul.ts for executing commands using the Pijul CLI
  • [*] WHQQV5QQ Add watcher to refresh on file system changes
  • [*] LUFSQKUV Enable support for experimental decorators
  • [*] NCBEWRYE Initialize Repository

Change contents

  • edit in src/repository.ts at line 2
    [3.134]
    [4.122]
    import { PijulDecorationProvider } from './decorations';
  • edit in src/repository.ts at line 17
    [3.448]
    [11.197]
    private readonly decorationProvider: PijulDecorationProvider;
  • edit in src/repository.ts at line 90
    [4.1]
    [4.1]
    this.decorationProvider = new PijulDecorationProvider(this);
    this.disposables.push(this.decorationProvider);
  • edit in src/pijul.ts at line 36
    [4.1001][4.1001:1068]()
    * @param dotPijul The path to the repository's .pijul directory
  • replacement in src/pijul.ts at line 37
    [4.1074][4.1074:1189]()
    open (repository: string, dotPijul: string): Repository {
    return new Repository(this, repository, dotPijul);
    [4.1074]
    [4.1189]
    open (repository: string): Repository {
    return new Repository(this, repository);
  • replacement in src/pijul.ts at line 138
    [4.4421][4.4421:4496]()
    private readonly repositoryRoot: string,
    readonly dotPijul: string
    [4.4421]
    [4.4496]
    private readonly repositoryRoot: string
  • edit in src/pijul.ts at line 204
    [12.436]
    [4.2721]
    *
    * TODO: Fix handling of file deletions
  • edit in src/extension.ts at line 129
    [2.168]
    [2.168]
    // Pop whitespace only lines off the end
  • replacement in src/extension.ts at line 141
    [4.2031][4.2031:2120]()
    const repository = new Repository(pijul.open(root, root + '.pijul'), outputChannel);
    [4.2031]
    [4.4094]
    const repository = new Repository(pijul.open(root), outputChannel);
  • file addition: decorations.ts (-xw-x--x--)
    [13.104980]
    import { Disposable, Event, EventEmitter, FileDecoration, FileDecorationProvider, Uri, window } from 'vscode';
    import { Repository } from './repository';
    import { PijulResourceGroup } from './resource';
    /**
    * A decoration provider which tells VS Code how to decorate the files in a Pijul repository
    */
    export class PijulDecorationProvider implements FileDecorationProvider {
    private readonly onDidChangeDecorationsEmitter = new EventEmitter<Uri[]>();
    readonly onDidChangeFileDecorations: Event<Uri[]> = this.onDidChangeDecorationsEmitter.event;
    private readonly disposables: Disposable[] = [];
    private decorations = new Map<string, FileDecoration>();
    constructor (private readonly repository: Repository) {
    this.disposables.push(
    window.registerFileDecorationProvider(this),
    repository.onDidRefreshStatus(this.onDidRefreshStatus, this)
    );
    }
    /**
    * Event listener that is triggered when the Pijul repo state is refreshed
    */
    private onDidRefreshStatus (): void {
    const newDecorations = new Map<string, FileDecoration>();
    this.collectDecorationData(this.repository.changedGroup, newDecorations);
    this.collectDecorationData(this.repository.untrackedGroup, newDecorations);
    const uris = new Set([...this.decorations.keys()].concat([...newDecorations.keys()]));
    this.decorations = newDecorations;
    this.onDidChangeDecorationsEmitter.fire([...uris.values()].map(value => Uri.parse(value, true)));
    }
    /**
    * Take the decoration data from each item in a resource group and add it to the decorationMap
    * @param group The resource group decoration data will be taken from
    * @param decorationMap The decoration map the decoration data will be added to
    */
    private collectDecorationData (group: PijulResourceGroup, decorationMap: Map<string, FileDecoration>): void {
    for (const resource of group.resourceStates) {
    // TODO: Better handling of moves
    decorationMap.set(resource.resourceUri.toString(), resource.resourceDecoration);
    }
    }
    /**
    * Interface function which provides decorations to VS Code by looking up the file
    * URI in the decoration map.
    * @param uri The URI of the file VS Code is looking up decorations for
    */
    provideFileDecoration (uri: Uri): FileDecoration | undefined {
    return this.decorations.get(uri.toString());
    }
    /**
    * Dispose of all of the disposable resources
    */
    dispose (): void {
    this.disposables.forEach(d => d.dispose());
    }
    }