deco - update decorations when gitignore-file changes

This commit is contained in:
Johannes Rieken
2017-10-18 10:06:02 +02:00
parent b2f4ba4dd7
commit ca2c107324
4 changed files with 23 additions and 11 deletions

View File

@@ -5,10 +5,11 @@
'use strict';
import { window, Uri, Disposable, Event, EventEmitter, DecorationData, DecorationProvider, ThemeColor } from 'vscode';
import { window, workspace, Uri, Disposable, Event, EventEmitter, DecorationData, DecorationProvider, ThemeColor } from 'vscode';
import { Repository, GitResourceGroup } from './repository';
import { Model } from './model';
import { debounce } from './decorators';
import { filterEvent } from './util';
class GitIgnoreDecorationProvider implements DecorationProvider {
@@ -20,8 +21,9 @@ class GitIgnoreDecorationProvider implements DecorationProvider {
constructor(private repository: Repository) {
this.disposables.push(
window.registerDecorationProvider(this, '.gitignore')
//todo@joh -> events when the ignore status actually changes, not when the file changes
window.registerDecorationProvider(this, '.gitignore'),
filterEvent(workspace.onDidSaveTextDocument, e => e.fileName.endsWith('.gitignore'))(_ => this._onDidChangeDecorations.fire())
//todo@joh -> events when the ignore status actually changes, not only when the file changes
);
}

View File

@@ -182,7 +182,7 @@ declare module 'vscode' {
}
export interface DecorationProvider {
onDidChangeDecorations: Event<Uri | Uri[]>;
onDidChangeDecorations: Event<undefined | Uri | Uri[]>;
provideDecoration(uri: Uri, token: CancellationToken): ProviderResult<DecorationData>;
}

View File

@@ -28,7 +28,7 @@ export class ExtHostDecorations implements ExtHostDecorationsShape {
this._proxy.$registerDecorationProvider(handle, label);
const listener = provider.onDidChangeDecorations(e => {
this._proxy.$onDidChange(handle, Array.isArray(e) ? e : [e]);
this._proxy.$onDidChange(handle, !e ? null : Array.isArray(e) ? e : [e]);
});
return new Disposable(() => {

View File

@@ -221,12 +221,21 @@ class DecorationProviderWrapper {
constructor(
private readonly _provider: IDecorationsProvider,
private readonly _emitter: Emitter<URI | URI[]>
private readonly _uriEmitter: Emitter<URI | URI[]>,
private readonly _flushEmitter: Emitter<IResourceDecorationChangeEvent>
) {
this._dispoable = this._provider.onDidChange(uris => {
for (const uri of uris) {
this.data.delete(uri.toString());
this._fetchData(uri);
if (!uris) {
// flush event -> drop all data, can affect everything
this.data.clear();
this._flushEmitter.fire({ affectsResource() { return true; } });
} else {
// selective changes -> drop for resource, fetch again, send event
for (const uri of uris) {
this.data.delete(uri.toString());
this._fetchData(uri);
}
}
});
}
@@ -293,7 +302,7 @@ class DecorationProviderWrapper {
private _keepItem(uri: URI, data: IDecorationData): IDecorationData {
let deco = data ? data : null;
this.data.set(uri.toString(), deco);
this._emitter.fire(uri);
this._uriEmitter.fire(uri);
return deco;
}
}
@@ -345,7 +354,8 @@ export class FileDecorationsService implements IDecorationsService {
const wrapper = new DecorationProviderWrapper(
provider,
this._onDidChangeDecorationsDelayed
this._onDidChangeDecorationsDelayed,
this._onDidChangeDecorations
);
const remove = this._data.push(wrapper);