11import { isWebUri } from 'valid-url' ;
22
3- import {
4- Disposable ,
5- commands ,
6- window ,
7- workspace ,
8- Uri } from 'vscode' ;
3+ import { Disposable , commands , window , workspace , Uri } from 'vscode' ;
94
105import { ErrorHandler } from '../util/errorhandler' ;
116import { TextDecorator } from '../util/textdecorator' ;
127import { isActiveEditorValid } from '../util/editorvalidator' ;
138import { GitFile } from './file' ;
149import { GitFileFactory } from './filefactory' ;
1510import { StatusBarView } from '../view' ;
16- import {
17- Property ,
18- Properties } from '../util/property' ;
19- import {
20- GitBlameInfo ,
21- GitCommitInfo } from '../interfaces' ;
22- import {
23- HASH_NO_COMMIT_GIT ,
24- TITLE_VIEW_ONLINE } from '../constants' ;
25-
11+ import { Property , Properties } from '../util/property' ;
12+ import { GitBlameInfo , GitCommitInfo } from '../interfaces' ;
13+ import { HASH_NO_COMMIT_GIT , TITLE_VIEW_ONLINE } from '../constants' ;
2614
2715export class GitBlame {
2816 private disposable : Disposable ;
@@ -47,15 +35,31 @@ export class GitBlame {
4735
4836 const propertyHolder = Property . getInstance ( ) ;
4937
50- this . disposable = Disposable . from ( this . statusBarView , errorHandler , propertyHolder ) ;
38+ this . disposable = Disposable . from (
39+ this . statusBarView ,
40+ errorHandler ,
41+ propertyHolder
42+ ) ;
5143 }
5244
5345 setupListeners ( ) : void {
5446 const disposables : Disposable [ ] = [ ] ;
5547
56- window . onDidChangeActiveTextEditor ( this . onTextEditorMove , this , disposables ) ;
57- window . onDidChangeTextEditorSelection ( this . onTextEditorMove , this , disposables ) ;
58- workspace . onDidSaveTextDocument ( this . onTextEditorMove , this , disposables ) ;
48+ window . onDidChangeActiveTextEditor (
49+ this . onTextEditorMove ,
50+ this ,
51+ disposables
52+ ) ;
53+ window . onDidChangeTextEditorSelection (
54+ this . onTextEditorMove ,
55+ this ,
56+ disposables
57+ ) ;
58+ workspace . onDidSaveTextDocument (
59+ this . onTextEditorMove ,
60+ this ,
61+ disposables
62+ ) ;
5963
6064 this . disposable = Disposable . from ( this . disposable , ...disposables ) ;
6165 }
@@ -70,26 +74,38 @@ export class GitBlame {
7074 const commitInfo = await this . getCurrentLineInfo ( ) ;
7175
7276 // Only update if we haven't moved since we started blaming
73- if ( beforeBlameOpenFile === this . getCurrentActiveFileName ( ) && beforeBlameLineNumber === this . getCurrentActiveLineNumber ( ) ) {
77+ if (
78+ beforeBlameOpenFile === this . getCurrentActiveFileName ( ) &&
79+ beforeBlameLineNumber === this . getCurrentActiveLineNumber ( )
80+ ) {
7481 this . updateView ( commitInfo ) ;
7582 }
76-
7783 }
7884
7985 private getCurrentActiveFileName ( ) : string {
80- return window . activeTextEditor && window . activeTextEditor . document . fileName ;
86+ return (
87+ window . activeTextEditor && window . activeTextEditor . document . fileName
88+ ) ;
8189 }
8290
8391 private getCurrentActiveLineNumber ( ) : number {
84- return window . activeTextEditor && window . activeTextEditor . selection . active . line ;
92+ return (
93+ window . activeTextEditor &&
94+ window . activeTextEditor . selection . active . line
95+ ) ;
8596 }
8697
8798 async showMessage ( ) : Promise < void > {
8899 const commitInfo = await this . getCommitInfo ( ) ;
89100 const commitToolUrl = this . getToolUrl ( commitInfo ) ;
90101 const messageFormat = Property . get ( Properties . InfoMessageFormat ) ;
91- const normalizedTokens = TextDecorator . normalizeCommitInfoTokens ( commitInfo ) ;
92- const message = TextDecorator . parseTokens ( messageFormat , normalizedTokens ) ;
102+ const normalizedTokens = TextDecorator . normalizeCommitInfoTokens (
103+ commitInfo
104+ ) ;
105+ const message = TextDecorator . parseTokens (
106+ messageFormat ,
107+ normalizedTokens
108+ ) ;
93109 const extraAction = commitToolUrl ? TITLE_VIEW_ONLINE : '' ;
94110
95111 this . updateView ( commitInfo ) ;
@@ -107,17 +123,20 @@ export class GitBlame {
107123
108124 if ( commitToolUrl ) {
109125 commands . executeCommand ( 'vscode.open' , commitToolUrl ) ;
110- }
111- else {
112- window . showErrorMessage ( 'Missing gitblame.commitUrl configuration value.' ) ;
126+ } else {
127+ window . showErrorMessage (
128+ 'Missing gitblame.commitUrl configuration value.'
129+ ) ;
113130 }
114131 }
115132
116133 private async getCommitInfo ( ) : Promise < GitCommitInfo > {
117134 let commitInfo = await this . getCurrentLineInfo ( ) ;
118135
119136 if ( GitBlame . isGeneratedCommit ( commitInfo ) ) {
120- window . showErrorMessage ( 'The current file and line can not be blamed.' ) ;
137+ window . showErrorMessage (
138+ 'The current file and line can not be blamed.'
139+ ) ;
121140 }
122141
123142 return commitInfo ;
@@ -128,61 +147,71 @@ export class GitBlame {
128147 return ;
129148 }
130149
131- const parsedUrl = TextDecorator . parseTokens ( Property . get ( Properties . CommitUrl ) , {
132- 'hash' : commitInfo . hash
133- } ) ;
150+ const parsedUrl = TextDecorator . parseTokens (
151+ Property . get ( Properties . CommitUrl ) ,
152+ {
153+ hash : commitInfo . hash
154+ }
155+ ) ;
134156
135157 if ( isWebUri ( parsedUrl ) ) {
136158 return Uri . parse ( parsedUrl ) ;
137- }
138- else if ( parsedUrl ) {
139- window . showErrorMessage ( 'Malformed URL in setting gitblame.commitUrl. Must be a valid web url.' ) ;
159+ } else if ( parsedUrl ) {
160+ window . showErrorMessage (
161+ 'Malformed URL in setting gitblame.commitUrl. Must be a valid web url.'
162+ ) ;
140163 }
141164 }
142165
143166 private updateView ( commitInfo : GitCommitInfo ) : void {
144167 if ( GitBlame . isGeneratedCommit ( commitInfo ) ) {
145168 this . statusBarView . clear ( ) ;
146- }
147- else {
169+ } else {
148170 this . statusBarView . update ( commitInfo ) ;
149171 }
150172 }
151173
152174 async getBlameInfo ( fileName : string ) : Promise < GitBlameInfo > {
153175 if ( ! this . files [ fileName ] ) {
154- this . files [ fileName ] = GitFileFactory . create ( fileName , this . generateDisposeFunction ( fileName ) ) ;
176+ this . files [ fileName ] = GitFileFactory . create (
177+ fileName ,
178+ this . generateDisposeFunction ( fileName )
179+ ) ;
155180 }
156181
157182 return this . files [ fileName ] . blame ( ) ;
158183 }
159184
160185 async getCurrentLineInfo ( ) : Promise < GitCommitInfo > {
161186 if ( isActiveEditorValid ( ) ) {
162- return this . getLineInfo ( window . activeTextEditor . document . fileName , window . activeTextEditor . selection . active . line )
163- }
164- else {
187+ return this . getLineInfo (
188+ window . activeTextEditor . document . fileName ,
189+ window . activeTextEditor . selection . active . line
190+ ) ;
191+ } else {
165192 return GitBlame . blankCommitInfo ( ) ;
166193 }
167194 }
168195
169- async getLineInfo ( fileName : string , lineNumber : number ) : Promise < GitCommitInfo > {
196+ async getLineInfo (
197+ fileName : string ,
198+ lineNumber : number
199+ ) : Promise < GitCommitInfo > {
170200 const commitLineNumber = lineNumber + 1 ;
171201 const blameInfo = await this . getBlameInfo ( fileName ) ;
172202
173203 if ( blameInfo [ 'lines' ] [ commitLineNumber ] ) {
174204 const hash = blameInfo [ 'lines' ] [ commitLineNumber ] ;
175205 return blameInfo [ 'commits' ] [ hash ] ;
176- }
177- else {
206+ } else {
178207 return GitBlame . blankCommitInfo ( ) ;
179208 }
180209 }
181210
182211 private generateDisposeFunction ( fileName ) {
183212 return ( ) => {
184213 delete this . files [ fileName ] ;
185- }
214+ } ;
186215 }
187216
188217 dispose ( ) : void {
@@ -192,8 +221,8 @@ export class GitBlame {
192221
193222 static blankBlameInfo ( ) : GitBlameInfo {
194223 return {
195- ' commits' : { } ,
196- ' lines' : { }
224+ commits : { } ,
225+ lines : { }
197226 } ;
198227 }
199228
0 commit comments