@ -1,6 +1,6 @@
'use strict'
import { commands , DecorationOptions , Disposable , OverviewRulerLane , Position , Range , TextEditor , TextEditorEdit , TextEditorDecorationType , Uri , window } from 'vscode' ;
import { Commands , VsCode Commands} from './constants' ;
import { BuiltIn Commands, Commands } from './constants' ;
import GitProvider from './gitProvider' ;
import GitBlameController from './gitBlameController' ;
import { basename } from 'path' ;
@ -36,25 +36,59 @@ abstract class EditorCommand extends Disposable {
abstract execute ( editor : TextEditor , edit : TextEditorEdit , . . . args ) : any ;
}
export class ShowBlame Command extends EditorCommand {
constructor ( private git : GitProvider , private blameController : GitBlameController ) {
super ( Commands . ShowBlame ) ;
export class DiffWithPrevious Command extends EditorCommand {
constructor ( private git : GitProvider ) {
super ( Commands . DiffWithPrevious ) ;
}
execute ( editor : TextEditor , edit : TextEditorEdit , uri? : Uri , sha? : string ) {
if ( sha ) {
return this . blameController . toggleBlame ( editor , sha ) ;
execute ( editor : TextEditor , edit : TextEditorEdit , uri? : Uri , sha? : string , compareWithSha? : string , line? : number ) {
line = line || editor . selection . active . line ;
if ( ! sha ) {
return this . git . getBlameForLine ( uri . path , line )
. then ( blame = > commands . executeCommand ( Commands . DiffWithPrevious , uri , blame . commit . sha , blame . commit . previousSha ) ) ;
}
const activeLine = editor . selection . active . line ;
return this . git . getBlameForLine ( editor . document . fileName , activeLine )
. then ( blame = > this . blameController . showBlame ( editor , blame . commit . sha ) ) ;
if ( ! compareWithSha ) {
return window . showInformationMessage ( ` Commit ${ sha } has no previous commit ` ) ;
}
return Promise . all ( [ this . git . getVersionedFile ( uri . path , sha ) , this . git . getVersionedFile ( uri . path , compareWithSha ) ] )
. then ( values = > {
const [ source , compare ] = values ;
const fileName = basename ( uri . path ) ;
return commands . executeCommand ( BuiltInCommands . Diff , Uri . file ( compare ) , Uri . file ( source ) , ` ${ fileName } ( ${ compareWithSha } ) ↔ ${ fileName } ( ${ sha } ) ` )
// TODO: Moving doesn't always seem to work -- or more accurately it seems like it moves down that number of lines from the current line
// which for a diff could be the first difference
. then ( ( ) = > commands . executeCommand ( BuiltInCommands . CursorMove , { to : 'down' , value : line } ) ) ;
} ) ;
}
}
export class ToggleBlameCommand extends EditorCommand {
export class DiffWithWorkingCommand extends EditorCommand {
constructor ( private git : GitProvider ) {
super ( Commands . DiffWithWorking ) ;
}
execute ( editor : TextEditor , edit : TextEditorEdit , uri? : Uri , sha? : string , line? : number ) {
line = line || editor . selection . active . line ;
if ( ! sha ) {
return this . git . getBlameForLine ( uri . path , line )
. then ( blame = > commands . executeCommand ( Commands . DiffWithWorking , uri , blame . commit . sha ) ) ;
} ;
return this . git . getVersionedFile ( uri . path , sha ) . then ( compare = > {
const fileName = basename ( uri . path ) ;
return commands . executeCommand ( BuiltInCommands . Diff , Uri . file ( compare ) , uri , ` ${ fileName } ( ${ sha } ) ↔ ${ fileName } (index) ` )
// TODO: Moving doesn't always seem to work -- or more accurately it seems like it moves down that number of lines from the current line
// which for a diff could be the first difference
. then ( ( ) = > commands . executeCommand ( BuiltInCommands . CursorMove , { to : 'down' , value : line } ) ) ;
} ) ;
}
}
export class ShowBlameCommand extends EditorCommand {
constructor ( private git : GitProvider , private blameController : GitBlameController ) {
super ( Commands . ToggleBlame ) ;
super ( Commands . Show Blame) ;
}
execute ( editor : TextEditor , edit : TextEditorEdit , uri? : Uri , sha? : string ) {
@ -64,13 +98,13 @@ export class ToggleBlameCommand extends EditorCommand {
const activeLine = editor . selection . active . line ;
return this . git . getBlameForLine ( editor . document . fileName , activeLine )
. then ( blame = > this . blameController . toggle Blame( editor , blame . commit . sha ) ) ;
. then ( blame = > this . blameController . show Blame( editor , blame . commit . sha ) ) ;
}
}
export class ShowHistoryCommand extends EditorCommand {
export class ShowBlame HistoryCommand extends EditorCommand {
constructor ( private git : GitProvider ) {
super ( Commands . ShowHistory ) ;
super ( Commands . ShowBlame History ) ;
}
execute ( editor : TextEditor , edit : TextEditorEdit , uri? : Uri , range? : Range , position? : Position ) {
@ -87,49 +121,23 @@ export class ShowHistoryCommand extends EditorCommand {
}
return this . git . getBlameLocations ( uri . path , range ) . then ( locations = > {
return commands . executeCommand ( VsCode Commands. ShowReferences , uri , position , locations ) ;
return commands . executeCommand ( BuiltIn Commands. ShowReferences , uri , position , locations ) ;
} ) ;
}
}
export class DiffWithPreviousCommand extends EditorCommand {
constructor ( private git : GitProvider ) {
super ( Commands . DiffWithPrevious ) ;
}
execute ( editor : TextEditor , edit : TextEditorEdit , uri? : Uri , sha? : string , compareWithSha? : string ) {
if ( ! sha ) {
return this . git . getBlameForLine ( uri . path , editor . selection . active . line )
. then ( blame = > commands . executeCommand ( Commands . DiffWithPrevious , uri , blame . commit . sha , blame . commit . previousSha ) ) ;
}
if ( ! compareWithSha ) {
return window . showInformationMessage ( ` Commit ${ sha } has no previous commit ` ) ;
}
return Promise . all ( [ this . git . getVersionedFile ( uri . path , sha ) , this . git . getVersionedFile ( uri . path , compareWithSha ) ] )
. then ( values = > {
const [ source , compare ] = values ;
const fileName = basename ( uri . path ) ;
return commands . executeCommand ( VsCodeCommands . Diff , Uri . file ( compare ) , Uri . file ( source ) , ` ${ fileName } ( ${ compareWithSha } ) ↔ ${ fileName } ( ${ sha } ) ` ) ;
} ) ;
}
}
export class DiffWithWorkingCommand extends EditorCommand {
constructor ( private git : GitProvider ) {
super ( Commands . DiffWithWorking ) ;
export class ToggleBlameCommand extends EditorCommand {
constructor ( private git : GitProvider , private blameController : GitBlameController ) {
super ( Commands . ToggleBlame ) ;
}
execute ( editor : TextEditor , edit : TextEditorEdit , uri? : Uri , sha? : string ) {
if ( ! sha ) {
return this . git . getBlameForLine ( uri . path , editor . selection . active . line )
. then ( blame = > commands . executeCommand ( Commands . DiffWithWorking , uri , blame . commit . sha ) ) ;
} ;
if ( sha ) {
return this . blameController . toggleBlame ( editor , sha ) ;
}
return this . git . getVersionedFile ( uri . path , sha ) . then ( compare = > {
const fileName = basename ( uri . path ) ;
return commands . executeCommand ( VsCodeCommands . Diff , Uri . file ( compare ) , uri , ` ${ fileName } ( ${ sha } ) ↔ ${ fileName } (index) ` ) ;
} ) ;
const activeLine = editor . selection . active . line ;
return this . git . getBlameForLine ( editor . document . fileName , activeLine )
. then ( blame = > this . blameController . toggleBlame ( editor , blame . commit . sha ) ) ;
}
}