@@ -14,8 +14,8 @@ export class GitBlameCodeLens extends CodeLens {
1414 return this . blame . then ( allLines => allLines . slice ( this . blameRange . start . line , this . blameRange . end . line + 1 ) ) ;
1515 }
1616
17- static toUri ( lens : GitBlameCodeLens , index : number , line : IGitBlameLine , lines : IGitBlameLine [ ] ) : Uri {
18- return toGitBlameUri ( Object . assign ( { repoPath : lens . repoPath , index : index , range : lens . blameRange , lines : lines } , line ) ) ;
17+ static toUri ( lens : GitBlameCodeLens , index : number , line : IGitBlameLine , lines : IGitBlameLine [ ] , commits : string [ ] ) : Uri {
18+ return toGitBlameUri ( Object . assign ( { repoPath : lens . repoPath , index : index , range : lens . blameRange , lines : lines , commits : commits } , line ) ) ;
1919 }
2020}
2121
@@ -78,46 +78,50 @@ export default class GitCodeLensProvider implements CodeLensProvider {
7878 }
7979
8080 _resolveGitBlameCodeLens ( lens : GitBlameCodeLens , token : CancellationToken ) : Thenable < CodeLens > {
81- return lens . getBlameLines ( ) . then ( lines => {
82- if ( ! lines . length ) {
83- console . error ( 'No blame lines found' , lens ) ;
84- throw new Error ( 'No blame lines found' ) ;
85- }
86-
87- let recentLine = lines [ 0 ] ;
88-
89- let locations : Location [ ] = [ ] ;
90- if ( lines . length > 1 ) {
91- let sorted = lines . sort ( ( a , b ) => b . date . getTime ( ) - a . date . getTime ( ) ) ;
92- recentLine = sorted [ 0 ] ;
93-
94- // console.log(lens.fileName, 'Blame lines:', sorted);
95-
96- let map : Map < string , IGitBlameLine [ ] > = new Map ( ) ;
97- sorted . forEach ( l => {
98- let item = map . get ( l . sha ) ;
99- if ( item ) {
100- item . push ( l ) ;
101- } else {
102- map . set ( l . sha , [ l ] ) ;
103- }
104- } ) ;
105-
106- Array . from ( map . values ( ) ) . forEach ( ( lines , i ) => {
107- const uri = GitBlameCodeLens . toUri ( lens , i + 1 , lines [ 0 ] , lines ) ;
108- lines . forEach ( l => locations . push ( new Location ( uri , new Position ( l . originalLine , 0 ) ) ) ) ;
109- } ) ;
110- } else {
111- locations = [ new Location ( GitBlameCodeLens . toUri ( lens , 1 , recentLine , lines ) , lens . range . start ) ] ;
112- }
113-
114- lens . command = {
115- title : `${ recentLine . author } , ${ moment ( recentLine . date ) . fromNow ( ) } ` ,
116- command : Commands . ShowBlameHistory ,
117- arguments : [ Uri . file ( lens . fileName ) , lens . range . start , locations ]
118- } ;
119- return lens ;
120- } ) . catch ( ex => Promise . reject ( ex ) ) ; // TODO: Figure out a better way to stop the codelens from appearing
81+ return new Promise < CodeLens > ( ( resolve , reject ) => {
82+ lens . getBlameLines ( ) . then ( lines => {
83+ if ( ! lines . length ) {
84+ console . error ( 'No blame lines found' , lens ) ;
85+ reject ( null ) ;
86+ return ;
87+ }
88+
89+ let recentLine = lines [ 0 ] ;
90+
91+ let locations : Location [ ] = [ ] ;
92+ if ( lines . length > 1 ) {
93+ let sorted = lines . sort ( ( a , b ) => b . date . getTime ( ) - a . date . getTime ( ) ) ;
94+ recentLine = sorted [ 0 ] ;
95+
96+ // console.log(lens.fileName, 'Blame lines:', sorted);
97+
98+ let map : Map < string , IGitBlameLine [ ] > = new Map ( ) ;
99+ sorted . forEach ( l => {
100+ let item = map . get ( l . sha ) ;
101+ if ( item ) {
102+ item . push ( l ) ;
103+ } else {
104+ map . set ( l . sha , [ l ] ) ;
105+ }
106+ } ) ;
107+
108+ const commits = Array . from ( map . keys ( ) ) ;
109+ Array . from ( map . values ( ) ) . forEach ( ( lines , i ) => {
110+ const uri = GitBlameCodeLens . toUri ( lens , i + 1 , lines [ 0 ] , lines , commits ) ;
111+ lines . forEach ( l => locations . push ( new Location ( uri , new Position ( l . originalLine , 0 ) ) ) ) ;
112+ } ) ;
113+ } else {
114+ locations = [ new Location ( GitBlameCodeLens . toUri ( lens , 1 , recentLine , lines , [ recentLine . sha ] ) , lens . range . start ) ] ;
115+ }
116+
117+ lens . command = {
118+ title : `${ recentLine . author } , ${ moment ( recentLine . date ) . fromNow ( ) } ` ,
119+ command : Commands . ShowBlameHistory ,
120+ arguments : [ Uri . file ( lens . fileName ) , lens . range . start , locations ]
121+ } ;
122+ resolve ( lens ) ;
123+ } ) ;
124+ } ) ; //.catch(ex => Promise.reject(ex)); // TODO: Figure out a better way to stop the codelens from appearing
121125 }
122126
123127 _resolveGitHistoryCodeLens ( lens : GitHistoryCodeLens , token : CancellationToken ) : Thenable < CodeLens > {
0 commit comments