mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 18:48:45 -05:00
Fixes updating CodeLens after file save
Fixes updating active line annotations after file save
This commit is contained in:
@@ -34,6 +34,7 @@ export default class BlameStatusBarController extends Disposable {
|
|||||||
const subscriptions: Disposable[] = [];
|
const subscriptions: Disposable[] = [];
|
||||||
|
|
||||||
subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigure, this));
|
subscriptions.push(workspace.onDidChangeConfiguration(this._onConfigure, this));
|
||||||
|
subscriptions.push(git.onDidRemoveCacheEntry(this._onRemoveCacheEntry, this));
|
||||||
|
|
||||||
this._disposable = Disposable.from(...subscriptions);
|
this._disposable = Disposable.from(...subscriptions);
|
||||||
}
|
}
|
||||||
@@ -98,6 +99,11 @@ export default class BlameStatusBarController extends Disposable {
|
|||||||
this._onActiveTextEditorChanged(window.activeTextEditor);
|
this._onActiveTextEditorChanged(window.activeTextEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _onRemoveCacheEntry() {
|
||||||
|
this._blame = undefined;
|
||||||
|
this._onActiveTextEditorChanged(window.activeTextEditor);
|
||||||
|
}
|
||||||
|
|
||||||
private async _onActiveTextEditorChanged(e: TextEditor): Promise<void> {
|
private async _onActiveTextEditorChanged(e: TextEditor): Promise<void> {
|
||||||
const previousEditor = this._editor;
|
const previousEditor = this._editor;
|
||||||
previousEditor && previousEditor.setDecorations(activeLineDecoration, []);
|
previousEditor && previousEditor.setDecorations(activeLineDecoration, []);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Functions, Iterables, Strings } from './system';
|
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 { BuiltInCommands, Commands, DocumentSchemes } from './constants';
|
||||||
import { CodeLensCommand, CodeLensLocation, IConfig, ICodeLensLanguageLocation } from './configuration';
|
import { CodeLensCommand, CodeLensLocation, IConfig, ICodeLensLanguageLocation } from './configuration';
|
||||||
import GitProvider, { GitCommit, GitUri, IGitBlame, IGitBlameLines } from './gitProvider';
|
import GitProvider, { GitCommit, GitUri, IGitBlame, IGitBlameLines } from './gitProvider';
|
||||||
@@ -31,6 +31,11 @@ export class GitAuthorsCodeLens extends CodeLens {
|
|||||||
|
|
||||||
export default class GitCodeLensProvider implements CodeLensProvider {
|
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 };
|
static selector: DocumentSelector = { scheme: DocumentSchemes.File };
|
||||||
|
|
||||||
private _config: IConfig;
|
private _config: IConfig;
|
||||||
@@ -39,6 +44,11 @@ export default class GitCodeLensProvider implements CodeLensProvider {
|
|||||||
this._config = workspace.getConfiguration('').get<IConfig>('gitlens');
|
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[]> {
|
async provideCodeLenses(document: TextDocument, token: CancellationToken): Promise<CodeLens[]> {
|
||||||
let languageLocations = this._config.codeLens.languageLocations.find(_ => _.language.toLowerCase() === document.languageId);
|
let languageLocations = this._config.codeLens.languageLocations.find(_ => _.language.toLowerCase() === document.languageId);
|
||||||
if (languageLocations == null) {
|
if (languageLocations == null) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Functions, Iterables, Objects } from './system';
|
import { /*Functions,*/ Iterables, Objects } from './system';
|
||||||
import { Disposable, ExtensionContext, languages, Location, Position, Range, TextDocument, TextEditor, Uri, workspace } from 'vscode';
|
import { Disposable, Event, EventEmitter, ExtensionContext, languages, Location, Position, Range, TextDocument, TextEditor, Uri, workspace } from 'vscode';
|
||||||
import { CodeLensVisibility, IConfig } from './configuration';
|
import { CodeLensVisibility, IConfig } from './configuration';
|
||||||
import { DocumentSchemes, WorkspaceState } from './constants';
|
import { DocumentSchemes, WorkspaceState } from './constants';
|
||||||
import Git, { GitBlameParserEnricher, GitBlameFormat, GitCommit, GitLogParserEnricher, IGitAuthor, IGitBlame, IGitBlameLine, IGitBlameLines, IGitLog } from './git/git';
|
import Git, { GitBlameParserEnricher, GitBlameFormat, GitCommit, GitLogParserEnricher, IGitAuthor, IGitBlame, IGitBlameLine, IGitBlameLines, IGitLog } from './git/git';
|
||||||
@@ -41,20 +41,25 @@ interface ICachedLog extends ICachedItem<IGitLog> { }
|
|||||||
|
|
||||||
enum RemoveCacheReason {
|
enum RemoveCacheReason {
|
||||||
DocumentClosed,
|
DocumentClosed,
|
||||||
DocumentSaved,
|
DocumentSaved
|
||||||
DocumentChanged
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class GitProvider extends Disposable {
|
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 _gitCache: Map<string, GitCacheEntry> | undefined;
|
||||||
private _cacheDisposable: Disposable | undefined;
|
private _cacheDisposable: Disposable | undefined;
|
||||||
private _repoPath: string;
|
private _repoPath: string;
|
||||||
private _uriCache: Map<string, UriCacheEntry> | undefined;
|
private _uriCache: Map<string, UriCacheEntry> | undefined;
|
||||||
|
|
||||||
config: IConfig;
|
config: IConfig;
|
||||||
private _disposable: Disposable;
|
private _codeLensProvider: GitCodeLensProvider | undefined;
|
||||||
private _codeLensProviderDisposable: Disposable | undefined;
|
private _codeLensProviderDisposable: Disposable | undefined;
|
||||||
|
private _disposable: Disposable;
|
||||||
private _gitignore: Promise<ignore.Ignore>;
|
private _gitignore: Promise<ignore.Ignore>;
|
||||||
|
|
||||||
static EmptyPromise: Promise<IGitBlame | IGitLog> = Promise.resolve(undefined);
|
static EmptyPromise: Promise<IGitBlame | IGitLog> = Promise.resolve(undefined);
|
||||||
@@ -76,7 +81,11 @@ export default class GitProvider extends Disposable {
|
|||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
this._disposable && this._disposable.dispose();
|
this._disposable && this._disposable.dispose();
|
||||||
|
|
||||||
this._codeLensProviderDisposable && this._codeLensProviderDisposable.dispose();
|
this._codeLensProviderDisposable && this._codeLensProviderDisposable.dispose();
|
||||||
|
this._codeLensProviderDisposable = undefined;
|
||||||
|
this._codeLensProvider = undefined;
|
||||||
|
|
||||||
this._cacheDisposable && this._cacheDisposable.dispose();
|
this._cacheDisposable && this._cacheDisposable.dispose();
|
||||||
this._uriCache && this._uriCache.clear();
|
this._uriCache && this._uriCache.clear();
|
||||||
this._gitCache && this._gitCache.clear();
|
this._gitCache && this._gitCache.clear();
|
||||||
@@ -98,12 +107,20 @@ export default class GitProvider extends Disposable {
|
|||||||
|
|
||||||
if (codeLensChanged || advancedChanged) {
|
if (codeLensChanged || advancedChanged) {
|
||||||
Logger.log('CodeLens config changed; resetting CodeLens provider');
|
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)) {
|
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 {
|
else {
|
||||||
|
this._codeLensProviderDisposable && this._codeLensProviderDisposable.dispose();
|
||||||
this._codeLensProviderDisposable = undefined;
|
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
|
// 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)));
|
disposables.push(workspace.onDidCloseTextDocument(d => this._removeCachedEntry(d, RemoveCacheReason.DocumentClosed)));
|
||||||
|
disposables.push(workspace.onDidSaveTextDocument(d => this._removeCachedEntry(d, RemoveCacheReason.DocumentSaved)));
|
||||||
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)));
|
|
||||||
|
|
||||||
this._cacheDisposable = Disposable.from(...disposables);
|
this._cacheDisposable = Disposable.from(...disposables);
|
||||||
}
|
}
|
||||||
@@ -188,10 +202,12 @@ export default class GitProvider extends Disposable {
|
|||||||
if (this._gitCache.delete(cacheKey)) {
|
if (this._gitCache.delete(cacheKey)) {
|
||||||
Logger.log(`Clear cache entry for '${cacheKey}', reason=${RemoveCacheReason[reason]}`);
|
Logger.log(`Clear cache entry for '${cacheKey}', reason=${RemoveCacheReason[reason]}`);
|
||||||
|
|
||||||
// if (reason === RemoveCacheReason.DocumentSaved) {
|
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._onDidRemoveCacheEntryEmitter.fire();
|
||||||
// this._registerCodeLensProvider();
|
|
||||||
// }
|
// Refresh the codelenses with the update blame
|
||||||
|
this._codeLensProvider && this._codeLensProvider.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user