@@ -5,16 +5,10 @@ import GitBlameProvider, {IGitBlame, IGitBlameCommit} from './gitBlameProvider';
55import * as moment from 'moment' ;
66
77export class GitBlameCodeLens extends CodeLens {
8- private _locations : Location [ ] = [ ] ;
9-
10- constructor ( private blameProvider : GitBlameProvider , public fileName : string , private blameRange : Range , range : Range ) {
8+ constructor ( private blameProvider : GitBlameProvider , public fileName : string , public blameRange : Range , range : Range ) {
119 super ( range ) ;
1210 }
1311
14- get locations ( ) {
15- return this . _locations ;
16- }
17-
1812 getBlame ( ) : Promise < IGitBlame > {
1913 return this . blameProvider . getBlameForRange ( this . fileName , this . blameRange ) ;
2014 }
@@ -35,11 +29,7 @@ export class GitHistoryCodeLens extends CodeLens {
3529}
3630
3731export default class GitCodeLensProvider implements CodeLensProvider {
38- public repoPath : string ;
39-
40- constructor ( context : ExtensionContext , public blameProvider : GitBlameProvider ) {
41- this . repoPath = context . workspaceState . get ( WorkspaceState . RepoPath ) as string ;
42- }
32+ constructor ( context : ExtensionContext , public blameProvider : GitBlameProvider ) { }
4333
4434 provideCodeLenses ( document : TextDocument , token : CancellationToken ) : CodeLens [ ] | Thenable < CodeLens [ ] > {
4535 this . blameProvider . blameFile ( document . fileName ) ;
@@ -52,7 +42,7 @@ export default class GitCodeLensProvider implements CodeLensProvider {
5242 if ( ! lenses . find ( l => l . range . start . line === 0 && l . range . end . line === 0 ) ) {
5343 const docRange = document . validateRange ( new Range ( 0 , 1000000 , 1000000 , 1000000 ) ) ;
5444 lenses . push ( new GitBlameCodeLens ( this . blameProvider , document . fileName , docRange , new Range ( 0 , 0 , 0 , docRange . start . character ) ) ) ;
55- lenses . push ( new GitHistoryCodeLens ( this . repoPath , document . fileName , docRange . with ( new Position ( docRange . start . line , docRange . start . character + 1 ) ) ) ) ;
45+ lenses . push ( new GitHistoryCodeLens ( this . blameProvider . repoPath , document . fileName , docRange . with ( new Position ( docRange . start . line , docRange . start . character + 1 ) ) ) ) ;
5646 }
5747 return lenses ;
5848 } ) ;
@@ -81,11 +71,11 @@ export default class GitCodeLensProvider implements CodeLensProvider {
8171 if ( startChar === - 1 ) {
8272 startChar = line . firstNonWhitespaceCharacterIndex ;
8373 } else {
84- startChar += ( symbol . name . length / 2 ) - 1 ;
74+ startChar += Math . floor ( symbol . name . length / 2 ) - 1 ;
8575 }
8676
8777 lenses . push ( new GitBlameCodeLens ( this . blameProvider , document . fileName , symbol . location . range , line . range . with ( new Position ( line . range . start . line , startChar ) ) ) ) ;
88- lenses . push ( new GitHistoryCodeLens ( this . repoPath , document . fileName , line . range . with ( new Position ( line . range . start . line , startChar + 1 ) ) ) ) ;
78+ lenses . push ( new GitHistoryCodeLens ( this . blameProvider . repoPath , document . fileName , line . range . with ( new Position ( line . range . start . line , startChar + 1 ) ) ) ) ;
8979 }
9080
9181 resolveCodeLens ( lens : CodeLens , token : CancellationToken ) : Thenable < CodeLens > {
@@ -102,27 +92,11 @@ export default class GitCodeLensProvider implements CodeLensProvider {
10292 return ;
10393 }
10494
105- // TODO: Rework this to only get the locations in the ShowBlameHistory command, rather than here -- should save a lot of processing
106- const commitCount = blame . commits . size ;
107-
108- let recentCommit ;
109- Array . from ( blame . commits . values ( ) )
110- . sort ( ( a , b ) => b . date . getTime ( ) - a . date . getTime ( ) )
111- . forEach ( ( c , i ) => {
112- if ( i === 0 ) {
113- recentCommit = c ;
114- }
115-
116- const uri = GitBlameCodeLens . toUri ( lens , this . repoPath , c , i + 1 , commitCount ) ;
117- blame . lines
118- . filter ( l => l . sha === c . sha )
119- . forEach ( l => lens . locations . push ( new Location ( uri , new Position ( l . originalLine , 0 ) ) ) ) ;
120- } ) ;
121-
95+ const recentCommit = Array . from ( blame . commits . values ( ) ) . sort ( ( a , b ) => b . date . getTime ( ) - a . date . getTime ( ) ) [ 0 ] ;
12296 lens . command = {
12397 title : `${ recentCommit . author } , ${ moment ( recentCommit . date ) . fromNow ( ) } ` ,
12498 command : Commands . ShowBlameHistory ,
125- arguments : [ Uri . file ( lens . fileName ) , lens . range . start , lens . locations ]
99+ arguments : [ Uri . file ( lens . fileName ) , lens . blameRange , lens . range . start ] // , lens.locations]
126100 } ;
127101 resolve ( lens ) ;
128102 } ) ;
0 commit comments