Browse Source

Fixes updating CodeLens after file save

Fixes updating active line annotations after file save
main
Eric Amodio 8 years ago
parent
commit
964cfd363e
3 changed files with 48 additions and 16 deletions
  1. +6
    -0
      src/blameStatusBarController.ts
  2. +11
    -1
      src/gitCodeLensProvider.ts
  3. +31
    -15
      src/gitProvider.ts

+ 6
- 0
src/blameStatusBarController.ts View File

@ -34,6 +34,7 @@ export default class BlameStatusBarController extends Disposable {
const subscriptions: Disposable[] = [];
subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigure, this));
subscriptions.push(git.onDidRemoveCacheEntry(this._onRemoveCacheEntry, this));
this._disposable = Disposable.from(...subscriptions);
}
@ -98,6 +99,11 @@ export default class BlameStatusBarController extends Disposable {
this._onActiveTextEditorChanged(window.activeTextEditor);
}
private _onRemoveCacheEntry() {
this._blame = undefined;
this._onActiveTextEditorChanged(window.activeTextEditor);
}
private async _onActiveTextEditorChanged(e: TextEditor): Promise<void> {
const previousEditor = this._editor;
previousEditor && previousEditor.setDecorations(activeLineDecoration, []);

+ 11
- 1
src/gitCodeLensProvider.ts View File

@ -1,6 +1,6 @@
'use strict';
import { Functions, Iterables, Strings } from './system';
import { CancellationToken, CodeLens, CodeLensProvider, commands, DocumentSelector, ExtensionContext, Position, Range, SymbolInformation, SymbolKind, TextDocument, Uri, workspace } from 'vscode';
import { CancellationToken, CodeLens, CodeLensProvider, commands, DocumentSelector, Event, EventEmitter, ExtensionContext, Position, Range, SymbolInformation, SymbolKind, TextDocument, Uri, workspace } from 'vscode';
import { BuiltInCommands, Commands, DocumentSchemes } from './constants';
import { CodeLensCommand, CodeLensLocation, IConfig, ICodeLensLanguageLocation } from './configuration';
import GitProvider, { GitCommit, GitUri, IGitBlame, IGitBlameLines } from './gitProvider';
@ -31,6 +31,11 @@ export class GitAuthorsCodeLens extends CodeLens {
export default class GitCodeLensProvider implements CodeLensProvider {
private _onDidChangeCodeLensesEmitter = new EventEmitter<void>();
public get onDidChangeCodeLenses(): Event<void> {
return this._onDidChangeCodeLensesEmitter.event;
}
static selector: DocumentSelector = { scheme: DocumentSchemes.File };
private _config: IConfig;
@ -39,6 +44,11 @@ export default class GitCodeLensProvider implements CodeLensProvider {
this._config = workspace.getConfiguration('').get<IConfig>('gitlens');
}
reset() {
Logger.log('Triggering a reset of the git CodeLens provider');
this._onDidChangeCodeLensesEmitter.fire();
}
async provideCodeLenses(document: TextDocument, token: CancellationToken): Promise<CodeLens[]> {
let languageLocations = this._config.codeLens.languageLocations.find(_ => _.language.toLowerCase() === document.languageId);
if (languageLocations == null) {

+ 31
- 15
src/gitProvider.ts View File

@ -1,6 +1,6 @@
'use strict';
import { Functions, Iterables, Objects } from './system';
import { Disposable, ExtensionContext, languages, Location, Position, Range, TextDocument, TextEditor, Uri, workspace } from 'vscode';
import { /*Functions,*/ Iterables, Objects } from './system';
import { Disposable, Event, EventEmitter, ExtensionContext, languages, Location, Position, Range, TextDocument, TextEditor, Uri, workspace } from 'vscode';
import { CodeLensVisibility, IConfig } from './configuration';
import { DocumentSchemes, WorkspaceState } from './constants';
import Git, { GitBlameParserEnricher, GitBlameFormat, GitCommit, GitLogParserEnricher, IGitAuthor, IGitBlame, IGitBlameLine, IGitBlameLines, IGitLog } from './git/git';
@ -41,20 +41,25 @@ interface ICachedLog extends ICachedItem { }
enum RemoveCacheReason {
DocumentClosed,
DocumentSaved,
DocumentChanged
DocumentSaved
}
export default class GitProvider extends Disposable {
private _onDidRemoveCacheEntryEmitter = new EventEmitter<void>();
get onDidRemoveCacheEntry(): Event<void> {
return this._onDidRemoveCacheEntryEmitter.event;
}
private _gitCache: Map<string, GitCacheEntry> | undefined;
private _cacheDisposable: Disposable | undefined;
private _repoPath: string;
private _uriCache: Map<string, UriCacheEntry> | undefined;
config: IConfig;
private _disposable: Disposable;
private _codeLensProvider: GitCodeLensProvider | undefined;
private _codeLensProviderDisposable: Disposable | undefined;
private _disposable: Disposable;
private _gitignore: Promise<ignore.Ignore>;
static EmptyPromise: Promise<IGitBlame | IGitLog> = Promise.resolve(undefined);
@ -76,7 +81,11 @@ export default class GitProvider extends Disposable {
dispose() {
this._disposable && this._disposable.dispose();
this._codeLensProviderDisposable && this._codeLensProviderDisposable.dispose();
this._codeLensProviderDisposable = undefined;
this._codeLensProvider = undefined;
this._cacheDisposable && this._cacheDisposable.dispose();
this._uriCache && this._uriCache.clear();
this._gitCache && this._gitCache.clear();
@ -98,12 +107,20 @@ export default class GitProvider extends Disposable {
if (codeLensChanged || advancedChanged) {
Logger.log('CodeLens config changed; resetting CodeLens provider');
this._codeLensProviderDisposable && this._codeLensProviderDisposable.dispose();
// this._codeLensProviderDisposable && this._codeLensProviderDisposable.dispose();
if (config.codeLens.visibility === CodeLensVisibility.Auto && (config.codeLens.recentChange.enabled || config.codeLens.authors.enabled)) {
this._codeLensProviderDisposable = languages.registerCodeLensProvider(GitCodeLensProvider.selector, new GitCodeLensProvider(this.context, this));
if (this._codeLensProvider) {
this._codeLensProvider.reset();
}
else {
this._codeLensProvider = new GitCodeLensProvider(this.context, this);
this._codeLensProviderDisposable = languages.registerCodeLensProvider(GitCodeLensProvider.selector, this._codeLensProvider);
}
}
else {
this._codeLensProviderDisposable && this._codeLensProviderDisposable.dispose();
this._codeLensProviderDisposable = undefined;
this._codeLensProvider = undefined;
}
}
@ -117,10 +134,7 @@ export default class GitProvider extends Disposable {
// TODO: Maybe stop clearing on close and instead limit to a certain number of recent blames
disposables.push(workspace.onDidCloseTextDocument(d => this._removeCachedEntry(d, RemoveCacheReason.DocumentClosed)));
const removeCachedEntryFn = Functions.debounce(this._removeCachedEntry.bind(this), 2500);
disposables.push(workspace.onDidSaveTextDocument(d => removeCachedEntryFn(d, RemoveCacheReason.DocumentSaved)));
disposables.push(workspace.onDidChangeTextDocument(e => removeCachedEntryFn(e.document, RemoveCacheReason.DocumentChanged)));
disposables.push(workspace.onDidSaveTextDocument(d => this._removeCachedEntry(d, RemoveCacheReason.DocumentSaved)));
this._cacheDisposable = Disposable.from(...disposables);
}
@ -188,10 +202,12 @@ export default class GitProvider extends Disposable {
if (this._gitCache.delete(cacheKey)) {
Logger.log(`Clear cache entry for '${cacheKey}', reason=${RemoveCacheReason[reason]}`);
// if (reason === RemoveCacheReason.DocumentSaved) {
// // TODO: Killing the code lens provider is too drastic -- makes the editor jump around, need to figure out how to trigger a refresh
// this._registerCodeLensProvider();
// }
if (reason === RemoveCacheReason.DocumentSaved) {
this._onDidRemoveCacheEntryEmitter.fire();
// Refresh the codelenses with the update blame
this._codeLensProvider && this._codeLensProvider.reset();
}
}
}

Loading…
Cancel
Save