1
1
'use strict'
2
2
import { commands , DecorationOptions , Disposable , OverviewRulerLane , Position , Range , TextEditor , TextEditorEdit , TextEditorDecorationType , Uri , window } from 'vscode' ;
3
- import { Commands , VsCodeCommands } from './constants' ;
3
+ import { BuiltInCommands , Commands } from './constants' ;
4
4
import GitProvider from './gitProvider' ;
5
5
import GitBlameController from './gitBlameController' ;
6
6
import { basename } from 'path' ;
@@ -36,25 +36,59 @@ abstract class EditorCommand extends Disposable {
36
36
abstract execute ( editor : TextEditor , edit : TextEditorEdit , ...args ) : any ;
37
37
}
38
38
39
- export class ShowBlameCommand extends EditorCommand {
40
- constructor ( private git : GitProvider , private blameController : GitBlameController ) {
41
- super ( Commands . ShowBlame ) ;
39
+ export class DiffWithPreviousCommand extends EditorCommand {
40
+ constructor ( private git : GitProvider ) {
41
+ super ( Commands . DiffWithPrevious ) ;
42
42
}
43
43
44
- execute ( editor : TextEditor , edit : TextEditorEdit , uri ?: Uri , sha ?: string ) {
45
- if ( sha ) {
46
- return this . blameController . toggleBlame ( editor , sha ) ;
44
+ execute ( editor : TextEditor , edit : TextEditorEdit , uri ?: Uri , sha ?: string , compareWithSha ?: string , line ?: number ) {
45
+ line = line || editor . selection . active . line ;
46
+ if ( ! sha ) {
47
+ return this . git . getBlameForLine ( uri . path , line )
48
+ . then ( blame => commands . executeCommand ( Commands . DiffWithPrevious , uri , blame . commit . sha , blame . commit . previousSha ) ) ;
47
49
}
48
50
49
- const activeLine = editor . selection . active . line ;
50
- return this . git . getBlameForLine ( editor . document . fileName , activeLine )
51
- . then ( blame => this . blameController . showBlame ( editor , blame . commit . sha ) ) ;
51
+ if ( ! compareWithSha ) {
52
+ return window . showInformationMessage ( `Commit ${ sha } has no previous commit` ) ;
53
+ }
54
+
55
+ return Promise . all ( [ this . git . getVersionedFile ( uri . path , sha ) , this . git . getVersionedFile ( uri . path , compareWithSha ) ] )
56
+ . then ( values => {
57
+ const [ source , compare ] = values ;
58
+ const fileName = basename ( uri . path ) ;
59
+ return commands . executeCommand ( BuiltInCommands . Diff , Uri . file ( compare ) , Uri . file ( source ) , `${ fileName } (${ compareWithSha } ) ↔ ${ fileName } (${ sha } )` )
60
+ // 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
61
+ // which for a diff could be the first difference
62
+ . then ( ( ) => commands . executeCommand ( BuiltInCommands . CursorMove , { to : 'down' , value : line } ) ) ;
63
+ } ) ;
52
64
}
53
65
}
54
66
55
- export class ToggleBlameCommand extends EditorCommand {
67
+ export class DiffWithWorkingCommand extends EditorCommand {
68
+ constructor ( private git : GitProvider ) {
69
+ super ( Commands . DiffWithWorking ) ;
70
+ }
71
+
72
+ execute ( editor : TextEditor , edit : TextEditorEdit , uri ?: Uri , sha ?: string , line ?: number ) {
73
+ line = line || editor . selection . active . line ;
74
+ if ( ! sha ) {
75
+ return this . git . getBlameForLine ( uri . path , line )
76
+ . then ( blame => commands . executeCommand ( Commands . DiffWithWorking , uri , blame . commit . sha ) ) ;
77
+ } ;
78
+
79
+ return this . git . getVersionedFile ( uri . path , sha ) . then ( compare => {
80
+ const fileName = basename ( uri . path ) ;
81
+ return commands . executeCommand ( BuiltInCommands . Diff , Uri . file ( compare ) , uri , `${ fileName } (${ sha } ) ↔ ${ fileName } (index)` )
82
+ // 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
83
+ // which for a diff could be the first difference
84
+ . then ( ( ) => commands . executeCommand ( BuiltInCommands . CursorMove , { to : 'down' , value : line } ) ) ;
85
+ } ) ;
86
+ }
87
+ }
88
+
89
+ export class ShowBlameCommand extends EditorCommand {
56
90
constructor ( private git : GitProvider , private blameController : GitBlameController ) {
57
- super ( Commands . ToggleBlame ) ;
91
+ super ( Commands . ShowBlame ) ;
58
92
}
59
93
60
94
execute ( editor : TextEditor , edit : TextEditorEdit , uri ?: Uri , sha ?: string ) {
@@ -64,13 +98,13 @@ export class ToggleBlameCommand extends EditorCommand {
64
98
65
99
const activeLine = editor . selection . active . line ;
66
100
return this . git . getBlameForLine ( editor . document . fileName , activeLine )
67
- . then ( blame => this . blameController . toggleBlame ( editor , blame . commit . sha ) ) ;
101
+ . then ( blame => this . blameController . showBlame ( editor , blame . commit . sha ) ) ;
68
102
}
69
103
}
70
104
71
- export class ShowHistoryCommand extends EditorCommand {
105
+ export class ShowBlameHistoryCommand extends EditorCommand {
72
106
constructor ( private git : GitProvider ) {
73
- super ( Commands . ShowHistory ) ;
107
+ super ( Commands . ShowBlameHistory ) ;
74
108
}
75
109
76
110
execute ( editor : TextEditor , edit : TextEditorEdit , uri ?: Uri , range ?: Range , position ?: Position ) {
@@ -87,49 +121,23 @@ export class ShowHistoryCommand extends EditorCommand {
87
121
}
88
122
89
123
return this . git . getBlameLocations ( uri . path , range ) . then ( locations => {
90
- return commands . executeCommand ( VsCodeCommands . ShowReferences , uri , position , locations ) ;
124
+ return commands . executeCommand ( BuiltInCommands . ShowReferences , uri , position , locations ) ;
91
125
} ) ;
92
126
}
93
127
}
94
128
95
- export class DiffWithPreviousCommand extends EditorCommand {
96
- constructor ( private git : GitProvider ) {
97
- super ( Commands . DiffWithPrevious ) ;
98
- }
99
-
100
- execute ( editor : TextEditor , edit : TextEditorEdit , uri ?: Uri , sha ?: string , compareWithSha ?: string ) {
101
- if ( ! sha ) {
102
- return this . git . getBlameForLine ( uri . path , editor . selection . active . line )
103
- . then ( blame => commands . executeCommand ( Commands . DiffWithPrevious , uri , blame . commit . sha , blame . commit . previousSha ) ) ;
104
- }
105
-
106
- if ( ! compareWithSha ) {
107
- return window . showInformationMessage ( `Commit ${ sha } has no previous commit` ) ;
108
- }
109
-
110
- return Promise . all ( [ this . git . getVersionedFile ( uri . path , sha ) , this . git . getVersionedFile ( uri . path , compareWithSha ) ] )
111
- . then ( values => {
112
- const [ source , compare ] = values ;
113
- const fileName = basename ( uri . path ) ;
114
- return commands . executeCommand ( VsCodeCommands . Diff , Uri . file ( compare ) , Uri . file ( source ) , `${ fileName } (${ compareWithSha } ) ↔ ${ fileName } (${ sha } )` ) ;
115
- } ) ;
116
- }
117
- }
118
-
119
- export class DiffWithWorkingCommand extends EditorCommand {
120
- constructor ( private git : GitProvider ) {
121
- super ( Commands . DiffWithWorking ) ;
129
+ export class ToggleBlameCommand extends EditorCommand {
130
+ constructor ( private git : GitProvider , private blameController : GitBlameController ) {
131
+ super ( Commands . ToggleBlame ) ;
122
132
}
123
133
124
134
execute ( editor : TextEditor , edit : TextEditorEdit , uri ?: Uri , sha ?: string ) {
125
- if ( ! sha ) {
126
- return this . git . getBlameForLine ( uri . path , editor . selection . active . line )
127
- . then ( blame => commands . executeCommand ( Commands . DiffWithWorking , uri , blame . commit . sha ) ) ;
128
- } ;
135
+ if ( sha ) {
136
+ return this . blameController . toggleBlame ( editor , sha ) ;
137
+ }
129
138
130
- return this . git . getVersionedFile ( uri . path , sha ) . then ( compare => {
131
- const fileName = basename ( uri . path ) ;
132
- return commands . executeCommand ( VsCodeCommands . Diff , Uri . file ( compare ) , uri , `${ fileName } (${ sha } ) ↔ ${ fileName } (index)` ) ;
133
- } ) ;
139
+ const activeLine = editor . selection . active . line ;
140
+ return this . git . getBlameForLine ( editor . document . fileName , activeLine )
141
+ . then ( blame => this . blameController . toggleBlame ( editor , blame . commit . sha ) ) ;
134
142
}
135
143
}
0 commit comments