@ -5,6 +5,7 @@ import { Container } from '../container';
import { GitUri } from '../git/gitUri' ;
import { GitUri } from '../git/gitUri' ;
import { GitRevision } from '../git/models' ;
import { GitRevision } from '../git/models' ;
import { Logger } from '../logger' ;
import { Logger } from '../logger' ;
import { Functions } from '../system' ;
export interface DocumentBlameStateChangeEvent < T > {
export interface DocumentBlameStateChangeEvent < T > {
readonly editor : TextEditor ;
readonly editor : TextEditor ;
@ -37,7 +38,7 @@ export class TrackedDocument implements Disposable {
private _uri ! : GitUri ;
private _uri ! : GitUri ;
private constructor (
private constructor (
private readonly _document : TextDocument ,
readonly document : TextDocument ,
public readonly key : string ,
public readonly key : string ,
public dirty : boolean ,
public dirty : boolean ,
private _eventDelegates : { onDidBlameStateChange ( e : DocumentBlameStateChangeEvent < T > ) : void } ,
private _eventDelegates : { onDidBlameStateChange ( e : DocumentBlameStateChangeEvent < T > ) : void } ,
@ -45,14 +46,15 @@ export class TrackedDocument implements Disposable {
) { }
) { }
dispose() {
dispose() {
this . state = undefined ;
this . _disposed = true ;
this . _disposed = true ;
this . reset ( 'dispose' ) ;
this . _disposable ? . dispose ( ) ;
this . _disposable ? . dispose ( ) ;
}
}
private initializing = true ;
private initializing = true ;
private async initialize ( ) : Promise < void > {
private async initialize ( ) : Promise < void > {
const uri = this . _ document. uri ;
const uri = this . document. uri ;
this . _uri = await GitUri . fromUri ( uri ) ;
this . _uri = await GitUri . fromUri ( uri ) ;
if ( ! this . _disposed ) {
if ( ! this . _disposed ) {
@ -94,10 +96,10 @@ export class TrackedDocument implements Disposable {
}
}
get lineCount ( ) : number {
get lineCount ( ) : number {
return this . _ document. lineCount ;
return this . document. lineCount ;
}
}
get uri() {
get uri ( ) class="o">: GitUri {
return this . _uri ;
return this . _uri ;
}
}
@ -109,26 +111,29 @@ export class TrackedDocument implements Disposable {
}
}
is ( document : TextDocument ) {
is ( document : TextDocument ) {
return document === this . _ document;
return document === this . document;
}
}
reset ( reason : 'config' | 'dispose' | 'document' | 'repository' ) {
private _updateDebounced :
| Functions . Deferrable < ( { forceBlameChange } ? : { forceBlameChange? : boolean | undefined } ) = > Promise < void > >
| undefined ;
reset ( reason : 'config' | 'document' | 'repository' ) {
this . _requiresUpdate = true ;
this . _requiresUpdate = true ;
this . _blameFailed = false ;
this . _blameFailed = false ;
this . _isDirtyIdle = false ;
this . _isDirtyIdle = false ;
if ( this . state != null ) {
if ( this . state != null ) {
// // Don't remove broken blame on change (since otherwise we'll have to run the broken blame again)
// if (!this.state.hasErrors) {
this . state = undefined ;
this . state = undefined ;
Logger . log ( ` Reset state for ' ${ this . key } ', reason= ${ reason } ` ) ;
Logger . log ( ` Reset state for ' ${ this . key } ', reason= ${ reason } ` ) ;
// }
}
}
if ( reason === 'repository' && isActiveDocument ( this . _document ) ) {
void this . update ( ) ;
if ( reason === 'repository' && isActiveDocument ( this . document ) ) {
if ( this . _updateDebounced == null ) {
this . _updateDebounced = Functions . debounce ( this . update . bind ( this ) , 250 ) ;
}
void this . _updateDebounced ( ) ;
}
}
}
}
@ -138,7 +143,7 @@ export class TrackedDocument implements Disposable {
this . _blameFailed = true ;
this . _blameFailed = true ;
if ( wasBlameable && isActiveDocument ( this . _ document) ) {
if ( wasBlameable && isActiveDocument ( this . document) ) {
void this . update ( { forceBlameChange : true } ) ;
void this . update ( { forceBlameChange : true } ) ;
}
}
}
}
@ -165,7 +170,7 @@ export class TrackedDocument implements Disposable {
this . _isDirtyIdle = false ;
this . _isDirtyIdle = false ;
// Caches these before the awaits
// Caches these before the awaits
const active = getEditorIfActive ( this . _ document) ;
const active = getEditorIfActive ( this . document) ;
const wasBlameable = forceBlameChange ? undefined : this . isBlameable ;
const wasBlameable = forceBlameChange ? undefined : this . isBlameable ;
const repo = await this . container . git . getRepository ( this . _uri ) ;
const repo = await this . container . git . getRepository ( this . _uri ) ;