First pass of file decorations
[?]
Dec 28, 2020, 5:26 AM
6ONRFFRGQKTVXAV3URSA2QGMZYSEZBJ7BVMGVWW5M55MY57WFMQQCDependencies
- [2]
HWRWO63PAdd logging of pijul CLI commands - [3]
BIEL6Z5JUpdate resource groups to use custom interface - [4]
B4SKYP3YAdd repository model and add steps to initialize it - [5]
EJYTCVNQAdd stderr to error message when pijul CLI command fails - [6]
IBRKAWNMMoved utility modules into their own folder - [7]
YUVLBWV3Populate resource groups for unrecorded and untracked changes - [8]
ILH3GIVTAdd command centre and refresh/init commands - [9]
ZGMIJNFVCreate pijul.ts for executing commands using the Pijul CLI - [*]
WHQQV5QQAdd watcher to refresh on file system changes - [*]
LUFSQKUVEnable support for experimental decorators - [*]
NCBEWRYEInitialize Repository
Change contents
- edit in src/repository.ts at line 2
import { PijulDecorationProvider } from './decorations'; - edit in src/repository.ts at line 17
private readonly decorationProvider: PijulDecorationProvider; - edit in src/repository.ts at line 90
this.decorationProvider = new PijulDecorationProvider(this);this.disposables.push(this.decorationProvider); - edit in src/pijul.ts at line 36
* @param dotPijul The path to the repository's .pijul directory - replacement in src/pijul.ts at line 37
open (repository: string, dotPijul: string): Repository {return new Repository(this, repository, dotPijul);open (repository: string): Repository {return new Repository(this, repository); - replacement in src/pijul.ts at line 138
private readonly repositoryRoot: string,readonly dotPijul: stringprivate readonly repositoryRoot: string - edit in src/pijul.ts at line 204
** TODO: Fix handling of file deletions - edit in src/extension.ts at line 129
// Pop whitespace only lines off the end - replacement in src/extension.ts at line 141
const repository = new Repository(pijul.open(root, root + '.pijul'), outputChannel);const repository = new Repository(pijul.open(root), outputChannel); - file addition: decorations.ts[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 movesdecorationMap.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());}}